Sign in to follow this  
joe_bubamara

FXComposer - How to display z-buffer in a render panel

Recommended Posts

I am trying to implement shadowmap algorithm, and have written 2 passes which are really simple, just to calculate depth values and display those. But I don't seem to be able to display z-buffer. I have try to display texture I am rendering depth to, but it didn't work. Neither does work if I disable render to texture and just writes z values as out color (I do disable second pass in that case). I only see flat color, no gradient. Below are my 2 passes, first one just transformes to light space and outputs z values as color, second one transformes to clipspace and display color from the texture (z-values). // pass 1 void shadowVS( float4 p : POSITION, out float Z : TEXCOORD0, out float4 P : POSITION ) { float4x4 LVP = mul(LV,LP); // light-view-projection //P = mul(float4(p.xyz,1),LVP); P = mul(p,LVP); P /= P.w; Z = P.z; } float4 shadowPS( float Z : TEXCOORD0) : COLOR { return float4(Z,Z,Z,1); } /// pass 2 void useShadowVS( float4 p : POSITION, float4 uv : TEXCOORD0, out float4 P : POSITION, out float4 UV : TEXCOORD0 ) { P = mul(p,WVP); UV = uv; } float4 useShadowPS( float4 uv : TEXCOORD0) : COLOR { return tex2D(ShadSampler,uv) - (0.5,0.5,0.5); } // this one is version without second pass (and without pixel shader): float4 shadowVS( float4 p : POSITION, //out float Z : TEXCOORD0, out float4 P : POSITION ) : COLOR { float4x4 LVP = mul(LV,LP); // light-view-projection //P = mul(float4(p.xyz,1),LVP); P = mul(p,LVP); P /= P.w; float Z = P.z; P = mul(p,WVP); // position in clipspace return (Z,Z,Z,1) - (0.5,0.5,0.5); // color as z-value } [Edited by - joe_bubamara on May 8, 2008 4:28:36 AM]

Share this post


Link to post
Share on other sites
1.) You have to divide by w in the pixel shader, not in the vertex shader. Othwerwise the value won't interpolate correctly.

2.) No need to subtract 0.5 from your depth before outputting it

3.) If you use PIX, you can view any surface you've rendered without having to display it to the screen. Just find it in the list of created surfaces and it will show up in the display in the bottom right

Share this post


Link to post
Share on other sites
thnks;

I also found that I have to divide z value with some constant, since it get's much bigger then 1.0. Also I saw flat white color because I needed scale:

This one displays z buffer:

float4 main(float4 p : POSITION,
out float4 P : POSITION) : COLOR
{
float4x4 LVP= mul(LV,LP);
P = mul(float4(p.xyz,1),W);
P = mul(P,LVP);
float z = p.z / zs; // zs I used was 10.
//P = mul(p,WVP); // output clipspace
return float4(z,z,z,1);
}

I did as you said MJP, in 2 pas version, and it works fine now. Thnks for tips.

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