Hello, I’m working with jMonkeyEngine 3 to practice programming a bit and I began working on a little voxel engine. Right now I was just learning about shaders and how jMonkey handles lighting and ran into few problems.
I have DirectionalLight, DirectionalLightShadowRenderer, DirectionalLightShadowFilter and SSAOFilter working along side some simple shaders. I got most of the code from the wiki pages by following their tutorial, but I’m running into a couple problems:
- Ambient occlusion looks really strange and seems like it’s the inverse of what it should be (edges are bright, center of surfaces are dark + the darkness level changes with camera rotation)
- Shadows don’t contact the surfaces they are cast from correctly
- There are a few strange artifacts relating to the SSAO filters and shadows where they are cut off about half way up the screen. It’s more noticeable when moving back and forth and there’s a visible line where the shadows are harshly different above and bellow this line in view.
Some images of what is going on:
Paste bin of the relevant code:
Most relevant code:
sun = new DirectionalLight();
sun.setDirection(new Vector3f(-5, -4, -4).normalizeLocal());
localRootNode.addLight(sun);
localRootNode.setShadowMode(ShadowMode.CastAndReceive);
fpp = new FilterPostProcessor(assetManager);
/* Drop shadows */
final int SHADOWMAP_SIZE=2048;
DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3);
dlsr.setLight(sun);
app_manager.getViewPort().addProcessor(dlsr);
dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 3);
dlsf.setShadowZExtend(2048f);
fpp.addFilter(dlsf);
SSAOFilter ssaoFilter = new SSAOFilter(12.94f, 43.92f, 0.33f, 0.61f);
fpp.addFilter(ssaoFilter);
app_manager.getViewPort().addProcessor(fpp);
//-----------------------------//
MaterialDef BlockyTexture {
MaterialParameters {
Vector4 Color
}
Technique {
VertexShader GLSL330: Shaders/TerrainLOD.vert
FragmentShader GLSL330: Shaders/TerrainLOD.frag
WorldParameters {
WorldViewProjectionMatrix
LightDirection
LightColor
LightPosition
inColor
}
}
}
//-----------------------------// TerrainLOD.vert
uniform mat4 g_WorldViewProjectionMatrix;
attribute vec3 inPosition;
void main()
{
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
}
//-----------------------------// TerrainLOD.frag
uniform vec4 u_LightColor;
uniform vec4 u_LightDirection;
uniform vec4 u_LightPosition;
uniform vec4 inColor;
void main()
{
vec3 color = inColor.xyz+vec3(0.1,0.75,0.1);
gl_FragColor = vec4(color, 1.0);
}
Please let me know what I’m missing and if you need any info to help out.
Thanks in advance!