Terrain and Directional Lighting

I just got started with JM3 and am currently stuck with the lightning of the terrain.

I have a directional light which should illuminate the terrain, but i looks as if the light

does not influence the terrain at all. Every part seems to have the same brightness

and does not turn to black if i remove the directional light. Here my code:



[java]

import com.jme3.app.SimpleBulletApplication;

import com.jme3.bounding.BoundingBox;

import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;

import com.jme3.bullet.nodes.PhysicsCharacterNode;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.Camera;

import com.jme3.scene.Node;

import com.jme3.terrain.geomipmap.TerrainLodControl;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.heightmap.AbstractHeightMap;

import com.jme3.terrain.heightmap.ImageBasedHeightMap;

import com.jme3.terrain.jbullet.TerrainPhysicsShapeFactory;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

import com.jme3.util.SkyFactory;

import java.util.ArrayList;

import java.util.List;

import jme3tools.converters.ImageToAwt;



class TerrainLight extends SimpleBulletApplication {



PhysicsCharacterNode character;

Node model;

TerrainQuad terrain;

Node terrainPhysicsNode;

Material matRock;

Material matWire;



public static void main(String[] args) {

TerrainLight app = new TerrainLight();

app.start();

}



@Override

public void simpleInitApp() {

createLight();

createTerrain();

createCharacter();

getFlyByCamera().setMoveSpeed(500);

}



private void createLight() {

rootNode.attachChild(SkyFactory.createSky(

assetManager, “Textures/Sky/backgroundsky.jpg”, true));

DirectionalLight dl = new DirectionalLight();

dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());

dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));

rootNode.addLight(dl);

}



private void createTerrain() {

matRock = new Material(assetManager, “Common/MatDefs/Terrain/Terrain.j3md”);



matRock.setTexture(“m_Alpha”, assetManager.loadTexture(“Textures/Terrain/splat/alphamap.png”));



Texture heightMapImage = assetManager.loadTexture(“Textures/Terrain/splat/mountains512.png”);



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

grass.setWrap(WrapMode.Repeat);

matRock.setTexture(“m_Tex1”, grass);

matRock.setFloat(“m_Tex1Scale”, 64f);



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

dirt.setWrap(WrapMode.Repeat);

matRock.setTexture(“m_Tex2”, dirt);

matRock.setFloat(“m_Tex2Scale”, 32f);



Texture rock = assetManager.loadTexture(“Textures/Terrain/splat/road.jpg”);

rock.setWrap(WrapMode.Repeat);

matRock.setTexture(“m_Tex3”, rock);

matRock.setFloat(“m_Tex3Scale”, 128f);



AbstractHeightMap heightmap = null;

try {

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

heightmap.load();



} catch (Exception e) {

e.printStackTrace();

}

terrain = new TerrainQuad(“terrain”, 65, 513, heightmap.getHeightMap());

List cameras = new ArrayList();

cameras.add(getCamera());

TerrainLodControl control = new TerrainLodControl(terrain, cameras);

terrain.addControl(control);

terrain.setMaterial(matRock);

terrain.setModelBound(new BoundingBox());

terrain.updateModelBound();

terrain.setLocalScale(new Vector3f(2, 2, 2));

rootNode.attachChild(terrain);

TerrainPhysicsShapeFactory factory = new TerrainPhysicsShapeFactory();

terrainPhysicsNode = factory.createPhysicsMesh(terrain);

terrainPhysicsNode.attachChild(terrain);

rootNode.attachChild(terrainPhysicsNode);

getPhysicsSpace().add(terrainPhysicsNode);

}



private void createCharacter() {

CapsuleCollisionShape capsule = new CapsuleCollisionShape(1.5f, 3.9f);

character = new PhysicsCharacterNode(capsule, 0.01f);

model = (Node) assetManager.loadModel(“Models/MaleBody.mesh.j3o”);

model.setLocalScale(0.5f);

character.attachChild(model);

character.setLocalTranslation(new Vector3f(-30, 60, 0));

rootNode.attachChild(character);

getPhysicsSpace().add(character);

}



@Override

public void simpleUpdate(float tpf) {

rootNode.updateGeometricState();



}

}

[/java]

It’s basically the code of “Hello Terrain” plus a character i added (which does get lighted correctly).

I feel like i overlooked something fundamental here …

Mhh, I had a similar problem with water effects. Update to tonights build (Nov. 5th), maybe that’ll help (I know that my issue has been resolved like that…)?

Lighting doesnt affect terrain yet afaik.

normen said:
Lighting doesnt affect terrain yet afaik.

Correct, it isn't implemented yet. We have to take into account detail maps and normal maps for those detail maps, and the current terrain shader doesn't support that yet. It should have work started on it, I'm guessing, in December.

Guess i’ll wait for December then.

Thanks for your replies!