Skip to main content
gamedev.net
🔒 Locked

HLSL stencilbuffer settings

Started by mrhiggins Sep 20, 2010 at 6:36 PM 3 replies 1.2k views
Original Post
mrhiggins
mrhiggins
I have a big problem and my knowledge of hlsl is too less to solve this by my own.


Following Situation
We make a visualisation of sun system.
Planets are rendered with depth buffer, the sun as a quad with effects like beams and so on, with alphablending - so without depth buffer.

We do it like this:

1. Render planets behind sun.

2. Render sun as a round thing on quad

3. Render planets in front of sun.

4. Render effects in front of all planets IF SUN CENTER IS VISIBLE AND NOT BEHIND A PLANET.


And at the last point i have the problem. Here i have a screenshot:
www.goodnewsfans.de/problem.jpg
At the top you see the sun with both steps - the sun and the effects.
The second screenshot is just the effects. But i want to see these effects only if the center of the sun is not behind the planet.

The good thing is that the effects are just 1 vertex, and we make the quad to render the beams and also the lens flares in the geometry shader, so i have the sunCenterPosition for all pixels in pixelshaders.


My idea is to write in step 3. when i render the planets in front of sun, a 1 into the stencilbuffer if there is a planet. The rest is 0. In step4, i will multiply it with the color of effect. Can i use another point in stencilbuffer and writing on framebuffer? In the stencilbuffer the centralpoint of sun is important for an pixel of the lensflare...





How can i do this?
Any idea?
Erik Rufelt
Erik Rufelt
You can create a depth-stencil surface that can also be read as a shader-resource. You could use SampleLevel to read this in the geometry-shader. See the last section of this page: http://msdn.microsoft.com/en-us/library/bb205074(VS.85).aspx, and also for example the soft particles example in the SDK, which i think does this.

Another solution is to use an occlusion query, and only render the last sun-effect if rendering the sun center-point passes the depth-test.
mrhiggins
mrhiggins
Works one of these solutions just in the shader? That would be the best thing for us....
Erik Rufelt
Erik Rufelt
Well, you need to unbind the depth-stencil-view, and instead bind the shader-resource, to be able to read the texture in the shader. With the occlusion query you need to create the occlusion predicate in your program, and then set the condition for the last effect to be drawn, so that one doesn't require any change in the shader.
mrhiggins
mrhiggins
Sorry - i have no idea what you are talking about:-D

I worked a lot with HLSL, so i would prefer the solution in which i can do most things in the shader, not going to deep into the device things, cause i didn't wrote them.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.