public void Draw(Camera camera, Vector3 lightDirection) { var graphicsDevice = _effect.GraphicsDevice; //graphicsDevice.SetDepthStencilState(_noDepthState); var viewProjection = camera.ViewMatrix * camera.ProjectionMatrix; var inverseViewProjection = viewProjection; inverseViewProjection.Invert(); _effect.Parameters["InverseViewProjection"].SetValue(inverseViewProjection); _effect.Parameters["LightDirection"].SetValue(-lightDirection); _effect.CurrentTechnique.Passes[0].Apply(); ScreenTriangleRenderer.Instance.DrawScreenAlignedTriangle(graphicsDevice); }
protected override void Initialize() { Window.Title = "Voxel Seeds"; base.Initialize(); IsMouseVisible = true; var windowControl = Window.NativeWindow as System.Windows.Forms.Control; System.Diagnostics.Debug.Assert(windowControl != null); _camera = new Camera((float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, (float)Math.PI * 0.35f, 1.0f, 1000.0f, windowControl); var mainThreadDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher; windowControl.MouseClick += (object sender, System.Windows.Forms.MouseEventArgs e) => { if (e.Button == System.Windows.Forms.MouseButtons.Left) mainThreadDispatcher.BeginInvoke(new Action(() => { if (_pickPosAvailable && _seedbar.GetSelected() >= 0 && _currentLevel.GetMap().IsInside(_pickedPos.X, _pickedPos.Y, _pickedPos.Z) && TypeInformation.GetPrice(_seedbar.GetSeedInfo()._type) <= _currentLevel.Resources) { _currentLevel.Resources -= TypeInformation.GetPrice(_seedbar.GetSeedInfo()._type); _currentLevel.InsertSeed(_pickedPos.X, _pickedPos.Y, _pickedPos.Z, _seedbar.GetSeedInfo()._type); } })); }; }
public void DrawGhost(Camera camera, GraphicsDevice graphicsDevice, VoxelType voxel, Int32 levelPositionCode) { _voxelEffect.Parameters["ViewProjection"].SetValue(camera.ViewMatrix * camera.ProjectionMatrix); _voxelEffect.Parameters["VoxelTexture"].SetResource(_voxelTypeRenderingData[GetRenderingDataIndex(voxel)].Texture); _voxelEffect.Parameters["Transparency"].SetValue(0.7f); _voxelEffect.Parameters["Ambient"].SetValue(2.0f); _voxelEffect.Parameters["ScalingFactor"].SetValue(TypeInformation.GetScalingFactor(voxel) * 0.5f); _singleInstanceBuffer.SetDynamicData(graphicsDevice, (ptr) => System.Runtime.InteropServices.Marshal.Copy( new Int32[] { levelPositionCode }, 0, ptr, 1)); graphicsDevice.SetRasterizerState(_noneCullingState); graphicsDevice.SetDepthStencilState(_depthStencilStateState); graphicsDevice.SetBlendState(_blendStateTransparent); // Setup the vertices graphicsDevice.SetVertexBuffer(0, _cubeVertexBuffer); graphicsDevice.SetVertexBuffer(1, _singleInstanceBuffer); graphicsDevice.SetVertexInputLayout(_vertexInputLayout); _voxelEffect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.DrawInstanced(PrimitiveType.TriangleList, _cubeVertexBuffer.ElementCount, 1, 0, 0); }
/// <summary> /// draw what else /// </summary> public void Draw(Camera camera, GraphicsDevice graphicsDevice) { _voxelEffect.Parameters["ViewProjection"].SetValue(camera.ViewMatrix * camera.ProjectionMatrix); _voxelEffect.Parameters["Ambient"].SetValue(0.3f); _voxelEffect.Parameters["CameraPosition"].SetValue(camera.Position); graphicsDevice.SetRasterizerState(_backfaceCullingState); graphicsDevice.SetDepthStencilState(_depthStencilStateState); graphicsDevice.SetBlendState(_blendStateOpaque); // Setup the vertices graphicsDevice.SetVertexBuffer(_cubeVertexBuffer, 0); graphicsDevice.SetVertexInputLayout(_vertexInputLayout); // render all instances for (int i = 0; i < _voxelTypeRenderingData.Length; ++i) { _voxelEffect.Parameters["ScalingFactor"].SetValue(TypeInformation.GetScalingFactor(_voxelTypeRenderingData[i].Voxel) * 0.5f); _voxelEffect.Parameters["VoxelTexture"].SetResource(_voxelTypeRenderingData[i].Texture); _voxelEffect.Parameters["SpecularModifier"].SetValue(TypeInformation.IsParasite( _voxelTypeRenderingData[i].Voxel )); _voxelEffect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.SetVertexBuffer(1, _voxelTypeRenderingData[i].InstanceBuffer); graphicsDevice.DrawInstanced(PrimitiveType.TriangleList, _cubeVertexBuffer.ElementCount, _voxelTypeRenderingData[i].InstanceDataRAM.Count, 0, 0); } graphicsDevice.SetVertexBuffer<int>(1, (Buffer<int>)null); }