private void DrawDepth(float dt) { if (_sceneCameras.Count == 0) { return; } DepthStencilState depthState = new DepthStencilState(); depthState.DepthBufferEnable = true; /* Enable the depth buffer */ depthState.DepthBufferWriteEnable = true; /* When drawing to the screen, write to the depth buffer */ depthState.DepthBufferFunction = CompareFunction.Less; Platform.Instance.Device.BlendState = BlendState.Opaque; Platform.Instance.Device.DepthStencilState = depthState; Platform.Instance.Device.RasterizerState = RasterizerState.CullCounterClockwise; CameraAttachable currentCam = _sceneCameras[0]; Renderer.Instance.LoadMatrix(EMatrix.Projection, currentCam.GetPerspectiveMatrix()); Renderer.Instance.LoadMatrix(EMatrix.View, currentCam.GetViewMatrix()); foreach (var registeredNode in _registeredNodes) { Renderer.Instance.LoadMatrix(EMatrix.World, registeredNode.GetAbsoluteTransformation()); if (currentCam.GetFrustum().Contains(registeredNode.GetTransformedBoundingBox()) != ContainmentType.Disjoint && !registeredNode.Invisible && registeredNode.DrawsDepth) { Renderer.Instance.SetParameter("matWorldViewProj", Renderer.Instance.MatWorldViewProjection); foreach (var attachable in registeredNode.Attachable) { attachable.RenderDepth(dt); } } } }
private void DrawScene(float dt) { if ((StateManager.Instance.CurrentGameState as BaseMenuGameState) != null) { Quad scquad = GetScreenQuad(); Material blur = Renderer.Instance.GetBlurMaterial(); blur.SetParameter("matWorldViewProj", Matrix.Identity); blur.SetParameter("ColorMap", MenuBackgroundTexture); blur.SetParameter("blurDistance", 0.01f); scquad.Draw(blur); } if (_sceneCameras.Count == 0) { return; } Platform.Instance.Device.BlendState = new BlendState(); Platform.Instance.Device.RasterizerState = RasterizerState.CullCounterClockwise; CameraAttachable currentCam = _sceneCameras[0]; Renderer.Instance.LoadMatrix(EMatrix.Projection, currentCam.GetPerspectiveMatrix()); Renderer.Instance.LoadMatrix(EMatrix.View, currentCam.GetViewMatrix()); Renderer.Instance.SetParameter("eyePosition", currentCam.Parent.GetPosition()); Renderer.Instance.SetParameter("lightPosition", _lightPosition); int culledCount = 0; foreach (var registeredNode in _registeredNodes) { Renderer.Instance.LoadMatrix(EMatrix.World, registeredNode.GetAbsoluteTransformation()); if (currentCam.GetFrustum().Contains(registeredNode.GetTransformedBoundingBox()) != ContainmentType.Disjoint && !registeredNode.Invisible) { Renderer.Instance.SetParameter("matWorld", Renderer.Instance.MatWorld); Renderer.Instance.SetParameter("matWorldInverseTranspose", Renderer.Instance.MatWorldInverseTranspose); Renderer.Instance.SetParameter("matWorldViewProj", Renderer.Instance.MatWorldViewProjection); foreach (var attachable in registeredNode.Attachable) { attachable.Render(dt); } } else { culledCount++; } } if (ShowDebugInfo) { string toShow = culledCount.ToString() + " objects culled out of " + _registeredNodes.Count + " objects\nFPS: " + (1000f / dt).ToString(); if (_hint == null) { _hint = HintManager.Instance.SpawnHint(toShow, new Vector2(600, 20), 200f, 2000f); } else { _hint.Text = toShow; HintManager.Instance.SpawnHint(_hint); } } if (!UsePostDraw) { return; } //post render foreach (var registeredNode in _registeredNodes) { Renderer.Instance.LoadMatrix(EMatrix.World, registeredNode.GetAbsoluteTransformation()); if (currentCam.GetFrustum().Contains(registeredNode.GetTransformedBoundingBox()) != ContainmentType.Disjoint && !registeredNode.Invisible) { Renderer.Instance.SetParameter("matWorld", Renderer.Instance.MatWorld); Renderer.Instance.SetParameter("matWorldInverseTranspose", Renderer.Instance.MatWorldInverseTranspose); Renderer.Instance.SetParameter("matWorldViewProj", Renderer.Instance.MatWorldViewProjection); foreach (var attachable in registeredNode.Attachable) { attachable.PostRender(dt); } } } }