MRT & Z Pre-Pass manually ?
#1 Members - Reputation: 116
Posted 18 January 2011 - 04:45 AM
the implementation with normals, that's why I am using MRT, the first one is for depth (D3DFMT_D24X8) the
second one is for normals (D3DFMT_A8R8G8B8).
Now, I heard about Z Pre-Pass, and right now I have the depth stored, can I use it as depth stencil and let the
comparison made it automatically with D3DCMP_LESSOREQUAL? or I have to do it in the pixel frament,
and discard every pixel if not pass my depth comparison manually?
I know how to use the depth stencil directly writting black, but I don't know if it is possible with MRT AND
I need the depth as texture to be able to reconstruct position from it.
thanks and please sorry my bad grammar, you can spot my errors, that will help too.
#2 Moderators - Reputation: 5488
Posted 18 January 2011 - 01:26 PM
#3 Members - Reputation: 116
Posted 18 January 2011 - 03:59 PM
I thought that is possible to perform a depth test using the depth texture (thinking in shadow map), and discard pixels beyond the depth, but there will be z-fighting for
sure.
#4 Members - Reputation: 416
Posted 18 January 2011 - 10:57 PM
Also, most early-z passes do not cause an increase in speed. You must have an extremely heavy pixel shader to get any benefit out of it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
#5 Moderators - Reputation: 13606
Posted 18 January 2011 - 11:50 PM
D3DFMT_D24X8 is for use as a depth-stencil target, not as an MRT target. As mentioned above, you should use a floating-point, or ARGB8 texture here instead of a D24 one.Hi, I am about to pull the trigger with my first attempt to render to multiple targets, because I want to do SSAO,
the implementation with normals, that's why I am using MRT, the first one is for depth (D3DFMT_D24X8) the
second one is for normals (D3DFMT_A8R8G8B8).
Or, if your card supports reading from depth-buffers, then you don't need MRT - just use the depth-stencil target.
If the exact same geo is drawn with the exact same matrices, there won't be z-fighting.I thought that is possible to perform a depth test using the depth texture (thinking in shadow map), and discard pixels beyond the depth, but there will be z-fighting for sure.
You can read from the depth buffer in DX9 if the end-user has a DX10-level graphics card.In dx9 you cannot read from the depth buffer in the pixel shader. In dx10, you can create a depth buffer with the ability to sample it in the pixel shader.
To do this, you make a texture with D3DFMT_INTZ instead of D3DFMT_D24X8. To check if this is supported you can use:
const static D3DFORMAT D3DFMT_INTZ = (D3DFORMAT) MAKEFOURCC('I','N','T','Z');
bool supportsIntZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, displayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_INTZ);
#6 Members - Reputation: 116
Posted 19 January 2011 - 06:42 AM
@Hodgman that DX9 secret capability is awesome, and yes, was my mistake is D3DFMT_R32F, I was thinking in depth stencil too much
Now I can read it directly, in fact the Z Pre-Pass is working now:
1 - Render to depth
2 - Clear only target, disabling Z Writting and ZFunc to LessEqual
Using 3 point lights, Z Pre Pass saves me about .1 ms on the second pass. Now that I also can read directly from depth, I was curious to make the
depth test by myself on the fragment program, first to ensure that I was using the right projective texture coordinates I did the follow specting to have
z fighting:
float2 Texcoords = 0.5 * In.Other.xy / In.Other.w + float2( 0.5, 0.5 );
Texcoords.y = 1.0f - Texcoords.y;
float dist = In.Other.z/ In.Other.w;
if(dist == tex2D( nolerpsampler, Texcoords ).r)
return float4(1.0f,0.0f,0.0f,1.0f);
And I was right:

Well, I thought it would be a matter of adding bias to the distance and do the test:
...
float dist = (In.Other.z + 0.001f) / In.Other.w;
if(dist > tex2D( nolerpsampler, Texcoords ).r)
return float4(1.0f,0.0f,0.0f,1.0f);
And, I was wrong:

Why? It is supposed to be (dist + bias), and not (dist - bias), why it works inverse to what I spected?
Thanks Again






