C# 新华社提款单问题
我一直在尝试将去饱和和白噪声效果应用到我的XNA项目中,我成功地做到了这一点,但现在我在绘制顺序方面遇到了一些问题 在下面的代码中,注释掉的行是导致问题的原因。如果对它们进行了注释,则绘制顺序问题已得到修复,但屏幕不会去饱和。当它们未注释时,屏幕会如我所愿地去饱和,但会出现绘图顺序问题C# 新华社提款单问题,c#,xna,rendering,C#,Xna,Rendering,我一直在尝试将去饱和和白噪声效果应用到我的XNA项目中,我成功地做到了这一点,但现在我在绘制顺序方面遇到了一些问题 在下面的代码中,注释掉的行是导致问题的原因。如果对它们进行了注释,则绘制顺序问题已得到修复,但屏幕不会去饱和。当它们未注释时,屏幕会如我所愿地去饱和,但会出现绘图顺序问题 //GraphicsDevice.SetRenderTarget(scaleupTarget); GraphicsDevice.Clear(Color.SeaGreen); DrawMo
//GraphicsDevice.SetRenderTarget(scaleupTarget);
GraphicsDevice.Clear(Color.SeaGreen);
DrawModel(building_a_mdl, (Matrix.Identity * Matrix.CreateTranslation(100, -14, -100)), building_a_tex);
/*GraphicsDevice.SetRenderTarget(null);
scaleupEffect.Parameters["RandomOffset"].SetValue((float)rng.NextDouble());
GraphicsDevice.Textures[1] = noiseTexture;
spriteBatch.Begin(
SpriteSortMode.Texture,
BlendState.AlphaBlend,
SamplerState.PointClamp,
null,
null,
scaleupEffect);
spriteBatch.Draw(scaleupTarget, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero, upScaleAmount, SpriteEffects.None, 0.0f);
spriteBatch.End();*/
我怀疑,即使您试图更改
DepthStencilState
,它仍然是您问题的关键所在
调用SpriteBatch.Begin()
的过程会关闭深度缓冲区测试,因为在SpriteBatch.Draw()调用的2d渲染中不需要深度缓冲区测试。然后在下一帧,当你开始绘制3d素材时,它仍然处于关闭状态,并且你遇到了问题
因此,在绘制3d素材之前,请确保将DepthStencilState设置回默认值
GraphicsDevice.Clear(Color.SeaGreen);
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
DrawModel(building_a_mdl, (Matrix.Identity * Matrix.CreateTranslation(100, -14, -100)), building_a_tex);
请参阅此链接以获取参考:请尝试以下代码:
RenderTarget2D scaleupTarget = null;
protected override void Draw(GameTime gameTime)
{
if (scaleupTarget == null)
{
// be sure to keep the depthformat when creating the new renderTarget2d
scaleupTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.Depth24);
}
GraphicsDevice.SetRenderTarget(scaleupTarget);
GraphicsDevice.Clear(ClearOptions.Target, Color.SeaGreen, 1.0f, 0);
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
// Setup the rasterState,
// if CullMode.None; works, try with
// CullMode.CullCounterClockwiseFace
// afterwards
var rs = new RasterizerState();
rs.CullMode = CullMode.None;
rs.FillMode = FillMode.Solid;
// Set the GraphicsDevice to use the new RasterizeState
GraphicsDevice.RasterizerState = rs;
DrawModel(building_a_mdl, (Matrix.Identity * Matrix.CreateTranslation(100, -14, -100)), building_a_tex);
scaleupEffect.Parameters["RandomOffset"].SetValue((float)rng.NextDouble());
GraphicsDevice.Textures[1] = noiseTexture;
GraphicsDevice.SetRenderTarget(null);
// SpriteBatch.Begin will set the GraphicsDevice.DepthStencilState to None.
spriteBatch.Begin(
SpriteSortMode.Texture,
BlendState.AlphaBlend,
SamplerState.PointClamp,
null,
null,
scaleupEffect);
spriteBatch.Draw(scaleupTarget, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero, upScaleAmount, SpriteEffects.None, 0.0f);
spriteBatch.End();
// Set back to the original depthstate before you continue.
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
}
什么东西画得不对?在调用SpriteBatch.Begin()时,您是否尝试过更改BlendState?@davidsbro,如果您仔细观察黑白图像(很难看到),但您可以看到从建筑的另一侧通过它渲染的窗口-一组横穿模型的条形图。我已经更改了BlendState、SpriteSortMode和SamplerState,一切都没有运气。@詹姆斯蒙格在绘制模型之前是否更改了DepthStencialState和光栅化状态?@Blau我更改了DepthStencilState,但没有运气-我没有更改光栅化状态。为什么不在绘制三维模型之前尝试设置“GraphicsDevice.RenderState.DepthBufferEnable=true”这条线。我只记得我遇到了与您相同的问题,在每次抽签之前都将此设置为真。不幸的是,仍然存在问题,我截图并将其放在这里: