using System; using UnityEngine; namespace UnityStandardAssets.ImageEffects { // Token: 0x0200004C RID: 76 [ExecuteInEditMode] [RequireComponent(typeof(Camera))] [AddComponentMenu("Image Effects/Bloom and Glow/Bloom")] public class Bloom : PostEffectsBase { // Token: 0x060000CD RID: 205 RVA: 0x00008198 File Offset: 0x00006598 public override bool CheckResources() { base.CheckSupport(false); this.screenBlend = base.CheckShaderAndCreateMaterial(this.screenBlendShader, this.screenBlend); this.lensFlareMaterial = base.CheckShaderAndCreateMaterial(this.lensFlareShader, this.lensFlareMaterial); this.blurAndFlaresMaterial = base.CheckShaderAndCreateMaterial(this.blurAndFlaresShader, this.blurAndFlaresMaterial); this.brightPassFilterMaterial = base.CheckShaderAndCreateMaterial(this.brightPassFilterShader, this.brightPassFilterMaterial); if (!this.isSupported) { base.ReportAutoDisable(); } return this.isSupported; } // Token: 0x060000CE RID: 206 RVA: 0x00008224 File Offset: 0x00006624 public void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!this.CheckResources()) { Graphics.Blit(source, destination); return; } this.doHdr = false; if (this.hdr == Bloom.HDRBloomMode.Auto) { this.doHdr = source.format == RenderTextureFormat.ARGBHalf && base.GetComponent().allowHDR; } else { this.doHdr = this.hdr == Bloom.HDRBloomMode.On; } this.doHdr = this.doHdr && this.supportHDRTextures; Bloom.BloomScreenBlendMode bloomScreenBlendMode = this.screenBlendMode; if (this.doHdr) { bloomScreenBlendMode = Bloom.BloomScreenBlendMode.Add; } RenderTextureFormat renderTextureFormat = ((!this.doHdr) ? RenderTextureFormat.Default : RenderTextureFormat.ARGBHalf); int num = source.width / 2; int num2 = source.height / 2; int num3 = source.width / 4; int num4 = source.height / 4; float num5 = 1f * (float)source.width / (1f * (float)source.height); float num6 = 0.001953125f; RenderTexture temporary = RenderTexture.GetTemporary(num3, num4, 0, renderTextureFormat); RenderTexture temporary2 = RenderTexture.GetTemporary(num, num2, 0, renderTextureFormat); if (this.quality > Bloom.BloomQuality.Cheap) { Graphics.Blit(source, temporary2, this.screenBlend, 2); RenderTexture temporary3 = RenderTexture.GetTemporary(num3, num4, 0, renderTextureFormat); Graphics.Blit(temporary2, temporary3, this.screenBlend, 2); Graphics.Blit(temporary3, temporary, this.screenBlend, 6); RenderTexture.ReleaseTemporary(temporary3); } else { Graphics.Blit(source, temporary2); Graphics.Blit(temporary2, temporary, this.screenBlend, 6); } RenderTexture.ReleaseTemporary(temporary2); RenderTexture renderTexture = RenderTexture.GetTemporary(num3, num4, 0, renderTextureFormat); this.BrightFilter(this.bloomThreshold * this.bloomThresholdColor, temporary, renderTexture); if (this.bloomBlurIterations < 1) { this.bloomBlurIterations = 1; } else if (this.bloomBlurIterations > 10) { this.bloomBlurIterations = 10; } for (int i = 0; i < this.bloomBlurIterations; i++) { float num7 = (1f + (float)i * 0.25f) * this.sepBlurSpread; RenderTexture renderTexture2 = RenderTexture.GetTemporary(num3, num4, 0, renderTextureFormat); this.blurAndFlaresMaterial.SetVector("_Offsets", new Vector4(0f, num7 * num6, 0f, 0f)); Graphics.Blit(renderTexture, renderTexture2, this.blurAndFlaresMaterial, 4); RenderTexture.ReleaseTemporary(renderTexture); renderTexture = renderTexture2; renderTexture2 = RenderTexture.GetTemporary(num3, num4, 0, renderTextureFormat); this.blurAndFlaresMaterial.SetVector("_Offsets", new Vector4(num7 / num5 * num6, 0f, 0f, 0f)); Graphics.Blit(renderTexture, renderTexture2, this.blurAndFlaresMaterial, 4); RenderTexture.ReleaseTemporary(renderTexture); renderTexture = renderTexture2; if (this.quality > Bloom.BloomQuality.Cheap) { if (i == 0) { Graphics.SetRenderTarget(temporary); GL.Clear(false, true, Color.black); Graphics.Blit(renderTexture, temporary); } else { temporary.MarkRestoreExpected(); Graphics.Blit(renderTexture, temporary, this.screenBlend, 10); } } } if (this.quality > Bloom.BloomQuality.Cheap) { Graphics.SetRenderTarget(renderTexture); GL.Clear(false, true, Color.black); Graphics.Blit(temporary, renderTexture, this.screenBlend, 6); } if (this.lensflareIntensity > Mathf.Epsilon) { RenderTexture temporary4 = RenderTexture.GetTemporary(num3, num4, 0, renderTextureFormat); if (this.lensflareMode == Bloom.LensFlareStyle.Ghosting) { this.BrightFilter(this.lensflareThreshold, renderTexture, temporary4); if (this.quality > Bloom.BloomQuality.Cheap) { this.blurAndFlaresMaterial.SetVector("_Offsets", new Vector4(0f, 1.5f / (1f * (float)temporary.height), 0f, 0f)); Graphics.SetRenderTarget(temporary); GL.Clear(false, true, Color.black); Graphics.Blit(temporary4, temporary, this.blurAndFlaresMaterial, 4); this.blurAndFlaresMaterial.SetVector("_Offsets", new Vector4(1.5f / (1f * (float)temporary.width), 0f, 0f, 0f)); Graphics.SetRenderTarget(temporary4); GL.Clear(false, true, Color.black); Graphics.Blit(temporary, temporary4, this.blurAndFlaresMaterial, 4); } this.Vignette(0.975f, temporary4, temporary4); this.BlendFlares(temporary4, renderTexture); } else { float num8 = 1f * Mathf.Cos(this.flareRotation); float num9 = 1f * Mathf.Sin(this.flareRotation); float num10 = this.hollyStretchWidth * 1f / num5 * num6; this.blurAndFlaresMaterial.SetVector("_Offsets", new Vector4(num8, num9, 0f, 0f)); this.blurAndFlaresMaterial.SetVector("_Threshhold", new Vector4(this.lensflareThreshold, 1f, 0f, 0f)); this.blurAndFlaresMaterial.SetVector("_TintColor", new Vector4(this.flareColorA.r, this.flareColorA.g, this.flareColorA.b, this.flareColorA.a) * this.flareColorA.a * this.lensflareIntensity); this.blurAndFlaresMaterial.SetFloat("_Saturation", this.lensFlareSaturation); temporary.DiscardContents(); Graphics.Blit(temporary4, temporary, this.blurAndFlaresMaterial, 2); temporary4.DiscardContents(); Graphics.Blit(temporary, temporary4, this.blurAndFlaresMaterial, 3); this.blurAndFlaresMaterial.SetVector("_Offsets", new Vector4(num8 * num10, num9 * num10, 0f, 0f)); this.blurAndFlaresMaterial.SetFloat("_StretchWidth", this.hollyStretchWidth); temporary.DiscardContents(); Graphics.Blit(temporary4, temporary, this.blurAndFlaresMaterial, 1); this.blurAndFlaresMaterial.SetFloat("_StretchWidth", this.hollyStretchWidth * 2f); temporary4.DiscardContents(); Graphics.Blit(temporary, temporary4, this.blurAndFlaresMaterial, 1); this.blurAndFlaresMaterial.SetFloat("_StretchWidth", this.hollyStretchWidth * 4f); temporary.DiscardContents(); Graphics.Blit(temporary4, temporary, this.blurAndFlaresMaterial, 1); for (int j = 0; j < this.hollywoodFlareBlurIterations; j++) { num10 = this.hollyStretchWidth * 2f / num5 * num6; this.blurAndFlaresMaterial.SetVector("_Offsets", new Vector4(num10 * num8, num10 * num9, 0f, 0f)); temporary4.DiscardContents(); Graphics.Blit(temporary, temporary4, this.blurAndFlaresMaterial, 4); this.blurAndFlaresMaterial.SetVector("_Offsets", new Vector4(num10 * num8, num10 * num9, 0f, 0f)); temporary.DiscardContents(); Graphics.Blit(temporary4, temporary, this.blurAndFlaresMaterial, 4); } if (this.lensflareMode == Bloom.LensFlareStyle.Anamorphic) { this.AddTo(1f, temporary, renderTexture); } else { this.Vignette(1f, temporary, temporary4); this.BlendFlares(temporary4, temporary); this.AddTo(1f, temporary, renderTexture); } } RenderTexture.ReleaseTemporary(temporary4); } int num11 = (int)bloomScreenBlendMode; this.screenBlend.SetFloat("_Intensity", this.bloomIntensity); this.screenBlend.SetTexture("_ColorBuffer", source); if (this.quality > Bloom.BloomQuality.Cheap) { RenderTexture temporary5 = RenderTexture.GetTemporary(num, num2, 0, renderTextureFormat); Graphics.Blit(renderTexture, temporary5); Graphics.Blit(temporary5, destination, this.screenBlend, num11); RenderTexture.ReleaseTemporary(temporary5); } else { Graphics.Blit(renderTexture, destination, this.screenBlend, num11); } RenderTexture.ReleaseTemporary(temporary); RenderTexture.ReleaseTemporary(renderTexture); } // Token: 0x060000CF RID: 207 RVA: 0x000089C5 File Offset: 0x00006DC5 private void AddTo(float intensity_, RenderTexture from, RenderTexture to) { this.screenBlend.SetFloat("_Intensity", intensity_); to.MarkRestoreExpected(); Graphics.Blit(from, to, this.screenBlend, 9); } // Token: 0x060000D0 RID: 208 RVA: 0x000089F0 File Offset: 0x00006DF0 private void BlendFlares(RenderTexture from, RenderTexture to) { this.lensFlareMaterial.SetVector("colorA", new Vector4(this.flareColorA.r, this.flareColorA.g, this.flareColorA.b, this.flareColorA.a) * this.lensflareIntensity); this.lensFlareMaterial.SetVector("colorB", new Vector4(this.flareColorB.r, this.flareColorB.g, this.flareColorB.b, this.flareColorB.a) * this.lensflareIntensity); this.lensFlareMaterial.SetVector("colorC", new Vector4(this.flareColorC.r, this.flareColorC.g, this.flareColorC.b, this.flareColorC.a) * this.lensflareIntensity); this.lensFlareMaterial.SetVector("colorD", new Vector4(this.flareColorD.r, this.flareColorD.g, this.flareColorD.b, this.flareColorD.a) * this.lensflareIntensity); to.MarkRestoreExpected(); Graphics.Blit(from, to, this.lensFlareMaterial); } // Token: 0x060000D1 RID: 209 RVA: 0x00008B40 File Offset: 0x00006F40 private void BrightFilter(float thresh, RenderTexture from, RenderTexture to) { this.brightPassFilterMaterial.SetVector("_Threshhold", new Vector4(thresh, thresh, thresh, thresh)); Graphics.Blit(from, to, this.brightPassFilterMaterial, 0); } // Token: 0x060000D2 RID: 210 RVA: 0x00008B69 File Offset: 0x00006F69 private void BrightFilter(Color threshColor, RenderTexture from, RenderTexture to) { this.brightPassFilterMaterial.SetVector("_Threshhold", threshColor); Graphics.Blit(from, to, this.brightPassFilterMaterial, 1); } // Token: 0x060000D3 RID: 211 RVA: 0x00008B90 File Offset: 0x00006F90 private void Vignette(float amount, RenderTexture from, RenderTexture to) { if (this.lensFlareVignetteMask) { this.screenBlend.SetTexture("_ColorBuffer", this.lensFlareVignetteMask); to.MarkRestoreExpected(); Graphics.Blit((!(from == to)) ? from : null, to, this.screenBlend, (!(from == to)) ? 3 : 7); } else if (from != to) { Graphics.SetRenderTarget(to); GL.Clear(false, true, Color.black); Graphics.Blit(from, to); } } // Token: 0x04000179 RID: 377 public Bloom.TweakMode tweakMode; // Token: 0x0400017A RID: 378 public Bloom.BloomScreenBlendMode screenBlendMode = Bloom.BloomScreenBlendMode.Add; // Token: 0x0400017B RID: 379 public Bloom.HDRBloomMode hdr; // Token: 0x0400017C RID: 380 private bool doHdr; // Token: 0x0400017D RID: 381 public float sepBlurSpread = 2.5f; // Token: 0x0400017E RID: 382 public Bloom.BloomQuality quality = Bloom.BloomQuality.High; // Token: 0x0400017F RID: 383 public float bloomIntensity = 0.5f; // Token: 0x04000180 RID: 384 public float bloomThreshold = 0.5f; // Token: 0x04000181 RID: 385 public Color bloomThresholdColor = Color.white; // Token: 0x04000182 RID: 386 public int bloomBlurIterations = 2; // Token: 0x04000183 RID: 387 public int hollywoodFlareBlurIterations = 2; // Token: 0x04000184 RID: 388 public float flareRotation; // Token: 0x04000185 RID: 389 public Bloom.LensFlareStyle lensflareMode = Bloom.LensFlareStyle.Anamorphic; // Token: 0x04000186 RID: 390 public float hollyStretchWidth = 2.5f; // Token: 0x04000187 RID: 391 public float lensflareIntensity; // Token: 0x04000188 RID: 392 public float lensflareThreshold = 0.3f; // Token: 0x04000189 RID: 393 public float lensFlareSaturation = 0.75f; // Token: 0x0400018A RID: 394 public Color flareColorA = new Color(0.4f, 0.4f, 0.8f, 0.75f); // Token: 0x0400018B RID: 395 public Color flareColorB = new Color(0.4f, 0.8f, 0.8f, 0.75f); // Token: 0x0400018C RID: 396 public Color flareColorC = new Color(0.8f, 0.4f, 0.8f, 0.75f); // Token: 0x0400018D RID: 397 public Color flareColorD = new Color(0.8f, 0.4f, 0f, 0.75f); // Token: 0x0400018E RID: 398 public Texture2D lensFlareVignetteMask; // Token: 0x0400018F RID: 399 public Shader lensFlareShader; // Token: 0x04000190 RID: 400 private Material lensFlareMaterial; // Token: 0x04000191 RID: 401 public Shader screenBlendShader; // Token: 0x04000192 RID: 402 private Material screenBlend; // Token: 0x04000193 RID: 403 public Shader blurAndFlaresShader; // Token: 0x04000194 RID: 404 private Material blurAndFlaresMaterial; // Token: 0x04000195 RID: 405 public Shader brightPassFilterShader; // Token: 0x04000196 RID: 406 private Material brightPassFilterMaterial; // Token: 0x0200004D RID: 77 public enum LensFlareStyle { // Token: 0x04000198 RID: 408 Ghosting, // Token: 0x04000199 RID: 409 Anamorphic, // Token: 0x0400019A RID: 410 Combined } // Token: 0x0200004E RID: 78 public enum TweakMode { // Token: 0x0400019C RID: 412 Basic, // Token: 0x0400019D RID: 413 Complex } // Token: 0x0200004F RID: 79 public enum HDRBloomMode { // Token: 0x0400019F RID: 415 Auto, // Token: 0x040001A0 RID: 416 On, // Token: 0x040001A1 RID: 417 Off } // Token: 0x02000050 RID: 80 public enum BloomScreenBlendMode { // Token: 0x040001A3 RID: 419 Screen, // Token: 0x040001A4 RID: 420 Add } // Token: 0x02000051 RID: 81 public enum BloomQuality { // Token: 0x040001A6 RID: 422 Cheap, // Token: 0x040001A7 RID: 423 High } } }