Simplest way to create terrain shadowmap on forest scene

Hello,

I am working on the shadowing of a forest scene that I generate in JME, and I want to see how it’s possible to include a shadowtexture in the terrain material (just the terrain, NOT on the whole scene) based on the shadows from the whole scene (trees etc …) since it seems such a waste to calculate that static shadowing in real time

From reading the various threads regarding shadows generation in JME, such as these

Sure I could generate in blender or other tool a shadow texture for the whole terrain, but that would not include the shadows of all static elements from the terrain (such as the trees) that I am generating in JME. I have searched the forum to see if there would be any way to export the jme scene to blender but couldn’t find much

The shadow render pass in JME works nicely but there is no straightforward way to retrieve and export the shadow projected on the terrain by the whole scene (the system is thought to create shadow from the observer point of view)

Any thought?

Thanks!

So calculate (render) it once on the first frame. Or render it each time some ‘control sum’ is changed. I’m doing it this way in my game, Skullstone - For every light source I have 6 objects which contains shadowmap, camera and some control sum. Every frame and for every shadowmap I calculate an actual control sum using states (translations, animation time and so on) of every geometry in frustum. Then I compare it with the previous control sum. If they are equals I skip the rendering.

Assume the scene never changes, so the first frame would be the first frame of the game and that’s it. But then, probably I’m missing something but to me the render depends on the camera, no? How do you make that post rendering work for any camera position on the scene?

Note that you can add as many cameras as you like and set any number to render before or after the main scene. See RenderManager.

Copy-paste the shadow renderer’s code and make all the changes you need. My shadowrenderer is actually completely rewritten.

ok, will look into this, thanks!

Yes, but presumably your camera position does… and presumably your scene is large enough that you want detailed shadows up close and not-detailed shadows far away. Versus not-detailed shadows up close and far away.

Yes, but presumably your camera position does…

That was my doubt as well and from @FrozenShade answer, I assumed it should be feasible modifying the renderer (haven’t looked at it yet)

Regarding the size of scene and different quality of shadows, sounds quite reasonable, but how do you do this? Through creating 2 shadow renderers and playing on which part of the scene shows the render of which?

,…you use the stock shadow rendering which already does this.

In an open forest environment, you either have ugly static shadows, 4 gig of RAM pretty static shadows, or use the dynamic renderer and have pretty shadows up close.

There aren’t really any alternatives.

Ok sorry, not sure where I pulled that code from but I had these two lines set and I thought they were mandatory parameters

 plsr.setShadowZExtend(100);
 plsr.setShadowZFadeLength(5);

Yes by removing these lines, it all makes sense !

:-\

thanks for the heads up

One last thing, using that “all over the map shadow” I see a significant drop in fps, can you confirm this is expected and if I may be missing an obvious optimization?

Going from something like 220 fps to 20 on a config with a GeForce GTX 480/PCIe/SSE2

Trying with a split of 1, texture size of 1024

Stats are
Textures (M) = 10
Textures (F) = 10
Textures(S) = 267

Shaders (M) = 7
Shaders (F) = 7
Shaders (S) = 265

Objects = 1189
Uniforms = 2574
Triangles = 1,140,807
Vertices = 1,876,897

I’ve searched the forum for similar posts but only found that topic related to SSAO

https://hub.jmonkeyengine.org/t/solved-ambient-shadow-filter-drops-my-fps-a-lot/35181/19

Code is

    plsr = new DirectionalLightShadowRenderer(assetManager, 1024,1);
    plsr.setLight(lightTest);
    viewPort.addProcessor(plsr);       
    plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsr.setShadowIntensity(0.8f);
    plsr.setLambda(0.8f);

Thanks

You may have better luck with the shadow filter on it a scene like that.

MUCH better thanks!