210 lines
5.7 KiB
C#
210 lines
5.7 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace UnityStandardAssets.ImageEffects
|
|
{
|
|
// Token: 0x02000064 RID: 100
|
|
[ExecuteInEditMode]
|
|
[AddComponentMenu("Image Effects/Color Adjustments/Contrast Stretch")]
|
|
public class ContrastStretch : MonoBehaviour
|
|
{
|
|
// Token: 0x17000053 RID: 83
|
|
// (get) Token: 0x0600010C RID: 268 RVA: 0x0000B94D File Offset: 0x00009D4D
|
|
protected Material materialLum
|
|
{
|
|
get
|
|
{
|
|
if (this.m_materialLum == null)
|
|
{
|
|
this.m_materialLum = new Material(this.shaderLum);
|
|
this.m_materialLum.hideFlags = HideFlags.HideAndDontSave;
|
|
}
|
|
return this.m_materialLum;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000054 RID: 84
|
|
// (get) Token: 0x0600010D RID: 269 RVA: 0x0000B984 File Offset: 0x00009D84
|
|
protected Material materialReduce
|
|
{
|
|
get
|
|
{
|
|
if (this.m_materialReduce == null)
|
|
{
|
|
this.m_materialReduce = new Material(this.shaderReduce);
|
|
this.m_materialReduce.hideFlags = HideFlags.HideAndDontSave;
|
|
}
|
|
return this.m_materialReduce;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000055 RID: 85
|
|
// (get) Token: 0x0600010E RID: 270 RVA: 0x0000B9BB File Offset: 0x00009DBB
|
|
protected Material materialAdapt
|
|
{
|
|
get
|
|
{
|
|
if (this.m_materialAdapt == null)
|
|
{
|
|
this.m_materialAdapt = new Material(this.shaderAdapt);
|
|
this.m_materialAdapt.hideFlags = HideFlags.HideAndDontSave;
|
|
}
|
|
return this.m_materialAdapt;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000056 RID: 86
|
|
// (get) Token: 0x0600010F RID: 271 RVA: 0x0000B9F2 File Offset: 0x00009DF2
|
|
protected Material materialApply
|
|
{
|
|
get
|
|
{
|
|
if (this.m_materialApply == null)
|
|
{
|
|
this.m_materialApply = new Material(this.shaderApply);
|
|
this.m_materialApply.hideFlags = HideFlags.HideAndDontSave;
|
|
}
|
|
return this.m_materialApply;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000110 RID: 272 RVA: 0x0000BA2C File Offset: 0x00009E2C
|
|
private void Start()
|
|
{
|
|
if (!SystemInfo.supportsImageEffects)
|
|
{
|
|
base.enabled = false;
|
|
return;
|
|
}
|
|
if (!this.shaderAdapt.isSupported || !this.shaderApply.isSupported || !this.shaderLum.isSupported || !this.shaderReduce.isSupported)
|
|
{
|
|
base.enabled = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000111 RID: 273 RVA: 0x0000BA94 File Offset: 0x00009E94
|
|
private void OnEnable()
|
|
{
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
if (!this.adaptRenderTex[i])
|
|
{
|
|
this.adaptRenderTex[i] = new RenderTexture(1, 1, 0);
|
|
this.adaptRenderTex[i].hideFlags = HideFlags.HideAndDontSave;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000112 RID: 274 RVA: 0x0000BAE4 File Offset: 0x00009EE4
|
|
private void OnDisable()
|
|
{
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
global::UnityEngine.Object.DestroyImmediate(this.adaptRenderTex[i]);
|
|
this.adaptRenderTex[i] = null;
|
|
}
|
|
if (this.m_materialLum)
|
|
{
|
|
global::UnityEngine.Object.DestroyImmediate(this.m_materialLum);
|
|
}
|
|
if (this.m_materialReduce)
|
|
{
|
|
global::UnityEngine.Object.DestroyImmediate(this.m_materialReduce);
|
|
}
|
|
if (this.m_materialAdapt)
|
|
{
|
|
global::UnityEngine.Object.DestroyImmediate(this.m_materialAdapt);
|
|
}
|
|
if (this.m_materialApply)
|
|
{
|
|
global::UnityEngine.Object.DestroyImmediate(this.m_materialApply);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000113 RID: 275 RVA: 0x0000BB88 File Offset: 0x00009F88
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
RenderTexture renderTexture = RenderTexture.GetTemporary(source.width, source.height);
|
|
Graphics.Blit(source, renderTexture, this.materialLum);
|
|
while (renderTexture.width > 1 || renderTexture.height > 1)
|
|
{
|
|
int num = renderTexture.width / 2;
|
|
if (num < 1)
|
|
{
|
|
num = 1;
|
|
}
|
|
int num2 = renderTexture.height / 2;
|
|
if (num2 < 1)
|
|
{
|
|
num2 = 1;
|
|
}
|
|
RenderTexture temporary = RenderTexture.GetTemporary(num, num2);
|
|
Graphics.Blit(renderTexture, temporary, this.materialReduce);
|
|
RenderTexture.ReleaseTemporary(renderTexture);
|
|
renderTexture = temporary;
|
|
}
|
|
this.CalculateAdaptation(renderTexture);
|
|
this.materialApply.SetTexture("_AdaptTex", this.adaptRenderTex[this.curAdaptIndex]);
|
|
Graphics.Blit(source, destination, this.materialApply);
|
|
RenderTexture.ReleaseTemporary(renderTexture);
|
|
}
|
|
|
|
// Token: 0x06000114 RID: 276 RVA: 0x0000BC4C File Offset: 0x0000A04C
|
|
private void CalculateAdaptation(Texture curTexture)
|
|
{
|
|
int num = this.curAdaptIndex;
|
|
this.curAdaptIndex = (this.curAdaptIndex + 1) % 2;
|
|
float num2 = 1f - Mathf.Pow(1f - this.adaptationSpeed, 30f * Time.deltaTime);
|
|
num2 = Mathf.Clamp(num2, 0.01f, 1f);
|
|
this.materialAdapt.SetTexture("_CurTex", curTexture);
|
|
this.materialAdapt.SetVector("_AdaptParams", new Vector4(num2, this.limitMinimum, this.limitMaximum, 0f));
|
|
Graphics.SetRenderTarget(this.adaptRenderTex[this.curAdaptIndex]);
|
|
GL.Clear(false, true, Color.black);
|
|
Graphics.Blit(this.adaptRenderTex[num], this.adaptRenderTex[this.curAdaptIndex], this.materialAdapt);
|
|
}
|
|
|
|
// Token: 0x04000240 RID: 576
|
|
[Range(0.0001f, 1f)]
|
|
public float adaptationSpeed = 0.02f;
|
|
|
|
// Token: 0x04000241 RID: 577
|
|
[Range(0f, 1f)]
|
|
public float limitMinimum = 0.2f;
|
|
|
|
// Token: 0x04000242 RID: 578
|
|
[Range(0f, 1f)]
|
|
public float limitMaximum = 0.6f;
|
|
|
|
// Token: 0x04000243 RID: 579
|
|
private RenderTexture[] adaptRenderTex = new RenderTexture[2];
|
|
|
|
// Token: 0x04000244 RID: 580
|
|
private int curAdaptIndex;
|
|
|
|
// Token: 0x04000245 RID: 581
|
|
public Shader shaderLum;
|
|
|
|
// Token: 0x04000246 RID: 582
|
|
private Material m_materialLum;
|
|
|
|
// Token: 0x04000247 RID: 583
|
|
public Shader shaderReduce;
|
|
|
|
// Token: 0x04000248 RID: 584
|
|
private Material m_materialReduce;
|
|
|
|
// Token: 0x04000249 RID: 585
|
|
public Shader shaderAdapt;
|
|
|
|
// Token: 0x0400024A RID: 586
|
|
private Material m_materialAdapt;
|
|
|
|
// Token: 0x0400024B RID: 587
|
|
public Shader shaderApply;
|
|
|
|
// Token: 0x0400024C RID: 588
|
|
private Material m_materialApply;
|
|
}
|
|
}
|