Terrain Splatting and Shadowmaps - bad performance scaling

Started by
5 comments, last by RuneHjelm 16 years, 1 month ago
My current terrain implementation runs with the splatting technique, where transitions are taken care of with alpha transitions and rendering of multiple layers (one layer for each terraintype present on a given terrain patch). However, this poses a problem for me, when it comes to shadows. I use shadowmaps, and to render shadows on the splatting-terrain, I have to render shadows on EACH layer! That means a shadow rendering once for the base layer (that ensures, that you can't see through the terrain on transitions), and once for each terraintype layer. That is ok if there is only something like 2 terraintypes. But once I begin adding more layers, 4-5, maybe more, it takes a heavy toll on the system. With just 2 terraintypes, I have to render shadows 3 times, which is in itself quite a bit. At around 4 layers, the lag becomes very noticable. ----------------------------------------- I wanted to solve the problem by first rendering the entire terrain without shadows, and then render shadows with a consequtive shadow rendering pass, making the shadows a kind of "overlay". I have not implemented it yet, because I foresaw a big problem with this approach, when it comes to multiple lights: The lights will already have affected the terrain in the pre-shadow pass, and then the shadowpass will just write across all that, dimming out light effects, that are not part of the light, that generated a given shadow... How do I solve this to make the performance scale well, as I add further layers?
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.
Advertisement
Something is wrong here.. there is no way you should have to render apply the shadow more than once.. can you explain you rendering method in more detail? It sounds like you are making a basic mistake like not using multi-textureing. You should be doing this all in a pixel shader though.

Normally, the shader would do something like this:

1)Create the the final color map by lerping the various texture samples together
2) calculate the diffuse lighting term
3) calculate the shadow map value
4) mulitply the lighting by the shadow map.
5) muliply the final color by the lighting * suncolor .. you can add in ambient before this as well..

There should be no reason to ever do shadows (or lighting) multiple times...unless you are using multiple passes, which you shouldnt be. If you need mulitple passes for some reason, there should be a way to only do sun lighting with shadows in one pass.

At the moment I do multipass rendering.

I don't have a limit on the number of terraintypes per patch, and I can't upload an unlimited amount of textures to the card...

I use a texturemap/normalmap/alphamap per layer. With a maximum of 8 simultaneous textures per pass (on my 7900 card - I don't want to make my game require a bleeding edge card), that limits me to only blending two layers in a single pass (even if I store multiple alphamaps in the rgba channels of one texture, I can only push it to 3 layers in one pass - and that is provided I use only one shadow!).

Anyway, you gave me some good ideas that I will work with. I will see how far I can push running it in a single pass.

[Edited by - Mercenarey on March 22, 2008 9:00:53 AM]
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.
I just looked up the stuff on simultaneous textures, and it seems I confused the flag on devicecaps (MaxSimultaneousTextures) with how many you can use on a shader. It goes only for FFP.

And since I use PS_30, I should be unlimited. Ok, lets see what this baby can take :)
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.
Quote:Original post by Mercenarey
I just looked up the stuff on simultaneous textures, and it seems I confused the flag on devicecaps (MaxSimultaneousTextures) with how many you can use on a shader. It goes only for FFP.

And since I use PS_30, I should be unlimited. Ok, lets see what this baby can take :)


And also there are ways to manage textures so that you only need to load the ones you need into video memory. Nearly all modern terrain renderers that use splatting do something like what I've suggested.

In other words any performance hit you take from having multiple textures loaded will be likely far less than multi-pass rendering.

I don't suppose you could show me your shader? I would like to see how you divide up the steps. Especially how you manage to only do a single shadowmap sample (i would have thought you needed one for each light, and that you couldn't divide up the light/shadow steps).
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.
Hoho, I finished implementing it. Speed increased some 6-8 fold :)

Thanx alot!


Edit: oops, logged on another account, Im Mercenarey.

This topic is closed to new replies.

Advertisement