过去几天我们研究了体素引擎。如果我们绘制立方体,我们会遇到一些深度渲染问题。请参阅以下 Youtube 视频:http: //youtu.be/lNDAqO7yHBQ
我们已经沿着这个问题搜索并找到了不同的方法,但它们都没有解决我们的问题。
- GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.CornflowerBlue, 1.0f, 0);
- GraphicsDevice.BlendState = BlendState.Opaque;
- GraphicsDevice.DepthStencilState = DepthStencilState.Default;
- GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
我们的LoadContent()
方法:
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
_effect = new BasicEffect(GraphicsDevice);
_vertexBuffer = new VertexBuffer(GraphicsDevice, Node.VertexPositionColorNormal.VertexDeclaration, _chunkManager.Vertices.Length, BufferUsage.WriteOnly);
_vertexBuffer.SetData(_chunkManager.Vertices); // copies the data from our local vertices array into the memory on our graphics card
_indexBuffer = new IndexBuffer(GraphicsDevice, typeof(int), _chunkManager.Indices.Length, BufferUsage.WriteOnly);
_indexBuffer.SetData(_chunkManager.Indices);
}
我们的Draw()
方法:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
// Set object and camera info
//_effect.World = Matrix.Identity;
_effect.View = _camera.View;
_effect.Projection = _camera.Projection;
_effect.VertexColorEnabled = true;
_effect.EnableDefaultLighting();
// Begin effect and draw for each pass
foreach (var pass in _effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(_vertexBuffer);
GraphicsDevice.Indices = _indexBuffer;
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _chunkManager.Vertices.Count(), 0, _chunkManager.Indices.Count() / 3);
}
base.Draw(gameTime);
}
我们的视图和投影设置:
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)Game.Window.ClientBounds.Width / Game.Window.ClientBounds.Height, 1, 500);
View = Matrix.CreateLookAt(CameraPosition, CameraPosition + _cameraDirection, _cameraUp);
我们使用Aaron Reed 的书 ( http://shop.oreilly.com/product/0636920013709.do )中的相机 ( http://www.filedropper.com/camera_1 )。
你看到我们遗漏的东西了吗?或者你有解决这个问题的想法吗?