using System;
using UnityEngine;

namespace UnityStandardAssets.ImageEffects
{
	// Token: 0x02000119 RID: 281
	[ExecuteInEditMode]
	[RequireComponent(typeof(Camera))]
	[AddComponentMenu("Image Effects/Blur/Blur (Optimized)")]
	public class BlurOptimized : PostEffectsBase
	{
		// Token: 0x060016C7 RID: 5831 RVA: 0x001A1411 File Offset: 0x0019F611
		public void OnEnable()
		{
		}

		// Token: 0x060016C8 RID: 5832 RVA: 0x001A1413 File Offset: 0x0019F613
		public void OnDisable()
		{
		}

		// Token: 0x060016C9 RID: 5833 RVA: 0x001A1418 File Offset: 0x0019F618
		public void OnRenderImage(RenderTexture source, RenderTexture destination)
		{
			if (!this.blurMaterial)
			{
				this.blurMaterial = new Material(this.blurShader);
			}
			float num = 1f / (1f * (float)(1 << this.downsample));
			this.blurMaterial.SetVector("_Parameter", new Vector4(this.blurSize * num, -this.blurSize * num, 0f, 0f));
			source.filterMode = FilterMode.Bilinear;
			int num2 = source.width >> this.downsample;
			int num3 = source.height >> this.downsample;
			RenderTexture renderTexture = RenderTexture.GetTemporary(num2, num3, 0, source.format);
			renderTexture.filterMode = FilterMode.Bilinear;
			Graphics.Blit(source, renderTexture, this.blurMaterial, 0);
			int num4 = ((this.blurType == BlurOptimized.BlurType.StandardGauss) ? 0 : 2);
			for (int i = 0; i < this.blurIterations; i++)
			{
				float num5 = (float)i * 1f;
				this.blurMaterial.SetVector("_Parameter", new Vector4(this.blurSize * num + num5, -this.blurSize * num - num5, 0f, 0f));
				RenderTexture renderTexture2 = RenderTexture.GetTemporary(num2, num3, 0, source.format);
				renderTexture2.filterMode = FilterMode.Bilinear;
				Graphics.Blit(renderTexture, renderTexture2, this.blurMaterial, 1 + num4);
				RenderTexture.ReleaseTemporary(renderTexture);
				renderTexture = renderTexture2;
				renderTexture2 = RenderTexture.GetTemporary(num2, num3, 0, source.format);
				renderTexture2.filterMode = FilterMode.Bilinear;
				Graphics.Blit(renderTexture, renderTexture2, this.blurMaterial, 2 + num4);
				RenderTexture.ReleaseTemporary(renderTexture);
				renderTexture = renderTexture2;
			}
			Graphics.Blit(renderTexture, destination);
			RenderTexture.ReleaseTemporary(renderTexture);
		}

		// Token: 0x040026ED RID: 9965
		[Range(0f, 2f)]
		public int downsample = 1;

		// Token: 0x040026EE RID: 9966
		[Range(0f, 10f)]
		public float blurSize = 3f;

		// Token: 0x040026EF RID: 9967
		[Range(1f, 4f)]
		public int blurIterations = 2;

		// Token: 0x040026F0 RID: 9968
		public BlurOptimized.BlurType blurType;

		// Token: 0x040026F1 RID: 9969
		public Shader blurShader;

		// Token: 0x040026F2 RID: 9970
		private Material blurMaterial;

		// Token: 0x0200026C RID: 620
		public enum BlurType
		{
			// Token: 0x040034C9 RID: 13513
			StandardGauss,
			// Token: 0x040034CA RID: 13514
			SgxGauss
		}
	}
}
