XNA 4.0 和(对我来说)无法解决的深度好奇渲染

标签 xna depth-buffer zbuffer

XNA 4.0 关于深度问题的大头痛:

enter image description here


我已经找到了许多类似问题的答案,但没有人适合我......

设备设置如下:

xnaPanel1.Device.BlendState = BlendState.Opaque;                
xnaPanel1.Device.DepthStencilState = DepthStencilState.Default;
xnaPanel1.Device.PresentationParameters.DepthStencilFormat = DepthFormat.Depth24Stencil8;
[...]
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 4.0f / 3.0f, 0.1f, 1000f);

作为一个残酷的问题解决者,我尝试了大多数 DepthStencilFormat 和 DepthStencilState 的可能性...没有人能像我想要的那样工作。

关于投影矩阵,我也尝试了很多nearclip和farclip值。 (立方体宽度:10f)但无法得到正确的结果。

我已经用许多不同的纹理对此进行了测试,全部都是不透明的。

我不使用BasicEffect,而是使用纹理+法线贴图的效果,这可能是问题的根源吗?

CubeEffect.fx

[...]
sampler2D colorMap = sampler_state
{
Texture = <colorMapTexture>;
    MagFilter = Linear;
    MinFilter = Anisotropic;
    MipFilter = Linear;
    MaxAnisotropy = 16;
};
sampler2D normalMap = sampler_state
{
   Texture = <normalMapTexture>;
   MagFilter = Linear;
   MinFilter = Anisotropic;
   MipFilter = Linear;
   MaxAnisotropy = 16;
};
[...]

编辑:我尝试使用 BasicEffect,问题是相同的...

所以...感谢您的帮助;)

最佳答案

好的,就是这样。

pp.DepthStencilFormat = DepthFormat.Depth24Stencil8;

必须在设备创建调用之前

所以我现在不知道为什么会这样:

Device.PresentationParameters.DepthStencilFormat = DepthFormat.Depth24Stencil8;

之前在我的主绘图函数中调用,不起作用...

结论?

PresentationParameters pp = new PresentationParameters();
pp.IsFullScreen = false;
pp.BackBufferHeight = this.renderControl.Height;
pp.BackBufferWidth = this.renderControl.Width;
pp.DeviceWindowHandle = renderControl.Handle;
pp.DepthStencilFormat = DepthFormat.Depth24Stencil8;
this.graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, pp);

现在工作正常!

关于XNA 4.0 和(对我来说)无法解决的深度好奇渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12427561/

相关文章:

OpenGL GL_DEPTH_TEST 与 glDepthFunc 和 glDepthMask 的对比?

c# - 是否可以在自定义 XNA 内容处理器中定义 Assets 名称?

c# - Windows Phone 使用方向计算位置

c++ - 如何使用 Triclops 和 FlyCapture SDK 从 PointGrey BumbleBee2 立体相机创建深度图?

java - OpenGL ES2 Alpha 测试问题

java - Z 缓冲算法未 100% 正确绘制

c# - 找到两个法向量之间的 x,y,z 旋转

.net - 在 F# 中的 Vector2 上重载相等运算符 ("=") - 不同的向量被报告为相等

c++ - OpenGL 线被其他对象隐藏

OpenGL优化天空盒渲染