render target cache system (shadows)

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

render target cache system (shadows)

Post by stefbuet »

Hi,
I've seen some shadows optimisations from leadwerks engine, however they don't want to explain me precisly what they've done, so I'm going to try to do this alone.
My goal is to use shadows faster with no rendering difference with my actual system. I think a great thing would be that instead of using 1 shadow map per light, we use 3 render target per light : 1 used for static shadow map (not moving objects), another for dynamic shadow map (moving objects), and the last one would be a Z-buffer from the static shadow map render to produce the dynamic one with Z-sorting (by ouself in the shader). The trick is to render the static shadow map / Z-buffer 1 time, and then only update the dynamic shadow map with moving objects. At the end we merge both static & dynamic maps to produce our shadows.

Here is a little illustration I did :
Image

I would like to know what you think of this system.
Is it better to use idle/moving object lists or just define directly static/dynamic nodes forever so we don't have to check if a node moved from the last frame?
What do you think in term of performance ? Using 3 render target instead of 1 should run slower on the GPU, however if you have a scene of 300 000 polygons and only like 1000 polygones moving you can go up to 300 times faster.
[ cube map :
normal render : 6 * 300 000 = 1 800 000 polys
only moving objects : 6000 polys ]

Did anyone on this forum attempted such a system ?
I think it's called a cache system and it can be also used with reflexion maps. But here I'm only after shadows... for now :)

Thanks all :wink:

[EDIT :](edit2 :Following remark is wrong) I didn't thought, but how can we don't update the static buffer if the camera moves? shadow maps are camera dependent, so this would be an optimisation for non-moving camera only ? That sucks :(
Last edited by stefbuet on Thu Sep 23, 2010 9:04 pm, edited 1 time in total.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Yeah and think about the fact of moving lights...even worse.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

Yep but most of my levels will be static exept some physic nodes and probably most of the lights will be static too.
But well, I really didn't think of camera mouvement.

However, if you look at this video :
http://www.youtube.com/watch?v=uG5cdI1Gqu0

You will see that even when moving the camera the engine only render moving objects :o
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Huh? Why is camera moving going to affect anything (Lights yes, but not camera...) :?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

Because the shadow maps (static or dynamic) are the depth (from camera) with the light point of view. So if we change the cam position, pixel depth will change and shadow map, even from not moving objects, have to be updated ? Or I don't get something ?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

The depth from the camera will change, but not from the light...

Shadow maps are the depth from the *light* from the *light* point of view. Your view position is irrelevant.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

Edit: oh! yep I'm sorry I used 'from light depth' in my shaders, I don't know why I thought I was doing with camera depth...
So, now it's more clear in my head, what do you think guys of this method ? If the light is not moving ? I will give a shot and do some benchmark. Being abble to use caching on static lights and standard method for moving light should be nice.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

I'm still confused as to why you'd need a separate buffer for moving objects. You're still capturing the lighting situations at the moment the frame is rendered. Their velocity is completely irrelevant for lighting. If you want to do some per-pixel motion blur, a better idea would be to just have a buffer that contains per-pixel velocity. Still, this has nothing to do with the lighting.
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

No, it's just about shadows.
If an object is moving, its shadow wont be the same. I don't need any velocity, just need to know if objects moved from the previous frame or not.
The trick is keep old object shadow map data in a first buffer, and draw moving object data in another, then blend both buffer to get the final shadow map so you save static object render time.
For now I'm looking for an idea to get a Z-buffer from static objects only, to be able to do some Z-sorting on the 'moving objects' buffer, and this is dependent of the camera :p
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Yep, the most important thing to keep in mind is doing a depth test when combining the static and moving buffers, everything else is pretty straightforward.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply