我希望通过从文件中导入深度图来呈现深度图,然后创建一个顶点和索引数组,然后使用基本着色器显示它(只需将视图和投影矩阵应用在上面,然后显示)。我知道基于GPU的解决方案,但是,我希望在呈现顶点之前使用CPU执行额外的计算。
所以,基本上,我要做的是,我的顶点在网格中有深度,然后导入三角形,如下所示:
+--+--+--+--+--+--+
¦ \¦ \¦ \¦ \¦ \¦ \¦
+--+--+--+--+--+--+ meaning that I simply split every quad spanned by four pixels
¦ \¦ \¦ \¦ \¦ \¦ \¦ into two triangles.
+--+--+--+--+--+--+
¦ \¦ \¦ \¦ \¦ \¦ \¦
+--+--+--+--+--+--+
当我在谷歌上找到第一张最好的深度地图时,我得到了以下结果:
然而,一旦我把相机移起来,奇怪的事情就会发生:
这个问题似乎只有在彼此背后呈现多个三角形时才会出现。在这种情况下,后面的三角形(无限深的黑色三角形或前面物体后面的墙)似乎会发光。另外,当我使用"PIX for Windows“并使用”调试此像素“功能时,我会得到我检查过的每个buggy像素的两个三角形。
呈现的步骤如下:
Initialize
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
IsMouseVisible = true;
Draw
GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 0, 0);
DrawModel();
spriteBatch.Begin();
DrawControls();
DrawFileBrowser();
spriteBatch.End();
base.Draw(gameTime);
DrawModel
GraphicsDevice.RasterizerState =
new RasterizerState {
CullMode = CullMode.None
};
// [...]
// set up view and projection matrix
// [...]
GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList,
vertices,
0,
vertices.Length,
indices,
0,
indices.Length / 3);
我的渲染方法会有什么问题?我一定要把我的三角形从后面排到前面吗?(不使用alpha-值)如果是,我如何订购?
可能是深度缓冲器出问题了吗?我怎么才能修好它?
关于如何解决这个问题,还有其他的想法吗?
着色代码是基本的:
float4x4 View;
float4x4 Projection;
void VS_Model(in float4 inPosition : POSITION,
in float4 inColor : COLOR,
out float4 outPosition : POSITION,
out float4 outColor : TEXCOORD0)
{
outPosition = mul(mul(inPosition, View), Projection);
outColor = inColor;
}
void PS_Model(in float4 inColor : TEXCOORD0,
out float4 outColor : COLOR)
{
outColor = inColor;
}
technique Model
{
pass
{
VertexShader = compile vs_3_0 VS_Model();
PixelShader = compile ps_3_0 PS_Model();
}
}
发布于 2011-06-07 12:18:18
你的渲染似乎没有深入的测试。这可能使三角形在更近的三角形之上进行更远的渲染,因为它们可能是在之后呈现的。
解决方案是在渲染设置中打开深度测试,并将深度比较函数设置为Less或LessEqual。如果你恰巧关掉了,记得打开深度写作。
https://gamedev.stackexchange.com/questions/13272
复制相似问题