diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 07:59:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | fb237529724ae1c01b15f99e3b25bdce7c77cf82 (patch) | |
| tree | 5402d604d88b6b6fb0f2ef4f1eba673bfb955b12 /examples/live/shaders | |
| parent | 4350e6840940da0b7af800faf5a1455a1de1908e (diff) | |
| download | sketchbook-fb237529724ae1c01b15f99e3b25bdce7c77cf82.tar.gz sketchbook-fb237529724ae1c01b15f99e3b25bdce7c77cf82.zip | |
examples/live: square units, x and y from the centre in half the height
picture.frag gives the tape x and y in half the target's height, 0 at
its centre and y up (`y` -1 to 1, `x` -1.78 to 1.78 on 16:9), so a
circle is round on any window, half resolution included. Lang.builtins
and the README's table say so; the README's program draws its ring
about the centre (`r = sqrt(x * x + y * y)`, the ring's radius and width
doubled into the new unit).
Test: test/live.script replaces the text (`%`, `c`) with a disc of
radius 0.5, `step(x * x + y * y, 0.25)`, and reads its edge 180 pixels
from the centre across and up: white at 170, black at 190, each way.
zig build test: 85 of 85 steps.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'examples/live/shaders')
| -rw-r--r-- | examples/live/shaders/picture.frag | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/examples/live/shaders/picture.frag b/examples/live/shaders/picture.frag index ec1293e..4621b31 100644 --- a/examples/live/shaders/picture.frag +++ b/examples/live/shaders/picture.frag @@ -1,6 +1,7 @@ #version 450 #extension GL_GOOGLE_include_directive : require -// The color tape at every pixel; x and y run 0..1, y up. +// The color tape at every pixel; x and y in half the target's height, 0 at +// its centre, y up: a circle is round on any window. #include "Picture.glsl" #define TAPE(i) u.tape[i] #include "vm.glsl" @@ -8,6 +9,6 @@ layout(location = 0) out vec4 out_color; void main() { - vec2 p = vec2(gl_FragCoord.x, u.size.y - gl_FragCoord.y) / u.size; + vec2 p = vec2(gl_FragCoord.x - 0.5 * u.size.x, 0.5 * u.size.y - gl_FragCoord.y) / (0.5 * u.size.y); out_color = vec4(clamp(vm(0u, u.len, u.time, p.x, p.y), 0.0, 1.0), 1.0); } |
