ChromaticAberrationComponent.cs
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
namespace UnityEngine.PostProcessing
{
public sealed class ChromaticAberrationComponent : PostProcessingComponentRenderTexture<ChromaticAberrationModel>
{
static class Uniforms
{
internal static readonly int _ChromaticAberration_Amount = Shader.PropertyToID("_ChromaticAberration_Amount");
internal static readonly int _ChromaticAberration_Spectrum = Shader.PropertyToID("_ChromaticAberration_Spectrum");
}
Texture2D m_SpectrumLut;
public override bool active
{
get
{
return model.enabled
&& model.settings.intensity > 0f
&& !context.interrupted;
}
}
public override void OnDisable()
{
GraphicsUtils.Destroy(m_SpectrumLut);
m_SpectrumLut = null;
}
public override void Prepare(Material uberMaterial)
{
var settings = model.settings;
var spectralLut = settings.spectralTexture;
if (spectralLut == null)
{
if (m_SpectrumLut == null)
{
m_SpectrumLut = new Texture2D(3, 1, TextureFormat.RGB24, false)
{
name = "Chromatic Aberration Spectrum Lookup",
filterMode = FilterMode.Bilinear,
wrapMode = TextureWrapMode.Clamp,
anisoLevel = 0,
hideFlags = HideFlags.DontSave
};
var pixels = new Color[3];
pixels[0] = new Color(1f, 0f, 0f);
pixels[1] = new Color(0f, 1f, 0f);
pixels[2] = new Color(0f, 0f, 1f);
m_SpectrumLut.SetPixels(pixels);
m_SpectrumLut.Apply();
}
spectralLut = m_SpectrumLut;
}
uberMaterial.EnableKeyword("CHROMATIC_ABERRATION");
uberMaterial.SetFloat(Uniforms._ChromaticAberration_Amount, settings.intensity * 0.03f);
uberMaterial.SetTexture(Uniforms._ChromaticAberration_Spectrum, spectralLut);
}
}
}