Today I was looking for a reason why my terrain didn’t cast shadows.
The cause I checked is that the area where I draw the shadows is set to very small.
The terrain I created is 256 x 256 in size.
The size is flexible, so I don’t know if I need to stretch it appropriately each time.
Can’t we make all cast objects cast shadows?
You can, by extending the size of the shadow area to encompass your entire scene. If you’re using a DirectionalLight to cast shadow then adjust these properties:
light.shadow.camera.near
light.shadow.camera.far
light.shadow.camera.left
light.shadow.camera.right
light.shadow.camera.top
light.shadow.camera.bottom
However, since the shadow is stored in a single texture, as you increase those values more and more data needs to be crammed into the texture and the shadow quality will get worse.
To avoid that, you can increase the texture size. These are the defaults:
light.shadow.mapSize.width = 512; // default
light.shadow.mapSize.height = 512; // default
You can change them to be:
light.shadow.mapSize.width = 2048;
light.shadow.mapSize.height = 2048;
…or even bigger. But at some point you’ll hit a limit in GPU max texture size or memory.
For big scenes like yours, the standard light shadows are not really suitable and it’s common to use a different technique such as Cascaded Shadow Maps.
1 Like