163 lines
5.0 KiB
C#
163 lines
5.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace UnityStandardAssets.ImageEffects
|
|
{
|
|
// Token: 0x02000077 RID: 119
|
|
[ExecuteInEditMode]
|
|
[RequireComponent(typeof(Camera))]
|
|
[AddComponentMenu("Image Effects/Noise/Noise and Scratches")]
|
|
public class NoiseAndScratches : MonoBehaviour
|
|
{
|
|
// Token: 0x06000155 RID: 341 RVA: 0x0000F320 File Offset: 0x0000D720
|
|
protected void Start()
|
|
{
|
|
if (!SystemInfo.supportsImageEffects)
|
|
{
|
|
base.enabled = false;
|
|
return;
|
|
}
|
|
if (this.shaderRGB == null || this.shaderYUV == null)
|
|
{
|
|
Debug.Log("Noise shaders are not set up! Disabling noise effect.");
|
|
base.enabled = false;
|
|
}
|
|
else if (!this.shaderRGB.isSupported)
|
|
{
|
|
base.enabled = false;
|
|
}
|
|
else if (!this.shaderYUV.isSupported)
|
|
{
|
|
this.rgbFallback = true;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000058 RID: 88
|
|
// (get) Token: 0x06000156 RID: 342 RVA: 0x0000F3AC File Offset: 0x0000D7AC
|
|
protected Material material
|
|
{
|
|
get
|
|
{
|
|
if (this.m_MaterialRGB == null)
|
|
{
|
|
this.m_MaterialRGB = new Material(this.shaderRGB);
|
|
this.m_MaterialRGB.hideFlags = HideFlags.HideAndDontSave;
|
|
}
|
|
if (this.m_MaterialYUV == null && !this.rgbFallback)
|
|
{
|
|
this.m_MaterialYUV = new Material(this.shaderYUV);
|
|
this.m_MaterialYUV.hideFlags = HideFlags.HideAndDontSave;
|
|
}
|
|
return (this.rgbFallback || this.monochrome) ? this.m_MaterialRGB : this.m_MaterialYUV;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000157 RID: 343 RVA: 0x0000F449 File Offset: 0x0000D849
|
|
protected void OnDisable()
|
|
{
|
|
if (this.m_MaterialRGB)
|
|
{
|
|
global::UnityEngine.Object.DestroyImmediate(this.m_MaterialRGB);
|
|
}
|
|
if (this.m_MaterialYUV)
|
|
{
|
|
global::UnityEngine.Object.DestroyImmediate(this.m_MaterialYUV);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000158 RID: 344 RVA: 0x0000F484 File Offset: 0x0000D884
|
|
private void SanitizeParameters()
|
|
{
|
|
this.grainIntensityMin = Mathf.Clamp(this.grainIntensityMin, 0f, 5f);
|
|
this.grainIntensityMax = Mathf.Clamp(this.grainIntensityMax, 0f, 5f);
|
|
this.scratchIntensityMin = Mathf.Clamp(this.scratchIntensityMin, 0f, 5f);
|
|
this.scratchIntensityMax = Mathf.Clamp(this.scratchIntensityMax, 0f, 5f);
|
|
this.scratchFPS = Mathf.Clamp(this.scratchFPS, 1f, 30f);
|
|
this.scratchJitter = Mathf.Clamp(this.scratchJitter, 0f, 1f);
|
|
this.grainSize = Mathf.Clamp(this.grainSize, 0.1f, 50f);
|
|
}
|
|
|
|
// Token: 0x06000159 RID: 345 RVA: 0x0000F550 File Offset: 0x0000D950
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
this.SanitizeParameters();
|
|
if (this.scratchTimeLeft <= 0f)
|
|
{
|
|
this.scratchTimeLeft = global::UnityEngine.Random.value * 2f / this.scratchFPS;
|
|
this.scratchX = global::UnityEngine.Random.value;
|
|
this.scratchY = global::UnityEngine.Random.value;
|
|
}
|
|
this.scratchTimeLeft -= Time.deltaTime;
|
|
Material material = this.material;
|
|
material.SetTexture("_GrainTex", this.grainTexture);
|
|
material.SetTexture("_ScratchTex", this.scratchTexture);
|
|
float num = 1f / this.grainSize;
|
|
material.SetVector("_GrainOffsetScale", new Vector4(global::UnityEngine.Random.value, global::UnityEngine.Random.value, (float)Screen.width / (float)this.grainTexture.width * num, (float)Screen.height / (float)this.grainTexture.height * num));
|
|
material.SetVector("_ScratchOffsetScale", new Vector4(this.scratchX + global::UnityEngine.Random.value * this.scratchJitter, this.scratchY + global::UnityEngine.Random.value * this.scratchJitter, (float)Screen.width / (float)this.scratchTexture.width, (float)Screen.height / (float)this.scratchTexture.height));
|
|
material.SetVector("_Intensity", new Vector4(global::UnityEngine.Random.Range(this.grainIntensityMin, this.grainIntensityMax), global::UnityEngine.Random.Range(this.scratchIntensityMin, this.scratchIntensityMax), 0f, 0f));
|
|
Graphics.Blit(source, destination, material);
|
|
}
|
|
|
|
// Token: 0x040002E8 RID: 744
|
|
public bool monochrome = true;
|
|
|
|
// Token: 0x040002E9 RID: 745
|
|
private bool rgbFallback;
|
|
|
|
// Token: 0x040002EA RID: 746
|
|
[Range(0f, 5f)]
|
|
public float grainIntensityMin = 0.1f;
|
|
|
|
// Token: 0x040002EB RID: 747
|
|
[Range(0f, 5f)]
|
|
public float grainIntensityMax = 0.2f;
|
|
|
|
// Token: 0x040002EC RID: 748
|
|
[Range(0.1f, 50f)]
|
|
public float grainSize = 2f;
|
|
|
|
// Token: 0x040002ED RID: 749
|
|
[Range(0f, 5f)]
|
|
public float scratchIntensityMin = 0.05f;
|
|
|
|
// Token: 0x040002EE RID: 750
|
|
[Range(0f, 5f)]
|
|
public float scratchIntensityMax = 0.25f;
|
|
|
|
// Token: 0x040002EF RID: 751
|
|
[Range(1f, 30f)]
|
|
public float scratchFPS = 10f;
|
|
|
|
// Token: 0x040002F0 RID: 752
|
|
[Range(0f, 1f)]
|
|
public float scratchJitter = 0.01f;
|
|
|
|
// Token: 0x040002F1 RID: 753
|
|
public Texture grainTexture;
|
|
|
|
// Token: 0x040002F2 RID: 754
|
|
public Texture scratchTexture;
|
|
|
|
// Token: 0x040002F3 RID: 755
|
|
public Shader shaderRGB;
|
|
|
|
// Token: 0x040002F4 RID: 756
|
|
public Shader shaderYUV;
|
|
|
|
// Token: 0x040002F5 RID: 757
|
|
private Material m_MaterialRGB;
|
|
|
|
// Token: 0x040002F6 RID: 758
|
|
private Material m_MaterialYUV;
|
|
|
|
// Token: 0x040002F7 RID: 759
|
|
private float scratchTimeLeft;
|
|
|
|
// Token: 0x040002F8 RID: 760
|
|
private float scratchX;
|
|
|
|
// Token: 0x040002F9 RID: 761
|
|
private float scratchY;
|
|
}
|
|
}
|