using System; using UnityEngine; namespace UnityStandardAssets.ImageEffects { // Token: 0x02000069 RID: 105 [ExecuteInEditMode] [RequireComponent(typeof(Camera))] [AddComponentMenu("Image Effects/Camera/Depth of Field (deprecated)")] public class DepthOfFieldDeprecated : PostEffectsBase { // Token: 0x06000122 RID: 290 RVA: 0x0000CF18 File Offset: 0x0000B318 private void CreateMaterials() { this.dofBlurMaterial = base.CheckShaderAndCreateMaterial(this.dofBlurShader, this.dofBlurMaterial); this.dofMaterial = base.CheckShaderAndCreateMaterial(this.dofShader, this.dofMaterial); this.bokehSupport = this.bokehShader.isSupported; if (this.bokeh && this.bokehSupport && this.bokehShader) { this.bokehMaterial = base.CheckShaderAndCreateMaterial(this.bokehShader, this.bokehMaterial); } } // Token: 0x06000123 RID: 291 RVA: 0x0000CFA4 File Offset: 0x0000B3A4 public override bool CheckResources() { base.CheckSupport(true); this.dofBlurMaterial = base.CheckShaderAndCreateMaterial(this.dofBlurShader, this.dofBlurMaterial); this.dofMaterial = base.CheckShaderAndCreateMaterial(this.dofShader, this.dofMaterial); this.bokehSupport = this.bokehShader.isSupported; if (this.bokeh && this.bokehSupport && this.bokehShader) { this.bokehMaterial = base.CheckShaderAndCreateMaterial(this.bokehShader, this.bokehMaterial); } if (!this.isSupported) { base.ReportAutoDisable(); } return this.isSupported; } // Token: 0x06000124 RID: 292 RVA: 0x0000D04F File Offset: 0x0000B44F private void OnDisable() { Quads.Cleanup(); } // Token: 0x06000125 RID: 293 RVA: 0x0000D056 File Offset: 0x0000B456 private void OnEnable() { this._camera = base.GetComponent(); this._camera.depthTextureMode |= DepthTextureMode.Depth; } // Token: 0x06000126 RID: 294 RVA: 0x0000D078 File Offset: 0x0000B478 private float FocalDistance01(float worldDist) { return this._camera.WorldToViewportPoint((worldDist - this._camera.nearClipPlane) * this._camera.transform.forward + this._camera.transform.position).z / (this._camera.farClipPlane - this._camera.nearClipPlane); } // Token: 0x06000127 RID: 295 RVA: 0x0000D0E8 File Offset: 0x0000B4E8 private int GetDividerBasedOnQuality() { int num = 1; if (this.resolution == DepthOfFieldDeprecated.DofResolution.Medium) { num = 2; } else if (this.resolution == DepthOfFieldDeprecated.DofResolution.Low) { num = 2; } return num; } // Token: 0x06000128 RID: 296 RVA: 0x0000D11C File Offset: 0x0000B51C private int GetLowResolutionDividerBasedOnQuality(int baseDivider) { int num = baseDivider; if (this.resolution == DepthOfFieldDeprecated.DofResolution.High) { num *= 2; } if (this.resolution == DepthOfFieldDeprecated.DofResolution.Low) { num *= 2; } return num; } // Token: 0x06000129 RID: 297 RVA: 0x0000D14C File Offset: 0x0000B54C private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!this.CheckResources()) { Graphics.Blit(source, destination); return; } if (this.smoothness < 0.1f) { this.smoothness = 0.1f; } this.bokeh = this.bokeh && this.bokehSupport; float num = ((!this.bokeh) ? 1f : DepthOfFieldDeprecated.BOKEH_EXTRA_BLUR); bool flag = this.quality > DepthOfFieldDeprecated.Dof34QualitySetting.OnlyBackground; float num2 = this.focalSize / (this._camera.farClipPlane - this._camera.nearClipPlane); if (this.simpleTweakMode) { this.focalDistance01 = ((!this.objectFocus) ? this.FocalDistance01(this.focalPoint) : (this._camera.WorldToViewportPoint(this.objectFocus.position).z / this._camera.farClipPlane)); this.focalStartCurve = this.focalDistance01 * this.smoothness; this.focalEndCurve = this.focalStartCurve; flag = flag && this.focalPoint > this._camera.nearClipPlane + Mathf.Epsilon; } else { if (this.objectFocus) { Vector3 vector = this._camera.WorldToViewportPoint(this.objectFocus.position); vector.z /= this._camera.farClipPlane; this.focalDistance01 = vector.z; } else { this.focalDistance01 = this.FocalDistance01(this.focalZDistance); } this.focalStartCurve = this.focalZStartCurve; this.focalEndCurve = this.focalZEndCurve; flag = flag && this.focalPoint > this._camera.nearClipPlane + Mathf.Epsilon; } this.widthOverHeight = 1f * (float)source.width / (1f * (float)source.height); this.oneOverBaseSize = 0.001953125f; this.dofMaterial.SetFloat("_ForegroundBlurExtrude", this.foregroundBlurExtrude); this.dofMaterial.SetVector("_CurveParams", new Vector4((!this.simpleTweakMode) ? this.focalStartCurve : (1f / this.focalStartCurve), (!this.simpleTweakMode) ? this.focalEndCurve : (1f / this.focalEndCurve), num2 * 0.5f, this.focalDistance01)); this.dofMaterial.SetVector("_InvRenderTargetSize", new Vector4(1f / (1f * (float)source.width), 1f / (1f * (float)source.height), 0f, 0f)); int dividerBasedOnQuality = this.GetDividerBasedOnQuality(); int lowResolutionDividerBasedOnQuality = this.GetLowResolutionDividerBasedOnQuality(dividerBasedOnQuality); this.AllocateTextures(flag, source, dividerBasedOnQuality, lowResolutionDividerBasedOnQuality); Graphics.Blit(source, source, this.dofMaterial, 3); this.Downsample(source, this.mediumRezWorkTexture); this.Blur(this.mediumRezWorkTexture, this.mediumRezWorkTexture, DepthOfFieldDeprecated.DofBlurriness.Low, 4, this.maxBlurSpread); if (this.bokeh && (DepthOfFieldDeprecated.BokehDestination.Foreground & this.bokehDestination) != (DepthOfFieldDeprecated.BokehDestination)0) { this.dofMaterial.SetVector("_Threshhold", new Vector4(this.bokehThresholdContrast, this.bokehThresholdLuminance, 0.95f, 0f)); Graphics.Blit(this.mediumRezWorkTexture, this.bokehSource2, this.dofMaterial, 11); Graphics.Blit(this.mediumRezWorkTexture, this.lowRezWorkTexture); this.Blur(this.lowRezWorkTexture, this.lowRezWorkTexture, this.bluriness, 0, this.maxBlurSpread * num); } else { this.Downsample(this.mediumRezWorkTexture, this.lowRezWorkTexture); this.Blur(this.lowRezWorkTexture, this.lowRezWorkTexture, this.bluriness, 0, this.maxBlurSpread); } this.dofBlurMaterial.SetTexture("_TapLow", this.lowRezWorkTexture); this.dofBlurMaterial.SetTexture("_TapMedium", this.mediumRezWorkTexture); Graphics.Blit(null, this.finalDefocus, this.dofBlurMaterial, 3); if (this.bokeh && (DepthOfFieldDeprecated.BokehDestination.Foreground & this.bokehDestination) != (DepthOfFieldDeprecated.BokehDestination)0) { this.AddBokeh(this.bokehSource2, this.bokehSource, this.finalDefocus); } this.dofMaterial.SetTexture("_TapLowBackground", this.finalDefocus); this.dofMaterial.SetTexture("_TapMedium", this.mediumRezWorkTexture); Graphics.Blit(source, (!flag) ? destination : this.foregroundTexture, this.dofMaterial, (!this.visualize) ? 0 : 2); if (flag) { Graphics.Blit(this.foregroundTexture, source, this.dofMaterial, 5); this.Downsample(source, this.mediumRezWorkTexture); this.BlurFg(this.mediumRezWorkTexture, this.mediumRezWorkTexture, DepthOfFieldDeprecated.DofBlurriness.Low, 2, this.maxBlurSpread); if (this.bokeh && (DepthOfFieldDeprecated.BokehDestination.Foreground & this.bokehDestination) != (DepthOfFieldDeprecated.BokehDestination)0) { this.dofMaterial.SetVector("_Threshhold", new Vector4(this.bokehThresholdContrast * 0.5f, this.bokehThresholdLuminance, 0f, 0f)); Graphics.Blit(this.mediumRezWorkTexture, this.bokehSource2, this.dofMaterial, 11); Graphics.Blit(this.mediumRezWorkTexture, this.lowRezWorkTexture); this.BlurFg(this.lowRezWorkTexture, this.lowRezWorkTexture, this.bluriness, 1, this.maxBlurSpread * num); } else { this.BlurFg(this.mediumRezWorkTexture, this.lowRezWorkTexture, this.bluriness, 1, this.maxBlurSpread); } Graphics.Blit(this.lowRezWorkTexture, this.finalDefocus); this.dofMaterial.SetTexture("_TapLowForeground", this.finalDefocus); Graphics.Blit(source, destination, this.dofMaterial, (!this.visualize) ? 4 : 1); if (this.bokeh && (DepthOfFieldDeprecated.BokehDestination.Foreground & this.bokehDestination) != (DepthOfFieldDeprecated.BokehDestination)0) { this.AddBokeh(this.bokehSource2, this.bokehSource, destination); } } this.ReleaseTextures(); } // Token: 0x0600012A RID: 298 RVA: 0x0000D768 File Offset: 0x0000BB68 private void Blur(RenderTexture from, RenderTexture to, DepthOfFieldDeprecated.DofBlurriness iterations, int blurPass, float spread) { RenderTexture temporary = RenderTexture.GetTemporary(to.width, to.height); if (iterations > DepthOfFieldDeprecated.DofBlurriness.Low) { this.BlurHex(from, to, blurPass, spread, temporary); if (iterations > DepthOfFieldDeprecated.DofBlurriness.High) { this.dofBlurMaterial.SetVector("offsets", new Vector4(0f, spread * this.oneOverBaseSize, 0f, 0f)); Graphics.Blit(to, temporary, this.dofBlurMaterial, blurPass); this.dofBlurMaterial.SetVector("offsets", new Vector4(spread / this.widthOverHeight * this.oneOverBaseSize, 0f, 0f, 0f)); Graphics.Blit(temporary, to, this.dofBlurMaterial, blurPass); } } else { this.dofBlurMaterial.SetVector("offsets", new Vector4(0f, spread * this.oneOverBaseSize, 0f, 0f)); Graphics.Blit(from, temporary, this.dofBlurMaterial, blurPass); this.dofBlurMaterial.SetVector("offsets", new Vector4(spread / this.widthOverHeight * this.oneOverBaseSize, 0f, 0f, 0f)); Graphics.Blit(temporary, to, this.dofBlurMaterial, blurPass); } RenderTexture.ReleaseTemporary(temporary); } // Token: 0x0600012B RID: 299 RVA: 0x0000D8AC File Offset: 0x0000BCAC private void BlurFg(RenderTexture from, RenderTexture to, DepthOfFieldDeprecated.DofBlurriness iterations, int blurPass, float spread) { this.dofBlurMaterial.SetTexture("_TapHigh", from); RenderTexture temporary = RenderTexture.GetTemporary(to.width, to.height); if (iterations > DepthOfFieldDeprecated.DofBlurriness.Low) { this.BlurHex(from, to, blurPass, spread, temporary); if (iterations > DepthOfFieldDeprecated.DofBlurriness.High) { this.dofBlurMaterial.SetVector("offsets", new Vector4(0f, spread * this.oneOverBaseSize, 0f, 0f)); Graphics.Blit(to, temporary, this.dofBlurMaterial, blurPass); this.dofBlurMaterial.SetVector("offsets", new Vector4(spread / this.widthOverHeight * this.oneOverBaseSize, 0f, 0f, 0f)); Graphics.Blit(temporary, to, this.dofBlurMaterial, blurPass); } } else { this.dofBlurMaterial.SetVector("offsets", new Vector4(0f, spread * this.oneOverBaseSize, 0f, 0f)); Graphics.Blit(from, temporary, this.dofBlurMaterial, blurPass); this.dofBlurMaterial.SetVector("offsets", new Vector4(spread / this.widthOverHeight * this.oneOverBaseSize, 0f, 0f, 0f)); Graphics.Blit(temporary, to, this.dofBlurMaterial, blurPass); } RenderTexture.ReleaseTemporary(temporary); } // Token: 0x0600012C RID: 300 RVA: 0x0000DA00 File Offset: 0x0000BE00 private void BlurHex(RenderTexture from, RenderTexture to, int blurPass, float spread, RenderTexture tmp) { this.dofBlurMaterial.SetVector("offsets", new Vector4(0f, spread * this.oneOverBaseSize, 0f, 0f)); Graphics.Blit(from, tmp, this.dofBlurMaterial, blurPass); this.dofBlurMaterial.SetVector("offsets", new Vector4(spread / this.widthOverHeight * this.oneOverBaseSize, 0f, 0f, 0f)); Graphics.Blit(tmp, to, this.dofBlurMaterial, blurPass); this.dofBlurMaterial.SetVector("offsets", new Vector4(spread / this.widthOverHeight * this.oneOverBaseSize, spread * this.oneOverBaseSize, 0f, 0f)); Graphics.Blit(to, tmp, this.dofBlurMaterial, blurPass); this.dofBlurMaterial.SetVector("offsets", new Vector4(spread / this.widthOverHeight * this.oneOverBaseSize, -spread * this.oneOverBaseSize, 0f, 0f)); Graphics.Blit(tmp, to, this.dofBlurMaterial, blurPass); } // Token: 0x0600012D RID: 301 RVA: 0x0000DB1C File Offset: 0x0000BF1C private void Downsample(RenderTexture from, RenderTexture to) { this.dofMaterial.SetVector("_InvRenderTargetSize", new Vector4(1f / (1f * (float)to.width), 1f / (1f * (float)to.height), 0f, 0f)); Graphics.Blit(from, to, this.dofMaterial, DepthOfFieldDeprecated.SMOOTH_DOWNSAMPLE_PASS); } // Token: 0x0600012E RID: 302 RVA: 0x0000DB80 File Offset: 0x0000BF80 private void AddBokeh(RenderTexture bokehInfo, RenderTexture tempTex, RenderTexture finalTarget) { if (this.bokehMaterial) { Mesh[] meshes = Quads.GetMeshes(tempTex.width, tempTex.height); RenderTexture.active = tempTex; GL.Clear(false, true, new Color(0f, 0f, 0f, 0f)); GL.PushMatrix(); GL.LoadIdentity(); bokehInfo.filterMode = FilterMode.Point; float num = (float)bokehInfo.width * 1f / ((float)bokehInfo.height * 1f); float num2 = 2f / (1f * (float)bokehInfo.width); num2 += this.bokehScale * this.maxBlurSpread * DepthOfFieldDeprecated.BOKEH_EXTRA_BLUR * this.oneOverBaseSize; this.bokehMaterial.SetTexture("_Source", bokehInfo); this.bokehMaterial.SetTexture("_MainTex", this.bokehTexture); this.bokehMaterial.SetVector("_ArScale", new Vector4(num2, num2 * num, 0.5f, 0.5f * num)); this.bokehMaterial.SetFloat("_Intensity", this.bokehIntensity); this.bokehMaterial.SetPass(0); foreach (Mesh mesh in meshes) { if (mesh) { Graphics.DrawMeshNow(mesh, Matrix4x4.identity); } } GL.PopMatrix(); Graphics.Blit(tempTex, finalTarget, this.dofMaterial, 8); bokehInfo.filterMode = FilterMode.Bilinear; } } // Token: 0x0600012F RID: 303 RVA: 0x0000DCF4 File Offset: 0x0000C0F4 private void ReleaseTextures() { if (this.foregroundTexture) { RenderTexture.ReleaseTemporary(this.foregroundTexture); } if (this.finalDefocus) { RenderTexture.ReleaseTemporary(this.finalDefocus); } if (this.mediumRezWorkTexture) { RenderTexture.ReleaseTemporary(this.mediumRezWorkTexture); } if (this.lowRezWorkTexture) { RenderTexture.ReleaseTemporary(this.lowRezWorkTexture); } if (this.bokehSource) { RenderTexture.ReleaseTemporary(this.bokehSource); } if (this.bokehSource2) { RenderTexture.ReleaseTemporary(this.bokehSource2); } } // Token: 0x06000130 RID: 304 RVA: 0x0000DDA4 File Offset: 0x0000C1A4 private void AllocateTextures(bool blurForeground, RenderTexture source, int divider, int lowTexDivider) { this.foregroundTexture = null; if (blurForeground) { this.foregroundTexture = RenderTexture.GetTemporary(source.width, source.height, 0); } this.mediumRezWorkTexture = RenderTexture.GetTemporary(source.width / divider, source.height / divider, 0); this.finalDefocus = RenderTexture.GetTemporary(source.width / divider, source.height / divider, 0); this.lowRezWorkTexture = RenderTexture.GetTemporary(source.width / lowTexDivider, source.height / lowTexDivider, 0); this.bokehSource = null; this.bokehSource2 = null; if (this.bokeh) { this.bokehSource = RenderTexture.GetTemporary(source.width / (lowTexDivider * this.bokehDownsample), source.height / (lowTexDivider * this.bokehDownsample), 0, RenderTextureFormat.ARGBHalf); this.bokehSource2 = RenderTexture.GetTemporary(source.width / (lowTexDivider * this.bokehDownsample), source.height / (lowTexDivider * this.bokehDownsample), 0, RenderTextureFormat.ARGBHalf); this.bokehSource.filterMode = FilterMode.Bilinear; this.bokehSource2.filterMode = FilterMode.Bilinear; RenderTexture.active = this.bokehSource2; GL.Clear(false, true, new Color(0f, 0f, 0f, 0f)); } source.filterMode = FilterMode.Bilinear; this.finalDefocus.filterMode = FilterMode.Bilinear; this.mediumRezWorkTexture.filterMode = FilterMode.Bilinear; this.lowRezWorkTexture.filterMode = FilterMode.Bilinear; if (this.foregroundTexture) { this.foregroundTexture.filterMode = FilterMode.Bilinear; } } // Token: 0x04000276 RID: 630 private static int SMOOTH_DOWNSAMPLE_PASS = 6; // Token: 0x04000277 RID: 631 private static float BOKEH_EXTRA_BLUR = 2f; // Token: 0x04000278 RID: 632 public DepthOfFieldDeprecated.Dof34QualitySetting quality = DepthOfFieldDeprecated.Dof34QualitySetting.OnlyBackground; // Token: 0x04000279 RID: 633 public DepthOfFieldDeprecated.DofResolution resolution = DepthOfFieldDeprecated.DofResolution.Low; // Token: 0x0400027A RID: 634 public bool simpleTweakMode = true; // Token: 0x0400027B RID: 635 public float focalPoint = 1f; // Token: 0x0400027C RID: 636 public float smoothness = 0.5f; // Token: 0x0400027D RID: 637 public float focalZDistance; // Token: 0x0400027E RID: 638 public float focalZStartCurve = 1f; // Token: 0x0400027F RID: 639 public float focalZEndCurve = 1f; // Token: 0x04000280 RID: 640 private float focalStartCurve = 2f; // Token: 0x04000281 RID: 641 private float focalEndCurve = 2f; // Token: 0x04000282 RID: 642 private float focalDistance01 = 0.1f; // Token: 0x04000283 RID: 643 public Transform objectFocus; // Token: 0x04000284 RID: 644 public float focalSize; // Token: 0x04000285 RID: 645 public DepthOfFieldDeprecated.DofBlurriness bluriness = DepthOfFieldDeprecated.DofBlurriness.High; // Token: 0x04000286 RID: 646 public float maxBlurSpread = 1.75f; // Token: 0x04000287 RID: 647 public float foregroundBlurExtrude = 1.15f; // Token: 0x04000288 RID: 648 public Shader dofBlurShader; // Token: 0x04000289 RID: 649 private Material dofBlurMaterial; // Token: 0x0400028A RID: 650 public Shader dofShader; // Token: 0x0400028B RID: 651 private Material dofMaterial; // Token: 0x0400028C RID: 652 public bool visualize; // Token: 0x0400028D RID: 653 public DepthOfFieldDeprecated.BokehDestination bokehDestination = DepthOfFieldDeprecated.BokehDestination.Background; // Token: 0x0400028E RID: 654 private float widthOverHeight = 1.25f; // Token: 0x0400028F RID: 655 private float oneOverBaseSize = 0.001953125f; // Token: 0x04000290 RID: 656 public bool bokeh; // Token: 0x04000291 RID: 657 public bool bokehSupport = true; // Token: 0x04000292 RID: 658 public Shader bokehShader; // Token: 0x04000293 RID: 659 public Texture2D bokehTexture; // Token: 0x04000294 RID: 660 public float bokehScale = 2.4f; // Token: 0x04000295 RID: 661 public float bokehIntensity = 0.15f; // Token: 0x04000296 RID: 662 public float bokehThresholdContrast = 0.1f; // Token: 0x04000297 RID: 663 public float bokehThresholdLuminance = 0.55f; // Token: 0x04000298 RID: 664 public int bokehDownsample = 1; // Token: 0x04000299 RID: 665 private Material bokehMaterial; // Token: 0x0400029A RID: 666 private Camera _camera; // Token: 0x0400029B RID: 667 private RenderTexture foregroundTexture; // Token: 0x0400029C RID: 668 private RenderTexture mediumRezWorkTexture; // Token: 0x0400029D RID: 669 private RenderTexture finalDefocus; // Token: 0x0400029E RID: 670 private RenderTexture lowRezWorkTexture; // Token: 0x0400029F RID: 671 private RenderTexture bokehSource; // Token: 0x040002A0 RID: 672 private RenderTexture bokehSource2; // Token: 0x0200006A RID: 106 public enum Dof34QualitySetting { // Token: 0x040002A2 RID: 674 OnlyBackground = 1, // Token: 0x040002A3 RID: 675 BackgroundAndForeground } // Token: 0x0200006B RID: 107 public enum DofResolution { // Token: 0x040002A5 RID: 677 High = 2, // Token: 0x040002A6 RID: 678 Medium, // Token: 0x040002A7 RID: 679 Low } // Token: 0x0200006C RID: 108 public enum DofBlurriness { // Token: 0x040002A9 RID: 681 Low = 1, // Token: 0x040002AA RID: 682 High, // Token: 0x040002AB RID: 683 VeryHigh = 4 } // Token: 0x0200006D RID: 109 public enum BokehDestination { // Token: 0x040002AD RID: 685 Background = 1, // Token: 0x040002AE RID: 686 Foreground, // Token: 0x040002AF RID: 687 BackgroundAndForeground } } }