Sign in to follow this  
AmidaBucu

VSM, the expensive shader

Recommended Posts

Hi there! I have done the vsm shader in my """engine""", and I hit a newer problem. For a shadow I create a depthmap in the light VP space (indeed, in the "depth, depth*depth" form). I blur that. Then I compute the ratio of the shadow using the vsm formula. And here is the problem. I can't draw the result to the same texture. So i draw the reults into an other texture. And so I have two texture for a shadowmap (a blurred depthmap and a vsm map) It's clear, sure. But how can I manage that? I'm sure using vsm shader with one texture can be. Any Idea? Thx ahead your help! And sorry my veryvery bad english! I hope I disturbed noone! BB

Share this post


Link to post
Share on other sites
I also do things this way in my current project, I render out the shadow map, then I do a single full-screen pass where I render out the shadow occlusion factor to a screen-sized texture. Then during my main pass where I render all of the opaque geometry and apply lighting, I just sample the shadow occlusion texture and use that to adjust the lighting.

What part exactly are you having difficulty managing?

Share this post


Link to post
Share on other sites
So. I have the blurred vsm map. And i have to draw that "occlusion factor"
to somewhere. Now somewhere surely doesn't mean the same texture.
If I drew to the same texture, I would overwrite some pixels, them I'd probably need. Therefore I can't use the same texture for computing vsm and computing "occlusion factor". I need two textures.

You said:
"I render out the shadow map, then I do a single full-screen pass where I render out the shadow occlusion factor to a screen-sized texture."
You also use two textures per one shadow. One to render shadow map, and another one to render "occlusion factor to a screen-sized texture".
I think You use the second one at the final render. Am I right?

So how to avoid using two maps per one shadow?

Share this post


Link to post
Share on other sites
I just create a new texture whose size is the same as the backbuffer. I only store the occlusion value from one light source since I only do shadows for the sun, but if you wanted you could could store the occlusion for up to 4 sources in one A8R8G8B8 texture (use one channel for each light source).

Share this post


Link to post
Share on other sites
This is also called a shadow mask or shadow collector. If you have several different shadow sources you can just alpha blend them in there. For example dedicated character shadows that are blended over the shadows coming from the Cascaded shadow maps can be stored in there or indoor shadows coming from several light sources cached in a texture atlas etc ...

Share this post


Link to post
Share on other sites
To MJP:
So I definitely need as much texture as much shadows I want plus one to store the occlusion value (one texture/4 shadow). Right?

To wolf:
Okay! It looks like It worth to watch that page. Thx


And can I ask U guyz, 3 shadows enough are in the most of situations?

Share this post


Link to post
Share on other sites
Quote:
Original post by AmidaBucu
And can I ask U guyz, 3 shadows enough are in the most of situations?


Well. of course it depends on your scenes, your methods of navigations, etc. But, Whta you are saying essentially is two point lights plus a sun-shadow? Crysis supports at the least 4 point lights plus sun..

For many occasions, that may be enough. But maybe you write the engine in such a way that if a new light (greater than 3) is created, the resources for it can be created on demand, although you may get a little skip when you create the textures the first time.

All that said I would say 4 point lights and one sun shadow is enough for alsmot every occasion if used judiciously (I'm not a fan of VSM for a number of reasons, like the fact you need more than 1 channel of a floating point surface---means you cant pack 4 lgiht into one suface).

Share this post


Link to post
Share on other sites
Quote:
I'm not a fan of VSM for a number of reasons, like the fact you need more than 1 channel of a floating point surface
good point ... check out exponential shadow maps. They only use one channel and look similar or better (?).

Share this post


Link to post
Share on other sites
Quote:
Original post by wolf
Quote:
I'm not a fan of VSM for a number of reasons, like the fact you need more than 1 channel of a floating point surface
good point ... check out exponential shadow maps. They only use one channel and look similar or better (?).


ESM's are pretty nice, but they can have some bad artifacts in certain situations. VSM's with an exponential warp can look a lot better IMO, but their precision requirements make them impractical for most hardware (certainly on consoles).

Share this post


Link to post
Share on other sites
Quote:
Original post by wolf
If you have several different shadow sources you can just alpha blend them in there.

Uhh, I assume you're accumulating illumination (a la deferred lighting) here rather than than munging up a single shadow "mask" over several independent illumination sources?

Share this post


Link to post
Share on other sites
I read it as "accumulating occlusion" in screenspace. So you could do a multiply blend of a really detailed character shadow over top of a scene's less detailed shadows. Then you could use this screenspace shadow mask for the occlusion factor during forward (or deferred) rendering.

Brian Richardson
http://bzztbomb.com/noise/

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyTX
Quote:
Original post by wolf
If you have several different shadow sources you can just alpha blend them in there.

Uhh, I assume you're accumulating illumination (a la deferred lighting) here rather than than munging up a single shadow "mask" over several independent illumination sources?


I think he's talking about doing this for only one light source.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
I think he's talking about doing this for only one light source.

I would hope so, but one light source <=> one "shadow source" in my books :)

