某些东西不能正常工作。如果您对截图进行了解,您将看到结果很奇怪。展馆的地板是正确的,但柱子有点透明,屋顶是完全奇怪的。我使用Assimp.NET从.obj文件导入他的网格。在其他引擎中它看起来正确。另一件事是:如果我将CullMode设置为Back - 它会剔除正面?!我认为它可能是3件事:1,网格导入错误,或者z缓冲区不起作用,或者我可能需要多个世界矩阵(我只使用一个)。
有没有人知道这可能是什么?!
截图:
以下是一些代码:
深度缓存/ DepthStencilView
var depthBufferDescription = new Texture2DDescription
{
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = BackBuffer.Description.Width,
Height = BackBuffer.Description.Height,
SampleDescription = swapChainDescription.SampleDescription,
BindFlags = BindFlags.DepthStencil
};
var depthStencilViewDescription = new DepthStencilViewDescription
{
Dimension = SwapChain.Description.SampleDescription.Count > 1 || SwapChain.Description.SampleDescription.Quality > 0 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D
};
var depthStencilStateDescription = new DepthStencilStateDescription
{
IsDepthEnabled = true,
DepthComparison = Comparison.Always,
DepthWriteMask = DepthWriteMask.All,
IsStencilEnabled = false,
StencilReadMask = 0xff,
StencilWriteMask = 0xff,
FrontFace = new DepthStencilOperationDescription
{
Comparison = Comparison.Always,
PassOperation = StencilOperation.Keep,
FailOperation = StencilOperation.Keep,
DepthFailOperation = StencilOperation.Increment
},
BackFace = new DepthStencilOperationDescription
{
Comparison = Comparison.Always,
PassOperation = StencilOperation.Keep,
FailOperation = StencilOperation.Keep,
DepthFailOperation = StencilOperation.Decrement
}
};
加载网格文件:
public static Mesh Stadafax_ModelFromFile(string path)
{
if (_importContext.IsImportFormatSupported(Path.GetExtension(path)))
{
var imported = _importContext.ImportFile(path, PostProcessSteps.Triangulate | PostProcessSteps.FindDegenerates | PostProcessSteps.FindInstances | PostProcessSteps.FindInvalidData | PostProcessSteps.JoinIdenticalVertices | PostProcessSteps.OptimizeGraph | PostProcessSteps.ValidateDataStructure | PostProcessSteps.FlipUVs);
Mesh engineMesh = new Mesh();
Assimp.Mesh assimpMesh = imported.Meshes[0];
foreach(Face f in assimpMesh.Faces)
{
engineMesh.Structure.Faces.Add(new Rendering.Triangle((uint)f.Indices[0], (uint)f.Indices[1], (uint)f.Indices[2]));
}
List<Vector3D>[] uv = assimpMesh.TextureCoordinateChannels;
for(int i = 0; i < assimpMesh.Vertices.Count; i++)
{
engineMesh.Structure.Vertices.Add(new Vertex(new Vector4(assimpMesh.Vertices[i].X, assimpMesh.Vertices[i].Y, assimpMesh.Vertices[i].Z, 1), RenderColorRGBA.White, new Vector2(uv[0][i].X, uv[0][i].Y)));
}
return engineMesh;
}
else
NoëlEngine.Common.Output.Log("Model format not supported!", "Importeur", true); return null;
}
}
如果有人只知道这可能是什么,请写一个评论。
答案 0 :(得分:2)
你看到的是实际上落后于其他人的多边形仍在其上方。
通过DepthStencilStateDescription
配置深度缓冲区时,将DepthComparison
设置为Comparison.Always
。这不是您想要的,您想使用Comparison.Less
。
背后的逻辑是什么?检查像素的每个深度值是否可以实际写入深度缓冲区。此检查使用您指定的Comparison
进行配置。
Comparison.Always
始终允许写入新值。因此,无论多边形实际上是在其他人之上还是在他们之上或其他任何方面,它都将始终覆盖(&#34;在上面绘制&#34;)已经存在的东西 - 即使它&# 39;在空间上支持它。Comparison.Less
仅在值 less 时才写入值,而不是深度缓冲区中的当前值。不要忘记较小的深度值更接近观众。因此,更接近现有多边形的多边形将覆盖旧的多边形(&#34;在上面绘制&#34;)。但如果它落后于它,它就不会被吸引。这正是你想要的。你也可以猜出其他Comparison
枚举现在做了什么,然后玩弄它们:)