Why are the shadows from objects are not visible on a terrain? Do terrains support shadows?

I have already created more than one 3D scene using JME3, for example:

or my beginning scenes: https://youtu.be/J76mau6D_cs

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.

Example code was published in a previous post.

Is it possible to receive shadows from spatials on a terrain?


Check out the TerrainLighting material.

Edit: I guess PBRTerrain should work too for PBR scenes?

Does it means I can’t change it in the TerrainEditor? Should I create the material from the code?

 matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/PBRTerrain.j3md");

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.

Can you elaborate on this?

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.

Right, I didn’t think it through. So it’s not a lighting issue, but a shadow issue.

1 Like

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.

You don’t need to. This is not the issue.

PBR objects can cast shadows on regular terrain. Something else is wrong.

1 Like

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?

You are probably just not doing it right?

I didn’t found any differences

And it does print “Point light added”?

And it’s not something to do with falloff?

Can’t remember if I’ve ever used PointLightShadowRenderer

does it mean I need to use Filter instead?

No, I mean I’ve mostly used them with DirectionalLights.

Ok, but I tried to replace with code:

                FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
                PointLightShadowFilter pointShadowFilter = new PointLightShadowFilter(getAssetManager(), 1024*4);
                System.out.println("Point light added");         
                /*it was before
                PointLightShadowRenderer pointShadowFilter = new PointLightShadowRenderer(getAssetManager(), 1024*4);
                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.

Some screenshots:


What do you believe this is doing?

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?

What will be your advice?

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

1 Like