Light in TerrainQuad

Hello, they are light in terrainQuad, in the tuto “hello terrain” ? because i can’t put this :confused:

(Sorry i’m not english)

Use TerrainLighting.j3md as material.

Thanks, I have change my code but i have a another Problem

my code:

[java]mat_terrain = new Material(assetManager, "MatDefs/Terrain/TerrainLighting.j3md");


//texture 1

Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");


mat_terrain.setTexture("m_DiffuseMap", grass);

mat_terrain.setFloat("m_DiffuseMap_0_scale", 64f);

//texture 2

Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");


mat_terrain.setTexture("m_DiffuseMap_1", dirt);

mat_terrain.setFloat("m_DiffuseMap_1_scale", 32f);

//texture 3

Texture rock = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");


mat_terrain.setTexture("m_DiffuseMap_2", rock);

mat_terrain.setFloat("m_DiffuseMap_2_scale", 128f);

final Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/Modele/"+nbrCase+".png");

final AbstractHeightMap heightmap =new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));



terrain = new TerrainQuad("my terrain", 65, nbrCase+1, heightmap.getHeightMap());



terrain.setLocalTranslation(x,-1 , z);

terrain.setLocalScale(1f, 1f, 1f);


/DirectionalLight sun = new DirectionalLight();


sun.setDirection(new Vector3f(0,0,0).normalizeLocal());


The terrain was created but i seen nothing. already is black

Well did you add a light? Why don’t you just use the Terrain Editor?

because i want create a world editor :smiley:

[java]DirectionalLight soleil = nouvelle DirectionalLight ();

sun.setColor (ColorRGBA.White);

sun.setDirection (. Vector3f nouvelles (0,0,0) normalizeLocal ());

terrain.addLight (soleil); [/java]

this code change nothing :confused:

Add the light to the rootNode, not to the terrain. (french I see, I’m french too :slight_smile: )

Ok but we are in a english forum sooo … ^^

i have the same, but i can see my terrain because i have change my background in blue ! but my terrain is black :frowning:

Ok aleardy is good !!

My problem was in the light. but i don’t understand ! can you explain me why don’t can write

light.setDirection((new Vector3f(0,0,0)).normalize());

but this

light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());


thanks :slight_smile:

A directional light obviously requires a direction Vector.

(0,0,0) doesn’t provide a direction.

When you try to normalize this 0.0f Vector, you try to set its length to 1.0f. It will most certainly give you a division by zero Exception.

You should read this document to understand Vectors better :

Thanks :slight_smile:

this topic is OK

I have a other problem :slight_smile:

If i put 2 terrainQuad, just the first have light effect :confused:

ozonegrif said:
Add the light to the rootNode, not to the terrain.

i have already do this :slight_smile:

Can you share a screenshot ?


it’s strange… no it’s good thanks xD