Jump to content
  • Advertisement
Sign in to follow this  
resle

[D3D10] Variance Shadow Mapping for dummies

This topic is 3454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Once again I ask you to correct me if I didn't understand something properly... As far as I've understood from code snippets and vague tutorials, VSM should go like this: 1) Create a texture, the biggest, the better, with a format suitable to accomodate for two distinct full precision float values (which format is the ideal, by the way?) 2) Switch the render target to said texture 3) Set the view and world matrices like if the... light source was the camera (what about projection?) 4) Render using the normal vertex shader, but a pixel shader that will store in the render target 2 values: depth and squared depth 5) Switch back the render target to the default backbuffer surface 6) Render using the normal vertex shader, but a pixel shader that... well, does all that messy job that I haven't understood at all, sampling the shadowmap we rendered before, and fiddling with values Before going on expanding the last step... could you help me elaborate on this?

Share this post


Link to post
Share on other sites
Advertisement
1- With modern hardware 2-channel Float16 or Float32 look fine.
3- If your light is directional, then you need orthogonal projection. If it's a spot you need a standard perspective projection. The matrix can be calculated by using light parameters, where the aperture angle corresponds to the field of view of a standard camera. For point lights several techniques are available, the more intuitive is considering an omni like 6 spots each with 90 degrees angle. Look for dual paraboloid mapping if you don't want to deal with a cubemap. There's also another technique which unrolls the cubemap into a single 2d texture.
6- for each point you are drawing, get it's position in world coordinates. Transform it in light-space and sample the depth map accordingly. If the point you are drawing is closer than the sampled depth, it's not shadowed, otherwise apply any algorithm you like (VSM/PCF/etc).

Hope this helps :)

Share this post


Link to post
Share on other sites
Quote:
Original post by undead
1- With modern hardware 2-channel Float16 or Float32 look fine.
3- If your light is directional, then you need orthogonal projection. If it's a spot you need a standard perspective projection. The matrix can be calculated by using light parameters, where the aperture angle corresponds to the field of view of a standard camera. For point lights several techniques are available, the more intuitive is considering an omni like 6 spots each with 90 degrees angle. Look for dual paraboloid mapping if you don't want to deal with a cubemap. There's also another technique which unrolls the cubemap into a single 2d texture.
6- for each point you are drawing, get it's position in world coordinates. Transform it in light-space and sample the depth map accordingly. If the point you are drawing is closer than the sampled depth, it's not shadowed, otherwise apply any algorithm you like (VSM/PCF/etc).

Hope this helps :)


Thanks :)
Well.. point (3) got me confused a bit. I am going to have, to begin experimenting, a single light which we can call "the sun". I suppose it's a point light after all. So the things about dual paraboloid mapping should apply, only I don't know what that means at all :D

Before even trying to touch point (6) I think I will try to get a proper shadowmap rendered, post it and see if it's correct..

Share this post


Link to post
Share on other sites
It's not correct to say the sun is a point light, although actually the sun IS an huge point light far far away.

The problem is the sun is so huge and so far that rays arriving to earth are parallel.

Since they are parallel, the sunlight is usually modeled via a directional light, which differs from spot light because its rays are parallel. If you used a perspective projection to model its behaviour, you wouldn't fire parallel rays. The solution is an orthogonal projection.

IMHO the simplest shadow map is the spotlight/perspective. I'd start with a simple room with a sphere/box and a single spotlight.

Share this post


Link to post
Share on other sites
About creating the rendertarget..

In the Shader, it's simply declared like this:
Texture2D ShadowMap;

Whereas in the program itself, it gets a little more complicated..
1) Create a texture with
width = 1024
height = 1024
format = DXGI_R32G32_FLOAT
bind = D3D10_BIND_SHADER_RESOURCE || D3D10_BIND_RENDER_TARGET

2) CreateRenderTargetView(texture2d,NULL,@RenderTargetView);

3) .... now what is the correct way to "link" RenderTargetView to the shader's "ShadowMap" var so that when I call OMSetRenderTargets I am actually telling the shader to render over "ShadowMap"?

Sorry for the stream of newbieness :) (I try to follow the documentation but paradoxically the concise style of writing clashes with my understanding of english and I tend to learn ten times faster here!)

Share this post


Link to post
Share on other sites
Quote:
Original post by undead
I'm sorry but I'm not into DX10. I'm still working on a DX9 renderer. :(


Thanks a lot anyway for helping :)
I've moved from OpenGL to DX9 and it has been fairly traumatic but.. not as moving from DX9 to DX10!

Share this post


Link to post
Share on other sites
hi, for the rendertarget usage thing:

effect->GetVariableByName("ShadowMap")->AsShaderResource()->SetResource(ShadowRenderTarget->getShaderResourceView());

Share this post


Link to post
Share on other sites
Thanks Wavetable. So, unraveling the block..

a = effect->GetVariableByName("ShadowMap")->AsShaderResource()
b = ShadowRenderTarget->getShaderResourceView()
a-> SetResource(b);

a is an ID3D10EffectShaderResourceVariable and represents the target texture which is declared in the shader as Texture2d

b is an ID3D10ShaderResourceView and represents a view (I must still properly understand what this means) of the Render Target I created

The final step is a bit beyond my comprehension (looks like what I use to set the current diffuse texture..) but I'll try anyway


Share this post


Link to post
Share on other sites
yes, the final step is equal to setting any other texture.
whereas, there is not really something that is named 'texture' in DX10.
it's all a resource. when using this resource as input in a shader it must be made visible to (viewable by) the shader -> ShaderResourceView.
at least this is how i interpret it, but maybe the 'View' comes from the ModelView(Controler) concept?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!