But now I’m trying to work with terrains and I use the same pattern to create lights and shadow maps, which worked with my previous scenes, which contained only Spatials (no terrains). But in scenes with a terrain I can not receive shadows on the terrain.
It might be that the terrain editor doesn’t support different materials. In that case you can create it in the terrain editor, and then (presumably) replace the materials when loading it in the application.
PBR models on a non-PBR terrain should cast shadows just fine. The shadow support has nothing to do with the PBR-ness of the objects, cast or receive.
I don’t know why it’s not working but it would be strange (and require more explanation) if it’s related to PBR models on non-PBR terrain… the shadow maps shouldn’t care.
Maybe there are another tools to import terrains from external editors? Or maybe I can convert the terrain in a 3D model and reimport it as a Spatial?
I can not understand how to combine the terrain, created and textured in the JME3 editor, with the “Common/MatDefs/Terrain/PBRTerrain.j3md”- material, created from the code.
I think I found my error. When I add a DirectionalLight - the shadows are visible. They are not visible only with PointLights. I don’t know why - I make the same actions for the both LightSources.
I have published my Project with all recourses on Github - the main source file is here.
Have I right understood that the PointLight never produces shadows?
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
PointLightShadowFilter pointShadowFilter = new PointLightShadowFilter(getAssetManager(), 1024*4);
point.setRadius(10000);
pointShadowFilter.setLight(point);
pointShadowFilter.setEnabled(true);
pointShadowFilter.setShadowIntensity(10.8f);
pointShadowFilter.setShadowZExtend(15);
pointShadowFilter.setShadowZFadeLength(5);
pointShadowFilter.setShadowIntensity(0.8f);
pointShadowFilter.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
fpp.addFilter(pointShadowFilter);
viewPort.addProcessor(fpp);
System.out.println("Point light added");
/*it was before
PointLightShadowRenderer pointShadowFilter = new PointLightShadowRenderer(getAssetManager(), 1024*4);
pointShadowFilter.setLight(point);
viewPort.addProcessor(pointShadowFilter);
System.out.println("Point light added");
*/
And now I see the shadow but it is rendered not normal - only with the car and under some angles (when I see in the light source). I have also switched off the DirectionalLight and left only PointLight. See animation in the video.
Yes, you are right. I set shadowZExtend on 105 and the shadows are rendered normal.
The next logical question is: what must be optimal dimensions of the scene objects? I think, I should make my objects smaller to have not too many problems in the future development - with the collision detection (using Minnie), with the lighting. What sizes should my game objects (player with a capsule collider), cars, chests have?
Meter sized objects work well with default physics settings, at least. So stick to 1:1. It’s way easier to scale shadow/filter values than it is tweaking physics.
I should make my objects smaller to have not too many problems in the future development - with the collision detection (using Minnie), with the lighting.
For a physics simulation, it might seem natural to choose kilograms and meters as the units of mass and distance, respectively. However, this is not a requirement, and for many games, MKS units are not the best choice…continued