Share this post


Link to post
Share on other sites
So. I have 4*6 plus one shadow maps.
And I have to collect results in screen space in 7 fourchanelled texture (indeed, that's at the worst situation).
Is it parctical using 32 (25 with smaller resolution and 7 with screen resolution) for 4 pointlights and a sun?
Asking it in another way, does Crysis take so much video ram?
Or does Crytec create an another way that let them use so much shadow maps with lesser vram?

Share this post


Link to post
Share on other sites
No it's not at all necessary for so many textures. First of all, even if a point light requires 6 textures for a full cubemap, you still only need one channel to store the shadow occlusion term. So for 4 point lights + a directional light you need 5 channels, which is only 2 textures.

Also if memory is tight, you can reuse your cubemap for each point light. So you'd render all 6 sides for a light, then render the occlusion in one channel, then render the shadow maps for another light...rinse, wash, repeat.

Share this post


Link to post
Share on other sites
Quote:
Original post by AmidaBucu
Then what way would be the best solution?


There is never a "best" solution that perfectly fits all problems. What works best might depend on your scene, the size of your shadowmaps, the backbuffer resolution, or the hardware the game is running on.

Share this post


Link to post
Share on other sites
Quote:
I would hope so, but one light source <=> one "shadow source" in my books :)

I alpha blend shadow results in a shadow mask / shadow collector. What is in there are cloud, character, environment shadows and a couple of others. Also from different light sources :-) ... this texture holds grey values that are the result of the shadow calculation.

Share this post


Link to post
Share on other sites
Quote:
Original post by wolf
I alpha blend shadow results in a shadow mask / shadow collector. What is in there are cloud, character, environment shadows and a couple of others. Also from different light sources :-) ... this texture holds grey values that are the result of the shadow calculation.

Wow, so how do you deal with something as simple as coloured lights and their associated partially overlapping shadows? Your approach would seem to fundamentally munge together independent terms in a way that prevents you from getting any sort of reasonable solution here...

But alas, if people are still irrationally scared of the only thing that the rendering equation really does say - namely that incoming light contributions are summed - then I guess you get into these sorts of oddities ;)

In any case, back on topic, deferred rendering allows you to lower the memory footprint by reorganizing the rendering loop; in this case, one can reorganize by the dependency of a given shadow map so that it only needs to be "alive" while computing illumination for the single relevant light, or even the single cascade or cube map face of a light.

[Edited by - AndyTX on October 18, 2008 1:10:33 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by wolf
I alpha blend shadow results in a shadow mask / shadow collector. What is in there are cloud, character, environment shadows and a couple of others. Also from different light sources :-) ... this texture holds grey values that are the result of the shadow calculation.


I agree with Andy.. this doesnt make a lot of sense to me...unless you use one channel per light source.. obviously for sun shadows you can merge eveyrthing together like that, but not for other light sources...? Unless you dont mix shadow-casting lights very often.. then you can get away with it.

Share this post


Link to post
Share on other sites
We do something that is similar (I think) to what wolf was describing. Colored lights still work, because we just store the computed shadow information for each light source (one shadow-casting source / channel). During our lighting pass we can then still sum the contribution from each light source but use the pre-computed shadow information to modulate contribution.

Edit: Huh, on second reading it does sound like wolf's solution combines contributions from multiple sources. So I guess that's more aggressive than what we're doing...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this