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.
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.
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.
Yes.I just have disabled the shadows in your game GemIslands and gained a better performance.So i think is the shadow that have a huge impact on its fps.
Sorry for long delay in answering on forum – I had a backlog of unanswered stuff that I’m addressing now.
@Didi Thanks for investigating, and I think the toggle to show/hide shadows is a good idea.
Shadows will always have some performance cost. There are some things one just has to do to make Shadow Volumes | Manual | Castle Game Engine work (they need essentially rendering scene 2 times, with and without lights – that’s why even things that don’t cast shadows still affect the overall performance, basically everything is more costly with shadow volumes, not only shadow casters; only DistanceCulling, Castle Game Engine: CastleScene: Class TCastleScene , will help as it really removes shapes). We work on making a different shadows technique, Shadow Maps | Castle Game Engine , easily accessible, but – spoiler alert – it comes with a different set of problems (quality and performance). There’s no perfect solution.
Still, on the engine side, let me see can I bring down the difference 21 vs 65 that you observe as close as possible Let me plat with the testcase you have, I’m sure I can improve some things . From what I understand, you already made a testcase that is nice (separate from GemIslands game),
terrain (1000x1000) with hightmap and walk navigation. I placed about 3500 TCastleScene and TCastleTransform on it.
It took me some time, but I’ve done a significant optimization to the code I found was a bottleneck in this case (shadow volumes + world with many TCastleTransform, Performance of dynamic shadows - testcase · Issue #614 · castle-engine/castle-engine · GitHub ). This actually optimizes all rendering, whether it uses shadow volumes or not, but is most impactful for the shadow volumes case. So I’m really happy about it, it’s a very reasonable optimization (that actually cleans up some code) that just improves performance of ~everything.
Thank you everyone for participating in this thread, and testing the latest CGE with this optimization is most welcome!