Sign in to follow this  
lomateron

deferred shading and clearing the swap chain render target

Recommended Posts

I clear the depth to 1.0f every frame

In the final part were I render to the swap chain render target using the position, color, normal, etc textures

I want the pixel shader to process only the pixels that have a depth value different than 1.0f

How do I do that?

Share this post


Link to post
Share on other sites

"depth value different than 1.0f" I am not referring to the depth value I am writing with the vertex shader(I have disabled writing to the depthStencilView), I am referringg to the depth value that is already in the depthStencilView

 

OHHHHHHHHH I get it now, sorry it was a stupid question

Edited by lomateron

Share this post


Link to post
Share on other sites


You could write to a fullscreen polygon that at depth 1.0f with a depth-test of less-than

 

If the intention is to clear the depth buffer or any other buffer - clear command is superior in performance. This is stated in many documentation from AMD and NVidia. 

 

Cheers!

Share this post


Link to post
Share on other sites

ok so I draw a fullscreen polygon with depth: z = 1.0f

and I compare this value with the depthStencilView value and I configured it so it passes the test when NOT EQUAL

but the test always passes when z = 1.0f and w != 1.0f 

I want the test to fail only when z=1.0f

why is "w" value affecting the test?

 

I know that if w<=0 the vertex is discarded

Edited by lomateron

Share this post


Link to post
Share on other sites

the SV_POSITION system value is supposed to be in Normalized Device Coordinates or Clip coordinates, so that the pipeline can clip your primitives to the view frustum.

After that the vertices are denormalized (division by w) and rasterized, so a w != 1 will naturally effect your vertex position.

 

Regarding your deferred shading setup:

Is there really a situation, when you have to NOT draw a pixel in the lighting pass? If no, then just disable the depth test, do not clear any back buffer of the swap chain and overdraw the previous image.

If you have compute shader available, they are a neat solution too, because launching a compute shader kernel benefits from much less overhead than invoking the graphic pipeline.

 

I'm just guessing here but the only reason I can imagine why you would not want to draw a pixel in the lighting pass is because it belongs to a skybox or geometry that is not lit dynamically. I encourage you to use the stencil buffer for this purpose - maybe tell us why you want to draw only pixel with depth = 1?

Share this post


Link to post
Share on other sites

I do this because I think it is the fastest way:

 

I clear the depthStencilView to 1.0, this is the only thing that I clear every frame

I render to the position, normals, color, etc textures using the same depth stecil that I cleared

then when doing the lighting first I render a fullscreen primitive with depth value 1.0 and I compare this depth to the depthStencilView and only the pixels that have a depth value diferent than 1.0f get rendered, this fullscreen primitive renders a kind of global illumination technique and depth writing is disabled.

Then I render light spheres using blending addition, using the same previous depth test.

An finally I render the sky background by changing the depth test so it passes only when the depth test is equal.

 

But I am having problems rendering the light spheres because as I said the depth test only fails when z=1 and w=1 and I can't change "w" to 1 because it messes up the position of my spheres.

Share this post


Link to post
Share on other sites

I did it!

without using the stencil test

the light spheres faces have to be flipped so only the inner faces get rendered.

"z" gets divided by "w" before the depth test so in the vertex shader I output z=w*z;

there is still the depthclip test "0 <= z <= w", so I have to disable it by creating a rasterizerState with DepthClipEnable: FALSE

Edited by lomateron

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