Square SDF
Based on work by Inigo Quilez: https://iquilezles.org/articles/distfunctions2d/
Example Links
The sdf function is imported, but we then need to set up a proxy function. This is because the macro system relies on inlining, and we want to create a function definition, not just inline the body at the point of use.
This shader also uses an imported 'fill' function to calculate a nice colour gradient.
inline def fragment =
Shader[FragmentEnv] { env =>
import ultraviolet.sdf.*
import FillColorHelper.*
def proxy: (vec2, vec2) => Float =
(p, b) => box(p, b)
def calculateColour: (vec2, Float) => vec4 = (uv, sdf) => fill(uv, sdf)
def fragment(color: vec4): vec4 =
calculateColour(env.UV, proxy(env.UV - 0.5f, vec2(0.2f, 0.4f)))
}