forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVignetteComponent.cs
More file actions
executable file
·48 lines (45 loc) · 2.24 KB
/
Copy pathVignetteComponent.cs
File metadata and controls
executable file
·48 lines (45 loc) · 2.24 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
namespace UnityEngine.PostProcessing
{
public sealed class VignetteComponent : PostProcessingComponentRenderTexture<VignetteModel>
{
static class Uniforms
{
internal static readonly int _Vignette_Color = Shader.PropertyToID("_Vignette_Color");
internal static readonly int _Vignette_Center = Shader.PropertyToID("_Vignette_Center");
internal static readonly int _Vignette_Settings = Shader.PropertyToID("_Vignette_Settings");
internal static readonly int _Vignette_Mask = Shader.PropertyToID("_Vignette_Mask");
internal static readonly int _Vignette_Opacity = Shader.PropertyToID("_Vignette_Opacity");
}
public override bool active
{
get { return model.enabled; }
}
public override void Prepare(Material uberMaterial)
{
var settings = model.settings;
uberMaterial.SetColor(Uniforms._Vignette_Color, settings.color);
if (settings.mode == VignetteModel.Mode.Classic)
{
uberMaterial.SetVector(Uniforms._Vignette_Center, settings.center);
uberMaterial.EnableKeyword("VIGNETTE_CLASSIC");
float roundness = (1f - settings.roundness) * 6f + settings.roundness;
uberMaterial.SetVector(Uniforms._Vignette_Settings, new Vector3(settings.intensity * 3f, settings.smoothness * 5f, roundness));
}
else if (settings.mode == VignetteModel.Mode.Round)
{
uberMaterial.SetVector(Uniforms._Vignette_Center, settings.center);
uberMaterial.EnableKeyword("VIGNETTE_ROUND");
uberMaterial.SetVector(Uniforms._Vignette_Settings, new Vector3(settings.intensity * 3f, settings.smoothness * 5f, 1f));
}
else if (settings.mode == VignetteModel.Mode.Masked)
{
if (settings.mask != null && settings.opacity > 0f)
{
uberMaterial.EnableKeyword("VIGNETTE_MASKED");
uberMaterial.SetTexture(Uniforms._Vignette_Mask, settings.mask);
uberMaterial.SetFloat(Uniforms._Vignette_Opacity, settings.opacity);
}
}
}
}
}