/// <summary> /// Initializes a new instance of the <see cref="ShadowMap"/> class. /// </summary> public ShadowMap(GraphicsDevice graphics) { if (graphics == null) { throw new ArgumentNullException("graphics"); } this.graphics = graphics; this.depthMaterial = new DepthMaterial(graphics); this.blur = new BlurMaterial(graphics); this.fullScreenQuad = new FullScreenQuad(graphics); #if SILVERLIGHT this.SurfaceFormat = SurfaceFormat.Color; #else this.SurfaceFormat = SurfaceFormat.Single; #endif }
/// <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; }
void CameraUpdate() { //AspectRatio = (float)screenX / screenY; if (SceneCamera) { DepthMaterial.SetFloat("_AspectRatio", SceneCamera.aspect); ThisCamera.aspect = SceneCamera.aspect; // ThisCamera.nearClipPlane = .01f; // SceneCamera.nearClipPlane = .01f; //ThisCamera.farClipPlane = SceneCamera.farClipPlane; ThisCamera.nearClipPlane = SceneCamera.nearClipPlane; #if UNITY_5_6_OR_NEWER ThisCamera.allowHDR = SceneCamera.allowHDR; #else ThisCamera.hdr = SceneCamera.hdr; #endif ThisCamera.fieldOfView = SceneCamera.fieldOfView; } }