2012-04-20 37 views
0

我有一個問題,只是用SlimDX(DirectX 11)渲染一個簡單的旋轉立方體。立方體的旋轉,這些都是我得到的圖像:奇怪的渲染使用SlimDX(孔中的面孔)

Problem with the rendering

我用這個頂點着色器:

float4x4 WorldViewProj : register(c0); 
    float4 VShader(float4 position : POSITION) : SV_POSITION 
    { 
     return mul(float4(position.xyz, 1.0), WorldViewProj); 
    } 

這也是我如何準備WorldViewProj:

ProjectionMatrix = Matrix.PerspectiveFovLH((float)(Math.PI/4.0), 1f, -1, 20); 
ViewMatrix = Matrix.LookAtLH(new Vector3(0f, 0, ypos), new Vector3(0f, 0, 10), new Vector3(0f, 1f, 0f)); 

Matrix positionMatrix = Matrix.Translation(position); 
Matrix rotationMatrix = Matrix.RotationYawPitchRoll(rotation.X, rotation.Y, rotation.Z); 
Matrix scaleMatrix = Matrix.Scaling(scale); 
Matrix worldMatrix = rotationMatrix * scaleMatrix * positionMatrix; 
worldMatrix = Matrix.Transpose(worldMatrix); 

Matrix WorldViewProj = ViewMatrix * ProjectionMatrix * worldMatrix; 

第一所有我看到這個問題:Incorrect Clipping and 3D Projection when using SlimDX

而且,矩陣有可能是錯誤的(因爲我不是轉置視圖或投影,而是轉換世界 - 在相反的情況下,沒有任何東西被渲染)。但即使我將視圖矩陣和投影矩陣都設置爲單位矩陣,「洞」仍然存在。

請幫助和提前致謝!

+0

我不確定是不是手動操作,但是您不是在Matrix.PerspectiveFovLH()中爲近平面指定-1嗎?如果是的話,你爲什麼不設置正值? – Alan 2012-04-20 21:03:06

+0

野生狂猜:z緩衝區分辨率是否太小? – 2012-04-20 21:08:04

+0

即使我這樣做(0.0001f或1f) - 圖片完全一樣。 – 2012-04-20 21:09:53

回答

0

發現問題。這只是索引緩衝區中頂點的錯誤順序。對我感到羞恥:)感謝大家的幫助!