summaryrefslogtreecommitdiffstats
path: root/Shaders/aa_sample_algorithm.py
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2023-01-31 19:11:01 -0800
committeryum <yum.food.vr@gmail.com>2023-01-31 19:35:44 -0800
commit175965da720659df3099d3cda06a342fdfbe1cd4 (patch)
tree3c85c6ab3d2a806aa7f7069eaf3ceeb1f6410c1b /Shaders/aa_sample_algorithm.py
parent46f03b7ed89ab8146d143cdda733acd178c5314e (diff)
Implement simple anti-aliasing
Sample the texture up to 5 times using the algorithm shown in `aa_sample_algorithm.py`. Results are averaged together. * Redo dithering PRNG
Diffstat (limited to 'Shaders/aa_sample_algorithm.py')
-rw-r--r--Shaders/aa_sample_algorithm.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/Shaders/aa_sample_algorithm.py b/Shaders/aa_sample_algorithm.py
new file mode 100644
index 0000000..779e159
--- /dev/null
+++ b/Shaders/aa_sample_algorithm.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+# This is the algorithm that the anti-aliasing logic inside
+# TaSTT_lighting_template.cginc uses.
+
+from math import fmod
+
+x = .5
+y = .1
+aa = 10
+
+# This lets us handle values smaller than 1. We're creating an m*n rectangle
+# and walking a path left-to-right, top-to-bottom through it.
+x_cap = max(x, 1.0 / x)
+y_cap = max(y, 1.0 / y)
+
+print(f"{x_cap} {y_cap}")
+
+def lerp(lo, hi, fract):
+ return lo + (hi - lo) * fract
+
+for i in range(0, aa):
+ # We want to subdivide an x*y area into `aa` evenly spaced pieces.
+ region = x_cap * y_cap
+
+ stride = region / aa
+
+ region_i = i * stride + stride/2
+ region_x = region_i / y_cap
+ region_y = fmod(region_i, y_cap)
+
+ print(f"{region_x} {region_y}")
+
+ region_x = lerp(0, x, region_x / x_cap)
+ region_y = lerp(0, y, region_y / y_cap)
+
+ print(f"{region_x} {region_y}")
+
+ assert(region_x >= 0)
+ assert(region_x <= x)
+ assert(region_y >= 0)
+ assert(region_y <= y)
+