Problem with texture and lights

Hello Everyone :slight_smile:

I’m working together with two friends on a game-project for our university-project.

My friends are programming the data structures and I have the pleasure to create textures and 3d-models.

I thought it would be nice to have parallax mapping in our game, so I created all the necessary stuff for that. But now I have a big problem.
At first something about the lighting: Everything gets lighten up by an ambient light, just to make sure that not the whole scene is black. For the player we wanted a flashlight effect, so I’m using a spotlight as flashlight.
To brighten up the scene around the player, like the flashlight reflects light from the walls, there also is a pointlight in the player.
Now to the problem: It looks like the textures just receive light from an angle of about 180 degrees. If the players stands in the right direction there is no problem with lightning.
So I decided to test a simple light material with the texture as the diffuse-map. As you can see, the problem still apears.
To the screenshots:
First screenshot: The player just have the pointlight attached to himself.
Second screenshot: Only the ‘flash-light’ and the ambient-light is activatet. The player looks into the tunnel. The first materials are positioned in the right direction to the player so they dont show any problems. The dark spots are the textures which are positioned wrong to the player, so you can see that they dont receive the light.
Third screenshot: As above, the ‘flash-light’ and the ambient-light is active. The player is a angle to the texture, no problems.
Fourth screenshot: Same light as above. You can barely the shape of the flashlight. The texture absorbs nearly all the light.
Fifth screenshot: Thats the Material i used for all these screenshots. As you can see, nothing is activatet, just the texture is set as the DiffuseMap.

First screenshot

Second Screenshot

Third screenshot

Fourth screenshot



Material Source Code
[java]Material StoneWallTest : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
DiffuseMap : Materials/StoneWall/MediumRes/StoneWall_m.jpg

I have no idea what I’m doing wrong, can anyone help me? Please tell me if you nee more information!

I allready did all the tutorials and searched for a solution for more than 4 hours!

PS: I’m from germany, so I’m sorry if my english isn’t the best :wink:

Did you run the TangentBinormalGenerator on your geometry? If not then parallax mapping and normal mapping will be all messed up.

Also, both links appear to be the same and I could only see one image. Is there a reason that you don’t just use imgur like the rest of the internet? :slight_smile:

Edit: saw your edit late.

Also, a point light “attached to himself” just means that the point light will only affect that node and it’s children. If you want the point light in a particular world location then you will have to put it there. So are you actually moving the light or basically what does “attached to himself” mean in this context?

And because of the way lighting is done, if you have really big surfaces then things like point lights will get kind of lowered towards the middle. You have to increase your poly count for them to work properly.

Badly…yes, I did, so thats not the solution.

I wrote something like:

With “attached to himself” I mean:
The lighting is added to the root-node.
In the simpleUpdate function I addedd a function that sets the position of the flashlight and the pointlight in the same position as the player is located in.
The flashlight also gets the same direction as the player is looking.

How can i increas the poly count? Do you mean that I just have to increase the number of polygons for the walls?
Actually the walls are just meshs we hardcoded, so no export from Blender or something like this.

Maybe that’s because your mesh has too few subdivisions.
That can have bad effects on how light is computed. The light direction is computed in the vertex shader and interpolated in the fragment shader. Too few vertices can result in wrong light direction.
Is there a way that you subdivide your model?

Thanks for that tip, I will try to subdivide the meshes.
Its a liitle bit tricky because its hardcoded, but maybe we tried too much to optimize the perfomance of our game :wink:

I found out that there was a class Subdivision in jme2.
Is there a similar class in jme3?
Or is it possible that I just copy the old code?

I worked a little bit more on the problem but wasnt able to solve it completly.
Now it seems to work better, but not completly without problems.

I uploaded a video on youtube and give you the source code, maybe then you get a better idea of what I’m doing wrong :wink:

As you can see in the video, there is something like a sharp edge which “destroys” the light.

Thank you really much for your help!

The source code:
[java]package mygame;

import com.jme3.light.AmbientLight;
import com.jme3.light.PointLight;
import com.jme3.light.SpotLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector2f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer;
import com.jme3.texture.Texture;
import com.jme3.util.BufferUtils;
import com.jme3.util.TangentBinormalGenerator;


  • Texture Problem

  • @author Timo
    public class Main extends SimpleApplication {
    AmbientLight ambient;
    SpotLight flashlight;
    PointLight pl;

    Mesh mesh;
    Geometry geo;

    public static void main(String[] args) {
    Main app = new Main();

    public void simpleInitApp() {



    private void initMesh(){
    mesh = new Mesh();

     Vector2f[] vertices = new Vector2f[9];
     vertices[0] = new Vector2f(0,0);
     vertices[1] = new Vector2f(1,0);
     vertices[2] = new Vector2f(2,0);
     vertices[3] = new Vector2f(0,1);
     vertices[4] = new Vector2f(1,1);
     vertices[5] = new Vector2f(2,1);
     vertices[6] = new Vector2f(0,2);
     vertices[7] = new Vector2f(1,2);
     vertices[8] = new Vector2f(2,2);
     Vector2f[] texCoord = new Vector2f[8];
     texCoord[0] = new Vector2f(0,0);
     texCoord[1] = new Vector2f(1,0);
     texCoord[2] = new Vector2f(0,1);
     texCoord[3] = new Vector2f(1,1);
     texCoord[4] = new Vector2f(0,0);
     texCoord[5] = new Vector2f(1,0);
     texCoord[6] = new Vector2f(0,1);
     texCoord[7] = new Vector2f(1,1);
     int [] indexes = {6,3,4, 7,6,4, 3,0,1, 4,3,1, 7,4,5, 8,7,5, 4,1,2, 5,4,2};
     mesh.setBuffer(VertexBuffer.Type.Position, 2, BufferUtils.createFloatBuffer(vertices));
     mesh.setBuffer(VertexBuffer.Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
     mesh.setBuffer(VertexBuffer.Type.Index,    3, BufferUtils.createIntBuffer(indexes));
     geo = new Geometry("OurMesh", mesh);
     Material mat = getAssetManager().loadMaterial("Materials/Stone.j3m");

    // mat.getAdditionalRenderState().setWireframe(true);

    private void initAmbientLight(){
    ambient = new AmbientLight();

    private void initPointLight() {
    pl = new PointLight();

    private void initSpotLight() {
    flashlight = new SpotLight();
    flashlight.setSpotInnerAngle(10 * FastMath.DEG_TO_RAD);
    flashlight.setSpotOuterAngle(15 * FastMath.DEG_TO_RAD);

    public void simpleUpdate(float tpf) {


The material file:
Material Files


In the video is that one giant quad or a subdivided quad?

Its a subdivided quad, maybe this will make it more clear:

In “real” all sides have the same length. Its an quad divided in 4 quads with the same sizes.
I also recognized a new problem with the textures, but im sure its because my texCoord are wrong.

The video was recorded with the source code I postet above, so everything seen in the video results out of it.

Hmmmm…I just did the same like in the video but with wireframe activated, there is no sharp dark edge…any idea? I will upload a second video which will show this in some minutes.

Here is the video