2012-04-05 35 views
2

我還沒有意識到這一段時間,但我的深度圖搞亂了。對於:黑色像素=近剪裁平面,白色像素=遠剪裁平面 - 基本上,如果我朝地面上的100x1x100方格走,然後走到它(達到99,0和99的座標),則整個深度貼圖將變爲白色。這表明每個像素都在遠處的剪輯平面上,我不想要! exampleC#/ XNA/HLSL - 深度圖擰緊

這是處理呈現深度圖中的代碼:

GraphicsDevice.Clear(Color.White); 
effect.MainEffect.CurrentTechnique = effect.MainEffect.Techniques["DepthProcess"]; 
GraphicsDevice.SetVertexBuffer(line); 
effect.MainEffect.CurrentTechnique.Passes[0].Apply(); 
GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); 

而HLSL代碼(頂點着色器,像素着色器):

DVOut DVShader(VIn _in) 
{ 
    DVOut o; 
    o.position = mul(_in.position, WorldViewProjection); 
    float a = o.position.z/o.position.w; 
    o.color = float4(a,a,a,1); 
    return o; 
} 

float4 DPShader(DVOut _in) : COLOR 
{ 
    return _in.color; 
} 

technique DepthProcess 
{ 
    pass Pass0 
    { 
     ZEnable = TRUE; 
     ZWriteEnable = TRUE; 
     AlphaBlendEnable = FALSE; 
     VertexShader = compile vs_2_0 DVShader(); 
     PixelShader = compile ps_2_0 DPShader(); 
    } 
} 

就是因爲這樣一個1/0錯誤?或與矩陣乘法有問題?或者w/e?

回答

0

已解決。不知何故,乘法將W分量設置爲非常小的值。

而不是同質分裂,我除以10,這給了一個可以接受的結果。