Performance with dynamic shadows

I have now found that dynamic shadows have a very big impact on performance. For testing I created a terrain (1000x1000) with hightmap and walk navigation. I placed about 3500 TCastleScene and TCastleTransform on it.

Directional light with shadows = true → 21 FPS
Directional light with shadows = false → 65 FPS

It doesn’t matter whether the items have castshadows set to true or false.
So I can choose between good performance or shadows.

It would be very usefull to have some shadows on only some important items.
Grass, rocks or flowers do not need shadow in my oppinion, but these make up the majority of the items. Setting them to castshadow = false shows no performance gain.

I am able to get high framerates on my similarly sized tiled terrain. But I don’t have a zillion scenes yet maybe as many as 100 so far. I have tied shadow settings to my LOD handling, so the distant terrain tiles don’t cast or receive shadows, and distant objects don’t cast or receive shadows. I think this may help. My terrain is tiled though. Tilesize is 100x100 and then the grid size is about 11x11 right now, so about the same sized terrain. If you want to explore tiling your terrain (which then allows you to drop distance vertex count too)… I could help, but my code is pretty unruly in that area as it has experienced constant flux.

Shadows did so much to bring my world to life, and make me introduce moving sun and day night cycle… I would rather suffer at 20fps than give them up!

Also you might remove that distant grass completely, or set to exists=false when stuff like grass is really far away. Just having to figure out if it should cast shadow for 1000s of objects is time consuming I am sure.

Maybe you can add a switch for shadow effects in the option page.So players choose good performance or shadows themselves. :grinning:

Yes, dividing the terrain seems to me to be a good way to achieve better performance. I’ll do some research in this direction.
Yes, shadows are really important, you can’t really do without them.

Yes, the next game will get the option shadow yes/no. :+1:t4:

The key to tiling the terrain is the Offset field that Michalis added to the TCastleTerrain a year ago. Then the trick is having access to 3 neighbors to connect the edge seams. … Actually you don’t need to worry about seams if you are just using the standard noise. I do because I make a copy of the noise result data so it can be modified.