using System; using UnityEngine; namespace UnityStandardAssets.ImageEffects { // Token: 0x02000066 RID: 102 [ExecuteInEditMode] [RequireComponent(typeof(Camera))] [AddComponentMenu("Image Effects/Camera/Depth of Field (Lens Blur, Scatter, DX11)")] public class DepthOfField : PostEffectsBase { // Token: 0x06000119 RID: 281 RVA: 0x0000BFD8 File Offset: 0x0000A3D8 public override bool CheckResources() { base.CheckSupport(true); this.dofHdrMaterial = base.CheckShaderAndCreateMaterial(this.dofHdrShader, this.dofHdrMaterial); if (this.supportDX11 && this.blurType == DepthOfField.BlurType.DX11) { this.dx11bokehMaterial = base.CheckShaderAndCreateMaterial(this.dx11BokehShader, this.dx11bokehMaterial); this.CreateComputeResources(); } if (!this.isSupported) { base.ReportAutoDisable(); } return this.isSupported; } // Token: 0x0600011A RID: 282 RVA: 0x0000C051 File Offset: 0x0000A451 private void OnEnable() { this.cachedCamera = base.GetComponent(); this.cachedCamera.depthTextureMode |= DepthTextureMode.Depth; } // Token: 0x0600011B RID: 283 RVA: 0x0000C074 File Offset: 0x0000A474 private void OnDisable() { this.ReleaseComputeResources(); if (this.dofHdrMaterial) { global::UnityEngine.Object.DestroyImmediate(this.dofHdrMaterial); } this.dofHdrMaterial = null; if (this.dx11bokehMaterial) { global::UnityEngine.Object.DestroyImmediate(this.dx11bokehMaterial); } this.dx11bokehMaterial = null; } // Token: 0x0600011C RID: 284 RVA: 0x0000C0CB File Offset: 0x0000A4CB private void ReleaseComputeResources() { if (this.cbDrawArgs != null) { this.cbDrawArgs.Release(); } this.cbDrawArgs = null; if (this.cbPoints != null) { this.cbPoints.Release(); } this.cbPoints = null; } // Token: 0x0600011D RID: 285 RVA: 0x0000C108 File Offset: 0x0000A508 private void CreateComputeResources() { if (this.cbDrawArgs == null) { this.cbDrawArgs = new ComputeBuffer(1, 16, ComputeBufferType.DrawIndirect); int[] array = new int[] { 0, 1, 0, 0 }; this.cbDrawArgs.SetData(array); } if (this.cbPoints == null) { this.cbPoints = new ComputeBuffer(90000, 28, ComputeBufferType.Append); } } // Token: 0x0600011E RID: 286 RVA: 0x0000C174 File Offset: 0x0000A574 private float FocalDistance01(float worldDist) { return this.cachedCamera.WorldToViewportPoint((worldDist - this.cachedCamera.nearClipPlane) * this.cachedCamera.transform.forward + this.cachedCamera.transform.position).z / (this.cachedCamera.farClipPlane - this.cachedCamera.nearClipPlane); } // Token: 0x0600011F RID: 287 RVA: 0x0000C1E4 File Offset: 0x0000A5E4 private void WriteCoc(RenderTexture fromTo, bool fgDilate) { this.dofHdrMaterial.SetTexture("_FgOverlap", null); if (this.nearBlur && fgDilate) { int num = fromTo.width / 2; int num2 = fromTo.height / 2; RenderTexture renderTexture = RenderTexture.GetTemporary(num, num2, 0, fromTo.format); Graphics.Blit(fromTo, renderTexture, this.dofHdrMaterial, 4); float num3 = this.internalBlurWidth * this.foregroundOverlap; this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, num3, 0f, num3)); RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, fromTo.format); Graphics.Blit(renderTexture, temporary, this.dofHdrMaterial, 2); RenderTexture.ReleaseTemporary(renderTexture); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(num3, 0f, 0f, num3)); renderTexture = RenderTexture.GetTemporary(num, num2, 0, fromTo.format); Graphics.Blit(temporary, renderTexture, this.dofHdrMaterial, 2); RenderTexture.ReleaseTemporary(temporary); this.dofHdrMaterial.SetTexture("_FgOverlap", renderTexture); fromTo.MarkRestoreExpected(); Graphics.Blit(fromTo, fromTo, this.dofHdrMaterial, 13); RenderTexture.ReleaseTemporary(renderTexture); } else { fromTo.MarkRestoreExpected(); Graphics.Blit(fromTo, fromTo, this.dofHdrMaterial, 0); } } // Token: 0x06000120 RID: 288 RVA: 0x0000C324 File Offset: 0x0000A724 private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!this.CheckResources()) { Graphics.Blit(source, destination); return; } if (this.aperture < 0f) { this.aperture = 0f; } if (this.maxBlurSize < 0.1f) { this.maxBlurSize = 0.1f; } this.focalSize = Mathf.Clamp(this.focalSize, 0f, 2f); this.internalBlurWidth = Mathf.Max(this.maxBlurSize, 0f); this.focalDistance01 = ((!this.focalTransform) ? this.FocalDistance01(this.focalLength) : (this.cachedCamera.WorldToViewportPoint(this.focalTransform.position).z / this.cachedCamera.farClipPlane)); this.dofHdrMaterial.SetVector("_CurveParams", new Vector4(1f, this.focalSize, 1f / (1f - this.aperture) - 1f, this.focalDistance01)); RenderTexture renderTexture = null; RenderTexture renderTexture2 = null; float num = this.internalBlurWidth * this.foregroundOverlap; if (this.visualizeFocus) { this.WriteCoc(source, true); Graphics.Blit(source, destination, this.dofHdrMaterial, 16); } else if (this.blurType == DepthOfField.BlurType.DX11 && this.dx11bokehMaterial) { if (this.highResolution) { this.internalBlurWidth = ((this.internalBlurWidth >= 0.1f) ? this.internalBlurWidth : 0.1f); num = this.internalBlurWidth * this.foregroundOverlap; renderTexture = RenderTexture.GetTemporary(source.width, source.height, 0, source.format); RenderTexture temporary = RenderTexture.GetTemporary(source.width, source.height, 0, source.format); this.WriteCoc(source, false); RenderTexture renderTexture3 = RenderTexture.GetTemporary(source.width >> 1, source.height >> 1, 0, source.format); RenderTexture renderTexture4 = RenderTexture.GetTemporary(source.width >> 1, source.height >> 1, 0, source.format); Graphics.Blit(source, renderTexture3, this.dofHdrMaterial, 15); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, 1.5f, 0f, 1.5f)); Graphics.Blit(renderTexture3, renderTexture4, this.dofHdrMaterial, 19); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(1.5f, 0f, 0f, 1.5f)); Graphics.Blit(renderTexture4, renderTexture3, this.dofHdrMaterial, 19); if (this.nearBlur) { Graphics.Blit(source, renderTexture4, this.dofHdrMaterial, 4); } this.dx11bokehMaterial.SetTexture("_BlurredColor", renderTexture3); this.dx11bokehMaterial.SetFloat("_SpawnHeuristic", this.dx11SpawnHeuristic); this.dx11bokehMaterial.SetVector("_BokehParams", new Vector4(this.dx11BokehScale, this.dx11BokehIntensity, Mathf.Clamp(this.dx11BokehThreshold, 0.005f, 4f), this.internalBlurWidth)); this.dx11bokehMaterial.SetTexture("_FgCocMask", (!this.nearBlur) ? null : renderTexture4); Graphics.SetRandomWriteTarget(1, this.cbPoints); Graphics.Blit(source, renderTexture, this.dx11bokehMaterial, 0); Graphics.ClearRandomWriteTargets(); if (this.nearBlur) { this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, num, 0f, num)); Graphics.Blit(renderTexture4, renderTexture3, this.dofHdrMaterial, 2); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(num, 0f, 0f, num)); Graphics.Blit(renderTexture3, renderTexture4, this.dofHdrMaterial, 2); Graphics.Blit(renderTexture4, renderTexture, this.dofHdrMaterial, 3); } Graphics.Blit(renderTexture, temporary, this.dofHdrMaterial, 20); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(this.internalBlurWidth, 0f, 0f, this.internalBlurWidth)); Graphics.Blit(renderTexture, source, this.dofHdrMaterial, 5); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, this.internalBlurWidth, 0f, this.internalBlurWidth)); Graphics.Blit(source, temporary, this.dofHdrMaterial, 21); Graphics.SetRenderTarget(temporary); ComputeBuffer.CopyCount(this.cbPoints, this.cbDrawArgs, 0); this.dx11bokehMaterial.SetBuffer("pointBuffer", this.cbPoints); this.dx11bokehMaterial.SetTexture("_MainTex", this.dx11BokehTexture); this.dx11bokehMaterial.SetVector("_Screen", new Vector3(1f / (1f * (float)source.width), 1f / (1f * (float)source.height), this.internalBlurWidth)); this.dx11bokehMaterial.SetPass(2); Graphics.DrawProceduralIndirect(MeshTopology.Points, this.cbDrawArgs, 0); Graphics.Blit(temporary, destination); RenderTexture.ReleaseTemporary(temporary); RenderTexture.ReleaseTemporary(renderTexture3); RenderTexture.ReleaseTemporary(renderTexture4); } else { renderTexture = RenderTexture.GetTemporary(source.width >> 1, source.height >> 1, 0, source.format); renderTexture2 = RenderTexture.GetTemporary(source.width >> 1, source.height >> 1, 0, source.format); num = this.internalBlurWidth * this.foregroundOverlap; this.WriteCoc(source, false); source.filterMode = FilterMode.Bilinear; Graphics.Blit(source, renderTexture, this.dofHdrMaterial, 6); RenderTexture renderTexture3 = RenderTexture.GetTemporary(renderTexture.width >> 1, renderTexture.height >> 1, 0, renderTexture.format); RenderTexture renderTexture4 = RenderTexture.GetTemporary(renderTexture.width >> 1, renderTexture.height >> 1, 0, renderTexture.format); Graphics.Blit(renderTexture, renderTexture3, this.dofHdrMaterial, 15); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, 1.5f, 0f, 1.5f)); Graphics.Blit(renderTexture3, renderTexture4, this.dofHdrMaterial, 19); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(1.5f, 0f, 0f, 1.5f)); Graphics.Blit(renderTexture4, renderTexture3, this.dofHdrMaterial, 19); RenderTexture renderTexture5 = null; if (this.nearBlur) { renderTexture5 = RenderTexture.GetTemporary(source.width >> 1, source.height >> 1, 0, source.format); Graphics.Blit(source, renderTexture5, this.dofHdrMaterial, 4); } this.dx11bokehMaterial.SetTexture("_BlurredColor", renderTexture3); this.dx11bokehMaterial.SetFloat("_SpawnHeuristic", this.dx11SpawnHeuristic); this.dx11bokehMaterial.SetVector("_BokehParams", new Vector4(this.dx11BokehScale, this.dx11BokehIntensity, Mathf.Clamp(this.dx11BokehThreshold, 0.005f, 4f), this.internalBlurWidth)); this.dx11bokehMaterial.SetTexture("_FgCocMask", renderTexture5); Graphics.SetRandomWriteTarget(1, this.cbPoints); Graphics.Blit(renderTexture, renderTexture2, this.dx11bokehMaterial, 0); Graphics.ClearRandomWriteTargets(); RenderTexture.ReleaseTemporary(renderTexture3); RenderTexture.ReleaseTemporary(renderTexture4); if (this.nearBlur) { this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, num, 0f, num)); Graphics.Blit(renderTexture5, renderTexture, this.dofHdrMaterial, 2); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(num, 0f, 0f, num)); Graphics.Blit(renderTexture, renderTexture5, this.dofHdrMaterial, 2); Graphics.Blit(renderTexture5, renderTexture2, this.dofHdrMaterial, 3); } this.dofHdrMaterial.SetVector("_Offsets", new Vector4(this.internalBlurWidth, 0f, 0f, this.internalBlurWidth)); Graphics.Blit(renderTexture2, renderTexture, this.dofHdrMaterial, 5); this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, this.internalBlurWidth, 0f, this.internalBlurWidth)); Graphics.Blit(renderTexture, renderTexture2, this.dofHdrMaterial, 5); Graphics.SetRenderTarget(renderTexture2); ComputeBuffer.CopyCount(this.cbPoints, this.cbDrawArgs, 0); this.dx11bokehMaterial.SetBuffer("pointBuffer", this.cbPoints); this.dx11bokehMaterial.SetTexture("_MainTex", this.dx11BokehTexture); this.dx11bokehMaterial.SetVector("_Screen", new Vector3(1f / (1f * (float)renderTexture2.width), 1f / (1f * (float)renderTexture2.height), this.internalBlurWidth)); this.dx11bokehMaterial.SetPass(1); Graphics.DrawProceduralIndirect(MeshTopology.Points, this.cbDrawArgs, 0); this.dofHdrMaterial.SetTexture("_LowRez", renderTexture2); this.dofHdrMaterial.SetTexture("_FgOverlap", renderTexture5); this.dofHdrMaterial.SetVector("_Offsets", 1f * (float)source.width / (1f * (float)renderTexture2.width) * this.internalBlurWidth * Vector4.one); Graphics.Blit(source, destination, this.dofHdrMaterial, 9); if (renderTexture5) { RenderTexture.ReleaseTemporary(renderTexture5); } } } else { source.filterMode = FilterMode.Bilinear; if (this.highResolution) { this.internalBlurWidth *= 2f; } this.WriteCoc(source, true); renderTexture = RenderTexture.GetTemporary(source.width >> 1, source.height >> 1, 0, source.format); renderTexture2 = RenderTexture.GetTemporary(source.width >> 1, source.height >> 1, 0, source.format); int num2 = ((this.blurSampleCount != DepthOfField.BlurSampleCount.High && this.blurSampleCount != DepthOfField.BlurSampleCount.Medium) ? 11 : 17); if (this.highResolution) { this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, this.internalBlurWidth, 0.025f, this.internalBlurWidth)); Graphics.Blit(source, destination, this.dofHdrMaterial, num2); } else { this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, this.internalBlurWidth, 0.1f, this.internalBlurWidth)); Graphics.Blit(source, renderTexture, this.dofHdrMaterial, 6); Graphics.Blit(renderTexture, renderTexture2, this.dofHdrMaterial, num2); this.dofHdrMaterial.SetTexture("_LowRez", renderTexture2); this.dofHdrMaterial.SetTexture("_FgOverlap", null); this.dofHdrMaterial.SetVector("_Offsets", Vector4.one * (1f * (float)source.width / (1f * (float)renderTexture2.width)) * this.internalBlurWidth); Graphics.Blit(source, destination, this.dofHdrMaterial, (this.blurSampleCount != DepthOfField.BlurSampleCount.High) ? 12 : 18); } } if (renderTexture) { RenderTexture.ReleaseTemporary(renderTexture); } if (renderTexture2) { RenderTexture.ReleaseTemporary(renderTexture2); } } // Token: 0x04000256 RID: 598 public bool visualizeFocus; // Token: 0x04000257 RID: 599 public float focalLength = 10f; // Token: 0x04000258 RID: 600 public float focalSize = 0.05f; // Token: 0x04000259 RID: 601 public float aperture = 0.5f; // Token: 0x0400025A RID: 602 public Transform focalTransform; // Token: 0x0400025B RID: 603 public float maxBlurSize = 2f; // Token: 0x0400025C RID: 604 public bool highResolution; // Token: 0x0400025D RID: 605 public DepthOfField.BlurType blurType; // Token: 0x0400025E RID: 606 public DepthOfField.BlurSampleCount blurSampleCount = DepthOfField.BlurSampleCount.High; // Token: 0x0400025F RID: 607 public bool nearBlur; // Token: 0x04000260 RID: 608 public float foregroundOverlap = 1f; // Token: 0x04000261 RID: 609 public Shader dofHdrShader; // Token: 0x04000262 RID: 610 private Material dofHdrMaterial; // Token: 0x04000263 RID: 611 public Shader dx11BokehShader; // Token: 0x04000264 RID: 612 private Material dx11bokehMaterial; // Token: 0x04000265 RID: 613 public float dx11BokehThreshold = 0.5f; // Token: 0x04000266 RID: 614 public float dx11SpawnHeuristic = 0.0875f; // Token: 0x04000267 RID: 615 public Texture2D dx11BokehTexture; // Token: 0x04000268 RID: 616 public float dx11BokehScale = 1.2f; // Token: 0x04000269 RID: 617 public float dx11BokehIntensity = 2.5f; // Token: 0x0400026A RID: 618 private float focalDistance01 = 10f; // Token: 0x0400026B RID: 619 private ComputeBuffer cbDrawArgs; // Token: 0x0400026C RID: 620 private ComputeBuffer cbPoints; // Token: 0x0400026D RID: 621 private float internalBlurWidth = 1f; // Token: 0x0400026E RID: 622 private Camera cachedCamera; // Token: 0x02000067 RID: 103 public enum BlurType { // Token: 0x04000270 RID: 624 DiscBlur, // Token: 0x04000271 RID: 625 DX11 } // Token: 0x02000068 RID: 104 public enum BlurSampleCount { // Token: 0x04000273 RID: 627 Low, // Token: 0x04000274 RID: 628 Medium, // Token: 0x04000275 RID: 629 High } } }