Tweetjam 3D Donut

Publicado 2023-06-12


It's a frosted 3D donut, drawn in 265 chars of Lua!

I'm including the code here, with spacing and indents for legibility (instead of minimizing chars like in the cart).

Variable meanings:
X/Y/Z: Current sample position (moves along a camera ray), +Y is up
I/J: Screenspace position
U/V/W: Ray direction (normalized)
C: Output color of the current ray
K: Raymarch iterator
Q: Distance to the unextruded torus on XZ plane
L: Shortest distance to the surface of the extruded 3D torus
A: Angular position of sample pos around the torus (0-1, repeating)

(Both distance values are signed: a negative distance means that a point is inside a shape)