using System; using UnityEngine; namespace UnityStandardAssets.ImageEffects { // Token: 0x02000091 RID: 145 [ImageEffectAllowedInSceneView] [ExecuteInEditMode] [RequireComponent(typeof(Camera))] [AddComponentMenu("Image Effects/Color Adjustments/Tonemapping")] public class Tonemapping : PostEffectsBase { // Token: 0x06000199 RID: 409 RVA: 0x00012404 File Offset: 0x00010804 public override bool CheckResources() { base.CheckSupport(false, true); this.tonemapMaterial = base.CheckShaderAndCreateMaterial(this.tonemapper, this.tonemapMaterial); if (!this.curveTex && this.type == Tonemapping.TonemapperType.UserCurve) { this.curveTex = new Texture2D(256, 1, TextureFormat.ARGB32, false, true); this.curveTex.filterMode = FilterMode.Bilinear; this.curveTex.wrapMode = TextureWrapMode.Clamp; this.curveTex.hideFlags = HideFlags.DontSave; } if (!this.isSupported) { base.ReportAutoDisable(); } return this.isSupported; } // Token: 0x0600019A RID: 410 RVA: 0x000124A0 File Offset: 0x000108A0 public float UpdateCurve() { float num = 1f; if (this.remapCurve.keys.Length < 1) { this.remapCurve = new AnimationCurve(new Keyframe[] { new Keyframe(0f, 0f), new Keyframe(2f, 1f) }); } if (this.remapCurve != null) { if (this.remapCurve.length > 0) { num = this.remapCurve[this.remapCurve.length - 1].time; } for (float num2 = 0f; num2 <= 1f; num2 += 0.003921569f) { float num3 = this.remapCurve.Evaluate(num2 * 1f * num); this.curveTex.SetPixel((int)Mathf.Floor(num2 * 255f), 0, new Color(num3, num3, num3)); } this.curveTex.Apply(); } return 1f / num; } // Token: 0x0600019B RID: 411 RVA: 0x000125B0 File Offset: 0x000109B0 private void OnDisable() { if (this.rt) { global::UnityEngine.Object.DestroyImmediate(this.rt); this.rt = null; } if (this.tonemapMaterial) { global::UnityEngine.Object.DestroyImmediate(this.tonemapMaterial); this.tonemapMaterial = null; } if (this.curveTex) { global::UnityEngine.Object.DestroyImmediate(this.curveTex); this.curveTex = null; } } // Token: 0x0600019C RID: 412 RVA: 0x00012624 File Offset: 0x00010A24 private bool CreateInternalRenderTexture() { if (this.rt) { return false; } this.rtFormat = ((!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGHalf)) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.RGHalf); this.rt = new RenderTexture(1, 1, 0, this.rtFormat); this.rt.hideFlags = HideFlags.DontSave; return true; } // Token: 0x0600019D RID: 413 RVA: 0x00012680 File Offset: 0x00010A80 [ImageEffectTransformsToLDR] private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!this.CheckResources()) { Graphics.Blit(source, destination); return; } this.exposureAdjustment = ((this.exposureAdjustment >= 0.001f) ? this.exposureAdjustment : 0.001f); if (this.type == Tonemapping.TonemapperType.UserCurve) { float num = this.UpdateCurve(); this.tonemapMaterial.SetFloat("_RangeScale", num); this.tonemapMaterial.SetTexture("_Curve", this.curveTex); Graphics.Blit(source, destination, this.tonemapMaterial, 4); return; } if (this.type == Tonemapping.TonemapperType.SimpleReinhard) { this.tonemapMaterial.SetFloat("_ExposureAdjustment", this.exposureAdjustment); Graphics.Blit(source, destination, this.tonemapMaterial, 6); return; } if (this.type == Tonemapping.TonemapperType.Hable) { this.tonemapMaterial.SetFloat("_ExposureAdjustment", this.exposureAdjustment); Graphics.Blit(source, destination, this.tonemapMaterial, 5); return; } if (this.type == Tonemapping.TonemapperType.Photographic) { this.tonemapMaterial.SetFloat("_ExposureAdjustment", this.exposureAdjustment); Graphics.Blit(source, destination, this.tonemapMaterial, 8); return; } if (this.type == Tonemapping.TonemapperType.OptimizedHejiDawson) { this.tonemapMaterial.SetFloat("_ExposureAdjustment", 0.5f * this.exposureAdjustment); Graphics.Blit(source, destination, this.tonemapMaterial, 7); return; } bool flag = this.CreateInternalRenderTexture(); RenderTexture temporary = RenderTexture.GetTemporary((int)this.adaptiveTextureSize, (int)this.adaptiveTextureSize, 0, this.rtFormat); Graphics.Blit(source, temporary); int num2 = (int)Mathf.Log((float)temporary.width * 1f, 2f); int num3 = 2; RenderTexture[] array = new RenderTexture[num2]; for (int i = 0; i < num2; i++) { array[i] = RenderTexture.GetTemporary(temporary.width / num3, temporary.width / num3, 0, this.rtFormat); num3 *= 2; } RenderTexture renderTexture = array[num2 - 1]; Graphics.Blit(temporary, array[0], this.tonemapMaterial, 1); if (this.type == Tonemapping.TonemapperType.AdaptiveReinhardAutoWhite) { for (int j = 0; j < num2 - 1; j++) { Graphics.Blit(array[j], array[j + 1], this.tonemapMaterial, 9); renderTexture = array[j + 1]; } } else if (this.type == Tonemapping.TonemapperType.AdaptiveReinhard) { for (int k = 0; k < num2 - 1; k++) { Graphics.Blit(array[k], array[k + 1]); renderTexture = array[k + 1]; } } this.adaptionSpeed = ((this.adaptionSpeed >= 0.001f) ? this.adaptionSpeed : 0.001f); this.tonemapMaterial.SetFloat("_AdaptionSpeed", this.adaptionSpeed); this.rt.MarkRestoreExpected(); Graphics.Blit(renderTexture, this.rt, this.tonemapMaterial, (!flag) ? 2 : 3); this.middleGrey = ((this.middleGrey >= 0.001f) ? this.middleGrey : 0.001f); this.tonemapMaterial.SetVector("_HdrParams", new Vector4(this.middleGrey, this.middleGrey, this.middleGrey, this.white * this.white)); this.tonemapMaterial.SetTexture("_SmallTex", this.rt); if (this.type == Tonemapping.TonemapperType.AdaptiveReinhard) { Graphics.Blit(source, destination, this.tonemapMaterial, 0); } else if (this.type == Tonemapping.TonemapperType.AdaptiveReinhardAutoWhite) { Graphics.Blit(source, destination, this.tonemapMaterial, 10); } else { Debug.LogError("No valid adaptive tonemapper type found!"); Graphics.Blit(source, destination); } for (int l = 0; l < num2; l++) { RenderTexture.ReleaseTemporary(array[l]); } RenderTexture.ReleaseTemporary(temporary); } // Token: 0x0400039C RID: 924 public Tonemapping.TonemapperType type = Tonemapping.TonemapperType.Photographic; // Token: 0x0400039D RID: 925 public Tonemapping.AdaptiveTexSize adaptiveTextureSize = Tonemapping.AdaptiveTexSize.Square256; // Token: 0x0400039E RID: 926 public AnimationCurve remapCurve; // Token: 0x0400039F RID: 927 private Texture2D curveTex; // Token: 0x040003A0 RID: 928 public float exposureAdjustment = 1.5f; // Token: 0x040003A1 RID: 929 public float middleGrey = 0.4f; // Token: 0x040003A2 RID: 930 public float white = 2f; // Token: 0x040003A3 RID: 931 public float adaptionSpeed = 1.5f; // Token: 0x040003A4 RID: 932 public Shader tonemapper; // Token: 0x040003A5 RID: 933 public bool validRenderTextureFormat = true; // Token: 0x040003A6 RID: 934 private Material tonemapMaterial; // Token: 0x040003A7 RID: 935 private RenderTexture rt; // Token: 0x040003A8 RID: 936 private RenderTextureFormat rtFormat = RenderTextureFormat.ARGBHalf; // Token: 0x02000092 RID: 146 public enum TonemapperType { // Token: 0x040003AA RID: 938 SimpleReinhard, // Token: 0x040003AB RID: 939 UserCurve, // Token: 0x040003AC RID: 940 Hable, // Token: 0x040003AD RID: 941 Photographic, // Token: 0x040003AE RID: 942 OptimizedHejiDawson, // Token: 0x040003AF RID: 943 AdaptiveReinhard, // Token: 0x040003B0 RID: 944 AdaptiveReinhardAutoWhite } // Token: 0x02000093 RID: 147 public enum AdaptiveTexSize { // Token: 0x040003B2 RID: 946 Square16 = 16, // Token: 0x040003B3 RID: 947 Square32 = 32, // Token: 0x040003B4 RID: 948 Square64 = 64, // Token: 0x040003B5 RID: 949 Square128 = 128, // Token: 0x040003B6 RID: 950 Square256 = 256, // Token: 0x040003B7 RID: 951 Square512 = 512, // Token: 0x040003B8 RID: 952 Square1024 = 1024 } } }