DirectX 9光投影

我试图从光线空间看到组件“z”的变化。 在顶点着色器组件'z'中划分'w'不是0.但是在用texcoord1向像素着色器发送float4之后,所有matrix都是好的。 这里是代码:

float4x4 MatWorld; float4x4 MatView; float4x4 MatProjection; float4 LightViewMatrix; float4 LightProjectionMatrix; float4 LightPosition; texture tex0; sampler2D ShadowMap = sampler_state { texture = tex0; }; struct VertexOut { float4 position : POSITION; float2 tex : TEXCOORD0; float4 lightViewPosition : TEXCOORD1; }; struct VertexIn { float4 position : POSITION; float2 tex : TEXCOORD0; }; VertexOut VSLight(VertexIn In) { VertexOut Out; In.position.w = 1; Out.position = mul(In.position, MatWorld); Out.lightViewPosition = Out.position; Out.lightViewPosition = mul(Out.lightViewPosition, LightViewMatrix); Out.lightViewPosition = mul(Out.lightViewPosition, LightProjectionMatrix); Out.position = mul(Out.position, MatView); Out.position = mul(Out.position, MatProjection); Out.tex = In.tex; return Out; } float4 PSLight(float4 Color : COLOR, float2 tex : TEXCOORD0, float4 lightViewPosition : TEXCOORD1) : COLOR { float depth = lightViewPosition.z / lightViewPosition.w; if (depth == 0) { return float4(0, 0, 0, 1); } return float4(depth, 0, 0, 1); } technique T1 { pass P0 { VertexShader = compile vs_2_0 VSLight(); PixelShader = compile ps_2_0 PSLight(); } }; 

所有物体都是黑色的。 对不起,我的英文稍差。