Hi! Is it possible to change the Shadow Intensity of a ShadowRenderer during the update Method? I want to create a Day Night Cycle with two “moving” Directional Lights (Their “position” is calculated by inverting positional vectors) and their shadows should only be calculated when they are “above” the terrain; Currently, the shadows are cast anyway, and if I change the intensity during the update loop, nothing happens.
Then I think you are not really changing it.
Changing intensity at runtime is certainly possible. Or at least it was last time I checked. (The SimArboral editor lets you set it at runtime and it’s always worked.)
Edit: though I guess SimArboreal is using the shadow fllter instead of the renderer… still shouldn’t matter as it boils down to a material parameter.
This is my code (Just the sun):
@Override
public void update(float tpf){
float timeOfDay = GameState.GAMETIME.getTimeOfDayInMillis();
float timeInRads = timeOfDay / 43200000;
float timeDaylight = timeInRads - 0.5f;
quat.fromAngleAxis(timeDaylight * ((float)Math.PI), Vector3f.UNIT_Z);
sunNode.set(1, 0, 0);
sunNode = quat.mult(sunNode);
float shadowIntensity = (float)Math.sin((double)timeDaylight * Math.PI);
shadowIntensity = shadowIntensity > 0 ? shadowIntensity : 0;
System.out.println(shadowIntensity + "; " + GameState.GAMETIME.toString());
sunShadow.setShadowIntensity(shadowIntensity);
sun.setDirection(sunNode.mult(-1));
}
I do believe I am changing it. Shadow Filter seem to be too slow for my game - no idea why.
What is the output from this debug println?
It starts with 0.0 (between 18:00 and 6:00), then gradually reaches 1.0 (at 12:00) and then goes back to 0.0 at 18:00
Put together a simple one-class test case that illustrates the issue and perhaps others will spot the problem… or you will.
I found the solution before I did that - for some reason, I called “initialize()” manually on my AppStates. After removing that, it worked flawlessly with renderers and filters, and the framerate also became a LITTLE bit better (it jumped from 30 to 90 fps)