Jump to content
  • Advertisement
Sign in to follow this  
ayrton2388

drawing Shadows with the DepthStencilState. Need just a bit of help. [XNA 4.0]

This topic is 2607 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

I`m trying to render shadows using the stencilBuffer. And... doesn`t seem to work. Have a look at my code.



public void DrawShadow(Model model, Matrix world)
{

device.Clear(ClearOptions.Stencil, Color.Black, 0, 0);

dsstate.StencilEnable = true;
dsstate.DepthBufferEnable = true;
dsstate.ReferenceStencil = 0;
dsstate.StencilFunction = CompareFunction.Equal;
dsstate.StencilPass = StencilOperation.Increment;


foreach (ModelMesh mesh in model.Meshes) {
foreach (Effect effect in mesh.Effects)
{
effect.CurrentTechnique = effect.Techniques["Shadow"];
effect.Parameters["World"].SetValue(world*shadow);
effect.Parameters["AlphaTestDirection"].SetValue(-1f);
effect.Parameters["View"].SetValue(FreeCamera.ActiveCamera.View);
effect.Parameters["Projection"].SetValue(FreeCamera.ActiveCamera.Projection);
}
mesh.Draw();
}

dsstate.StencilEnable = false;

}

[/quote]



http://imageshack.us...07/shadowa.jpg/



A few more questions. How can i render the shadow of the leafs that i rendered using a 2 pass approach? I mean, using the correct alpha values.
And is this method efficient for rendering the shadows? I mean, i`ll set the DepthStencilState only once per draw, not for every model, of course, but the DrawShadow() code above was just for testing 1-2 objects.

Share this post


Link to post
Share on other sites
Advertisement

there is shadow on the screenshot


Yes, actually... there are more than 1 shadows. And that`s the problem. Zoom in the picture.
Every poly, i think, has a shadow. And they are overlapping. I want just 1 shadow, having the contour/shape of the tree.

Share this post


Link to post
Share on other sites
http://www.iimmgg.co...7d6e791518fac40

See the 1st half of the picture? there`s only 1 shape, 1 silhouette, 1 contour.
On the second one, there are many. And they are overlapping. You can easily see that.

The 1st half is actually just like the 2nd, except i use 1 for alpha, not 0.3 or whatever. The 2nd has many semi-transparent parts, one over the other. Thing is , i want just 1 shadow, like in the 1st part, that i can make semi-transparent.

Share this post


Link to post
Share on other sites
i see it now. you may need shaders to manage this. i dont know if there is any fixed function tricks to resolve it.

Share this post


Link to post
Share on other sites

http://www.iimmgg.co...7d6e791518fac40

See the 1st half of the picture? there`s only 1 shape, 1 silhouette, 1 contour.
On the second one, there are many. And they are overlapping. You can easily see that.

The 1st half is actually just like the 2nd, except i use 1 for alpha, not 0.3 or whatever. The 2nd has many semi-transparent parts, one over the other. Thing is , i want just 1 shadow, like in the 1st part, that i can make semi-transparent.


I'm just a noob, but can't you just make it like the first one, render it to a texture for example, and then apply that texture with alpha on the ground?
I think the idea would be to make it completely black, and then put alpha on the final result.

Share this post


Link to post
Share on other sites

[quote name='andreilng' timestamp='1306200407' post='4814837']
http://www.iimmgg.co...7d6e791518fac40

See the 1st half of the picture? there`s only 1 shape, 1 silhouette, 1 contour.
On the second one, there are many. And they are overlapping. You can easily see that.

The 1st half is actually just like the 2nd, except i use 1 for alpha, not 0.3 or whatever. The 2nd has many semi-transparent parts, one over the other. Thing is , i want just 1 shadow, like in the 1st part, that i can make semi-transparent.


I'm just a noob, but can't you just make it like the first one, render it to a texture for example, and then apply that texture with alpha on the ground?
I think the idea would be to make it completely black, and then put alpha on the final result.
[/quote]

That`s what is was trying, except not rendering to a texture, but using the stencil. My pixel shader for the shadow simply returns black.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!