summaryrefslogtreecommitdiff
path: root/Valheim_r202102_v0.141.2/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/DitheringComponent.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Valheim_r202102_v0.141.2/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/DitheringComponent.cs')
-rw-r--r--Valheim_r202102_v0.141.2/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/DitheringComponent.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/Valheim_r202102_v0.141.2/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/DitheringComponent.cs b/Valheim_r202102_v0.141.2/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/DitheringComponent.cs
new file mode 100644
index 0000000..f5f2395
--- /dev/null
+++ b/Valheim_r202102_v0.141.2/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/DitheringComponent.cs
@@ -0,0 +1,61 @@
+namespace UnityEngine.PostProcessing;
+
+public sealed class DitheringComponent : PostProcessingComponentRenderTexture<DitheringModel>
+{
+ private static class Uniforms
+ {
+ internal static readonly int _DitheringTex = Shader.PropertyToID("_DitheringTex");
+
+ internal static readonly int _DitheringCoords = Shader.PropertyToID("_DitheringCoords");
+ }
+
+ private Texture2D[] noiseTextures;
+
+ private int textureIndex;
+
+ private const int k_TextureCount = 64;
+
+ public override bool active
+ {
+ get
+ {
+ if (base.model.enabled)
+ {
+ return !context.interrupted;
+ }
+ return false;
+ }
+ }
+
+ public override void OnDisable()
+ {
+ noiseTextures = null;
+ }
+
+ private void LoadNoiseTextures()
+ {
+ noiseTextures = new Texture2D[64];
+ for (int i = 0; i < 64; i++)
+ {
+ noiseTextures[i] = Resources.Load<Texture2D>("Bluenoise64/LDR_LLL1_" + i);
+ }
+ }
+
+ public override void Prepare(Material uberMaterial)
+ {
+ if (++textureIndex >= 64)
+ {
+ textureIndex = 0;
+ }
+ float value = Random.value;
+ float value2 = Random.value;
+ if (noiseTextures == null)
+ {
+ LoadNoiseTextures();
+ }
+ Texture2D texture2D = noiseTextures[textureIndex];
+ uberMaterial.EnableKeyword("DITHERING");
+ uberMaterial.SetTexture(Uniforms._DitheringTex, texture2D);
+ uberMaterial.SetVector(Uniforms._DitheringCoords, new Vector4((float)context.width / (float)texture2D.width, (float)context.height / (float)texture2D.height, value, value2));
+ }
+}