Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

HLSL Shadows


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 dawchiks   Members   -  Reputation: 125

Like
0Likes
Like

Posted 18 January 2009 - 12:51 AM

Hi there. I've been learning HLSL for a while, and now, I think, it's time to learn to create shadows. what is the easiest way ( the easiest technique) to create shadows using HLSL? thx.

Sponsor:

#2 TheObi   Members   -  Reputation: 122

Like
0Likes
Like

Posted 18 January 2009 - 01:00 AM

Hi dawchiks,

this is a good tutorial:
http://www.gamedev.net/reference/articles/article2193.asp


#3 sybixsus   Members   -  Reputation: 214

Like
0Likes
Like

Posted 18 January 2009 - 07:56 AM

When I was trying to learn shadowmapping, I had a really hard time getting my head around the concepts at first. All the articles I read seemed to talk to someone who'd already got their head around the concepts. The article which really helped me get my head around it ( and it is a pretty simple concept once you get it ) was this one :

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Shadow_map.php

I found Anirudh.S Shastry's article ( linked above by TheObi ) very useful for adding a screenspace blur but I couldn't get the basics down until I read Riemers one. The sample code is C# and XNA but I wasn't using C# or XNA at the time, so I think it's understandable whatever language/api/engine you're using.



#4 Matt Aufderheide   Members   -  Reputation: 99

Like
0Likes
Like

Posted 18 January 2009 - 11:38 AM

Remember that using HLSL is only a part of doing the shadow mapping. You also need to set up the various render targets, textures and render the shadow map using D3D.

I don't know how advanced you are in D3D/D3DX, but the basic things are :

1) create a texture as a render target using a floating point format (like R32F) and get its surface.

2) create a depth buffer the same size.

3) define a light position. Compute view and projection matrices for the shadow camera..start with a directional light first because its very easy. Make the view matrix just face the object you want to cast shadows, and define the projection matrix as orthagonal with a size not too big, like 2000,2000 or something.

4) Render the scene using the shadow view and projection to your floating point surface (make sure you also set the new depth buffer and clear them both). Your shader just needs to output some form of the distance from the light position to the world space position (numerous optimizations exist but the easiest is to just output length(light_pos.xyz, worldspace_pos.xyz);

5) render the final scene and project the depth texture by using the light position, view and and projection matrices...there are many examples for texture projection. Then just compute the shadow by doing th same depth calculation you did in the shadow pass in this pass, calculating the distance form the light to the object vertex. Then just compare that distance to the projected depth texture. if the shadow depth is less than the calculated distance, then make it shadowed. Normally you also need to bias the depth map a bit, to prevent "shadow acne", just multiply the depth map value by a small amount before the comparison.

I hope this is at least somewhat comprehensible.. i was very confused by shadow mapping and such when I first started to mess with it. But its really very simple; sometimes the implementation details distract from the basic theory: render two views, one from the camera view, one from the light view. What's covered up the light's view is shadowed in your camera view (if the light can't "see" something it is in shadow).

Also, be warned that shadow quality will be very bad using just the above method--much work will have to be done later to get optimal shadows.

#5 dawchiks   Members   -  Reputation: 125

Like
0Likes
Like

Posted 20 January 2009 - 02:46 AM

thx guys. that was really helpful. :P




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS