Ok, I am trying to put everything important together:
@Override
public void simpleInitApp() {
//(...) init stuff for cam, gui
initLighting();
initShadow();
rootNode.setShadowMode(ShadowMode.CastAndReceive);
}
private void initLighting() {
g_ambient = new AmbientLight();
g_ambient.setColor(ColorRGBA.White);
rootNode.addLight(g_ambient);
g_sun = new DirectionalLight();
g_sun.setColor(ColorRGBA.White);
g_sun.setDirection(new Vector3f(0, 0.2f, 0.6f));
rootNode.addLight(g_sun);
}
private void initShadow() {
final int SHADOWMAP_SIZE = 512;
DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3);
dlsr.setLight(g_sun);
viewPort.addProcessor(dlsr);
DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 3);
dlsf.setLight(g_sun);
dlsf.setEnabled(true);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
SSAOFilter ssaoFilter = new SSAOFilter(12.94f, 43.92f, 0.33f, 0.61f);
fpp.addFilter(dlsf);
fpp.addFilter(ssaoFilter);
viewPort.addProcessor(fpp);
}
That’s how I init my geo:
private void initMesh() {
Vector3f[] vertices = new Vector3f[12];
vertices[0] = new Vector3f(8, 0, 0);
vertices[1] = new Vector3f(24, 0, 0);
vertices[2] = new Vector3f(32, 0, 12);
vertices[3] = new Vector3f(24, 0, 24);
vertices[4] = new Vector3f(8, 0, 24);
vertices[5] = new Vector3f(0, 0, 12);
vertices[6] = new Vector3f(8, -64, 0);
vertices[7] = new Vector3f(24, -64, 0);
vertices[8] = new Vector3f(32, -64, 12);
vertices[9] = new Vector3f(24, -64, 24);
vertices[10] = new Vector3f(8, -64, 24);
vertices[11] = new Vector3f(0, -64, 12);
Vector2f[] texCoord = new Vector2f[12];
texCoord[0] = new Vector2f(1, 0);
texCoord[1] = new Vector2f(1, 0);
texCoord[2] = new Vector2f(1, 1);
texCoord[3] = new Vector2f(1, 1);
texCoord[4] = new Vector2f(1, 1);
texCoord[5] = new Vector2f(0, 1);
texCoord[6] = new Vector2f(1, 0);
texCoord[7] = new Vector2f(1, 0);
texCoord[8] = new Vector2f(1, 1);
texCoord[9] = new Vector2f(1, 1);
texCoord[10] = new Vector2f(1, 1);
texCoord[11] = new Vector2f(0, 1);
int[] indexes = {
2, 0, 1,
5, 0, 2,
4, 5, 2,
3, 4, 2,
0, 6, 7,
0, 7, 1,
1, 7, 8,
1, 8, 2,
2, 8, 9,
2, 9, 3,
3, 9, 10,
3, 10, 4,
4, 10, 11,
4, 11, 5,
5, 11, 6,
5, 6, 0
};
mesh = new Mesh();
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes));
mesh.updateBound();
resource = new Resource(Resource.EMPTY, 0);
activeColor = resource.getRGBAValue(); //color is white
geo = new Geometry(id, mesh);
mat = new Material(GameManager.g_assetManager,
"Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Ambient", activeColor);
mat.preload(GameManager.g_simpleApplication.getRenderManager());
geo.setMaterial(mat);
geo.setLocalTranslation(position.x, position.y, position.z);
geo.updateModelBound();
node.attachChild(geo);
}
Each geo will be init by a object manager called terrain. And the node of this object manager is attached to the rootNode.
That’s the current status:
Somehow there’s also a problem with the camera casting a shadow itself. Is there some kind of special way to disable this?