Fix for using different ShadowRenderers(Point, Directional, Spot) together

Link to the pull request: ShadowRenderers can now be used together, a test case for this was added... by Perjin · Pull Request #137 · jMonkeyEngine/jmonkeyengine · GitHub

If the shadow renderers are used together errors occur because the Defines for PSSM and POINTLIGHT in the PostShadow material stay true for SpotLightShadowRenderer and DirectionalLightShadowRenderer.
I fixed this by clearing the material parameters causing this behavior.

The same thing also happens for the ShadowFilters, but I’m not sure how to fix this problem for those.

I also created a test case where all the ShadowRenderers are used together.

DirectionalLightShadowRenderer:
[java] @Override
protected void setMaterialParameters(Material material) {
material.setColor(“Splits”, splits);
material.clearParam(“LightViewProjectionMatrix5”);
}
[/java]

SpotLightShadowRenderer:
[java] @Override
protected void setMaterialParameters(Material material) {
material.setVector3(“LightPos”, light.getPosition());
material.setVector3(“LightDir”, light.getDirection());
material.clearParam(“LightViewProjectionMatrix5”);
material.clearParam(“Splits”);
}
[/java]

Fixed:

5 Likes

Cool, thanks for this.
I’ll test it and merge it

I tested it just now and it did seem to fix something… Although, it doesn’t seem the on-screen configuration does anything on that test.

This is how the test looks like for me:
with the bug fixed:

here is the test without the bug fix:

In the version without the bug fix there are errors in the shadows of the cylinder shape in the background, the shadows of the sphere and cylinder on the left wall are missing and the big cubes shadow extending to the left is being cut off.

Though I only tested it on nvidia and an intel, not on amd.

Ahh crap, now I noticed that I forgot to add an ShadowTestUIManager for the directional and spot light, i guess thats what you meant.

Edit: I have added the ShadowTestUIManager for the spot and directional lights the test will now toggle for all lights between renderer, filter and no shadows.

@nehon: This fix makes sense to me. Do you have any comments / concerns?

Well…I’d rather have a clearParams method called after each processor postFrame.
Here it feels hackish that a shadow renderer have to remove the params from another shadow renderer.

I agree, while the finding behind this is good, a filter should cleanup cleanly after it. There might be a few dozen other interdependencies hidden else.

So I made a fix for the issue

Thanks @Perjin, even if your PR was not merged as is it helped a lot.

1 Like

Good, your fix is working for me and I agree it is cleaner that way. The only thing I noticed is that in the test case for switching between filters and renderers the directional lights ShadowTestUIManager should be added first or else the shadow renderers will be reattached in the wrong order (also the Point light is added twice to a shadow manager).