2012-02-28 95 views
0

我试图绘制场景的深度图。 现在,我制作了一个如下所示的HLSL文件:http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Shadow_map.php 而且一切都很顺利。然而!我想找出每个像素的确切值,所以我没有绘制正常的渲染目标,而是创建了一个新的渲染目标,它是一个Texture2D,如:http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Render_to_texture.php 然后我使用spritebatch绘制它。XNA深度图重叠区域颜色

然后!当我显示图像中,第一,也就是,一个直接绘制到屏幕给出了这样的输出:

Correct Depth Image

并绘制到纹理然后于使用子画面屏幕上的一个给这样的: Sprite drawn Image

请注意,在第二次捕获时,身体右臂明显位于身体后方,如同身体不存在于重叠区域那样绘制。

我认为,它是一个排序问题,因为前面的顶点首先被绘制到纹理,然后更远的覆盖更接近的结果,从而导致观察图像。

我将不胜感激任何输入。

回答

2

SpriteBatchmodifies the graphics device state当你使用它。从链接的文章,这里是它集:

GraphicsDevice.BlendState = BlendState.AlphaBlend; 
GraphicsDevice.DepthStencilState = DepthStencilState.None; 
GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; 
GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; 

你可能要设置的深度模版状态恢复到默认值(深度读取和写入)。

GraphicsDevice.DepthStencilState = DepthStencilState.Default; 

您可能还必须设置一些其他状态,具体取决于您的渲染需要。

+1

+1:完全同意。在这种情况下,我通常在调用'SpriteBatch.Begin()'调用之前放置一个断点,然后检查'DepthStencilState','BlendState'和'RasterizerState',然后在'SpriteBatch.End()'调用之后全部重置它们。 – 2012-02-29 10:42:34

+0

工程就像一个魅力! – 2012-02-29 18:39:47