Sign in to follow this  
ayrton2388

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

Recommended Posts

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

[quote]

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]



[url="http://imageshack.us/photo/my-images/807/shadowa.jpg/"]http://imageshack.us...07/shadowa.jpg/[/url]



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
[quote name='Geri' timestamp='1306196019' post='4814814']
there is shadow on the screenshot
[/quote]

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
[url="http://www.iimmgg.com/image/25f69bb123fe9534e7d6e791518fac40"]http://www.iimmgg.co...7d6e791518fac40[/url]

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
[quote name='andreilng' timestamp='1306200407' post='4814837']
[url="http://www.iimmgg.com/image/25f69bb123fe9534e7d6e791518fac40"]http://www.iimmgg.co...7d6e791518fac40[/url]

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.
[/quote]

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='stromchin' timestamp='1306216647' post='4814901']
[quote name='andreilng' timestamp='1306200407' post='4814837']
[url="http://www.iimmgg.com/image/25f69bb123fe9534e7d6e791518fac40"]http://www.iimmgg.co...7d6e791518fac40[/url]

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.
[/quote]

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
And also cmp to less.

may try this:
[url="http://www.codesampler.com/dx9src/dx9src_7.htm#dx9_shadow_volume"]http://www.codesampl...9_shadow_volume[/url]

If not works, try to sort the polygons based on the distance from the camera. I suggest shell sort or quicksort.



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