XNA 4.0 关于深度问题的大头痛:
我已经找到了许多类似问题的答案,但没有人适合我......
设备设置如下:
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/