HLSL question

Started by
3 comments, last by Mezz 19 years, 8 months ago
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.
Advertisement
PS 1.x do not actually support depth write.

Niko Suni

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.
Please do verify the fact from the SDK. I did [smile]

-Nik

Niko Suni

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

This topic is closed to new replies.

Advertisement