forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrainComponent.cs
More file actions
executable file
·45 lines (39 loc) · 1.51 KB
/
Copy pathGrainComponent.cs
File metadata and controls
executable file
·45 lines (39 loc) · 1.51 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
namespace UnityEngine.PostProcessing
{
public sealed class GrainComponent : PostProcessingComponentRenderTexture<GrainModel>
{
static class Uniforms
{
internal static readonly int _Grain_Params1 = Shader.PropertyToID("_Grain_Params1");
internal static readonly int _Grain_Params2 = Shader.PropertyToID("_Grain_Params2");
}
public override bool active
{
get
{
return model.enabled
&& model.settings.intensity > 0f;
}
}
public override void Prepare(Material uberMaterial)
{
var settings = model.settings;
uberMaterial.EnableKeyword(
settings.mode == GrainModel.Mode.Fast
? "GRAIN_FAST"
: "GRAIN_FILMIC"
);
#if POSTFX_DEBUG_STATIC_GRAIN
float time = 4f;
#else
float time = Time.realtimeSinceStartup;
#endif
// Used for sample rotation in Filmic mode and position offset in Fast mode
const float kRotationOffset = 1.425f;
float c = Mathf.Cos(time + kRotationOffset);
float s = Mathf.Sin(time + kRotationOffset);
uberMaterial.SetVector(Uniforms._Grain_Params1, new Vector4(settings.intensity * 0.25f, settings.size, settings.luminanceContribution, (float)context.width / (float)context.height));
uberMaterial.SetVector(Uniforms._Grain_Params2, new Vector3(c, s, time / 20f));
}
}
}