Sign in to follow this  

HLSL question

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello! I tried to modify the depth value within a pixel shader and have some problems to get it working. I used the following structures: struct PS_INPUT { float4 Pos : POSITION; float4 Tex0 : TEXCOORD0; }; struct PS_OUTPUT { float4 ColOut : COLOR; float4 DepthOut : DEPTH; }; and the following shader code: PS_OUTPUT MainPS(PS_INPUT IN) { PS_OUTPUT Out; Out.ColOut = (0.0f, 0.0f, 0.0f, 1.0f); Out.DepthOut = 1.0f; return Out; } I know, this seems to be not a useful shader and of course it is not. just the problem is, that compilation fails if I use another return type than float4 mapped to COLOR. as target, ps_1_1 is used. All I need is to modify the depth value.

Share this post


Link to post
Share on other sites
hmm... thats interesting. What about this:

!!FP1.0

# f[WPOS] : fragment in trapezoidal space (window position)
# f[TEX0] : fragment's position in post-perspective space of the light


RCP R0.x, f[TEX0].w; # R0.x = 1 / w_L
MUL R1, f[TEX0], R0.x; # R1 = (x_L/w_L, y_L/w_L, z_L/w_L, 1)

MAD R2.z, R1.z, 0.5, 0.5; # R2.z = R1.z * 0.5 + 0.5; depth is now in the range [0;1]

MUL o[DEPR], R2.z, R2.z; # o[DEPR] = z_L/w_L * 0.5 + 0.5; replace "z_T" with "z_L"

MOV o[COLR], f[COL0];

END

this shader code is from the TSM recipe paper at http://www.comp.nus.edu.sg/~tants/tsm/TSM_recipe.html. I don't know too much about the shader assembly language, but I think that MUL o[DEPR], R2.z, r2.z replaces the actual depth buffer value, or is this wrong?

Nevertheless, I tried to compile my HLSL code with ps_2_0 target and it also didn't work.

Share this post


Link to post
Share on other sites
You only need a single float for your DepthOut variable, not a float4. To alter depth in ps_1_x the only way I am aware of doing it is using assembly shaders and using the texdepth/texm3x2depth etc. instructions (only supported in 1.3 and 1.4 in some cases).

-Mezz

Share this post


Link to post
Share on other sites

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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