Problems when combining DirectionalLight, SSAOFilter and simple shaders

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());
    fpp = new FilterPostProcessor(assetManager);
    /* Drop shadows */
    final int SHADOWMAP_SIZE=2048;
    DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3);

    dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 3);
    SSAOFilter ssaoFilter = new SSAOFilter(12.94f, 43.92f, 0.33f, 0.61f);


MaterialDef BlockyTexture {

MaterialParameters {
    Vector4 Color
Technique {
    VertexShader GLSL330:   Shaders/TerrainLOD.vert
    FragmentShader GLSL330: Shaders/TerrainLOD.frag

    WorldParameters {

//-----------------------------// 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 =,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!

I have not checked your full post, but:

You should use either DirectionalLightShadowRenderer or DirectionalLightShadowFilter. Not both at the same time.

Order of filters is important, too. And add a TranslucentBucketFilter last.

I usually encounter shadow issues when the depth map is too granular. What are your viewport frustum settings?

Also note: if these are custom shaders then there may be some things that have to be done to make them play nice with JME’s ssao and shadows… depending on how similar they are to JME’s existing shaders and whether or not they have the proper techniques for things like shadow passes and stuff.

For example, your material definition lacks a preshadow, postshadow, prenormal pass. It’s likely that you can just copy these from JME’s lighting shader… but it may requires some additional material parameters, I don’t remember.

1 Like