/// <summary> /// Draws this pass using the specified drawing context. /// </summary> public override void Draw(DrawingContext context, IList <IDrawableObject> drawables) { var passes = context.Passes; for (int i = 0; i < passes.Count; ++i) { if (passes[i].Enabled && passes[i] is LightPrePass) { return; } } var graphics = context.graphics; if (depthMaterial == null) { depthMaterial = new DepthMaterial(graphics); } var surfaceFormat = SurfaceFormat.Single; if (depthBuffer == null || depthBuffer.IsDisposed || depthBuffer.IsContentLost) { if (depthBuffer != null) { depthBuffer.Dispose(); } depthBuffer = new RenderTarget2D(graphics, graphics.Viewport.Width, graphics.Viewport.Height, false, surfaceFormat, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents); } if (drawingPass == null) { drawingPass = new DrawingPass(); drawingPass.MaterialUsage = MaterialUsage.Depth; } depthBuffer.Begin(); graphics.Clear(Color.White); drawingPass.Draw(context, drawables); depthBuffer.End(); context.textures[TextureUsage.DepthBuffer] = depthBuffer; }
/// <summary> /// Draws this pass using the specified drawing context. /// </summary> public override void Draw(DrawingContext context, IList <IDrawableObject> drawables) { var context3D = context as DrawingContext3D; Begin(context3D); { if (drawingPass == null) { drawingPass = new DrawingPass(); drawingPass.MaterialUsage = MaterialUsage.DepthAndNormal; } drawingPass.Draw(context, drawables); } End(context3D); context.textures[TextureUsage.DepthBuffer] = depthBuffer; context.textures[TextureUsage.NormalBuffer] = normalBuffer; if (lightQuery == null) { lightQuery = context.CreateSpatialQuery <IDeferredLight>(null); deferredLights = new FastList <IDeferredLight>(); } BeginLights(context3D); { lightQuery.FindAll(context.ViewFrustum, deferredLights); for (int i = 0; i < deferredLights.Count; ++i) { DrawLight(context3D, deferredLights[i]); } deferredLights.Clear(); } EndLights(context3D); context.textures[TextureUsage.LightBuffer] = lightBuffer; }