Sign in to follow this  
adt7

[XNA] Deferred Rendering & Skybox

Recommended Posts

I'm trying to add a skybox to my scene which is rendered using a deferred render. I'ev been rendering my scene in the normal way, restoring my depth buffer after the deferred pass, then trying to draw the skydome afterwards, but with bad results. If I enable the depth buffer, my model cuts through my terrain (obviously) just like anything else would. If I render it with the depth buffer disabled (like I would in a forward renderer) then it covers the whole screen and I can't see my deferred scene (again, obviously). Reading through this it seems that what I really need to do is restore my stencil buffer (or build one), and then use that when rendering my skybox. Is there a way of doing it using just the depth buffer? If not, how would I restore my stencil buffer? And then how would I read from it within a shader to draw the skydome to only that part of my scene? Edit: Would it be possible instead, to render it as part of my deferred scene, with the depth buffer disabled, then use a stencil mask so that my lighting calculations are not done on the areas covered by the skybox? I believe that is how it was done in STALKER. [Edited by - adt7 on July 24, 2009 4:23:53 AM]

Share this post


Link to post
Share on other sites
I've been doing some research, and some playing around, and it seems the stencil buffer is cleared in XNA whenever you resolve a render target.

So, I'm guessing this means I need to create a stencil buffer as part of my g-buffer. That doesn't seem efficient in the slightest.

Is there no way of resolving a stencil buffer in XNA and then restoring it?

I've currently got a "solution", which is to render my skybox before everything else, with the depth buffer disabled, as you would in a forward renderer, and then in my final lighting pass test for depth equal to 1.0f, and not apply the lighting to those pixels. This seems really hacky though.

EDIT: I've found a "better" solution, I'm now rendering my skydome at the start of my transparent objects pass, scaling it up to be on my far plane and it's working fine.

[Edited by - adt7 on July 25, 2009 6:16:18 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by adt7
then in my final lighting pass test for depth equal to 1.0f, and not apply the lighting to those pixels.


You could instead change your depth comparison function from "LessEqual" to just "Less". Hopefully your sky is rendered at depth = 1.0, then those pixels will get depth rejected and your lights won't apply to the sky.

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