yum-slop/TaSTT

Free self-hosted STT for VRChat.

git clone https://git.yummers.dev/yum-slop/TaSTT

yumImplement simple anti-aliasing175965d

v0.19.1
967 B43 linesraw
1#!/usr/bin/env python3
2
3# This is the algorithm that the anti-aliasing logic inside
4# TaSTT_lighting_template.cginc uses.
5
6from math import fmod
7
8x = .5
9y = .1
10aa = 10
11
12# This lets us handle values smaller than 1. We're creating an m*n rectangle
13# and walking a path left-to-right, top-to-bottom through it.
14x_cap = max(x, 1.0 / x)
15y_cap = max(y, 1.0 / y)
16
17print(f"{x_cap} {y_cap}")
18
19def lerp(lo, hi, fract):
20    return lo + (hi - lo) * fract
21
22for i in range(0, aa):
23    # We want to subdivide an x*y area into `aa` evenly spaced pieces.
24    region = x_cap * y_cap
25
26    stride = region / aa
27
28    region_i = i * stride + stride/2
29    region_x = region_i / y_cap
30    region_y = fmod(region_i, y_cap)
31
32    print(f"{region_x} {region_y}")
33
34    region_x = lerp(0, x, region_x / x_cap)
35    region_y = lerp(0, y, region_y / y_cap)
36
37    print(f"{region_x} {region_y}")
38
39    assert(region_x >= 0)
40    assert(region_x <= x)
41    assert(region_y >= 0)
42    assert(region_y <= y)
43