drawField = regl({
vert: `
${customGlsl.precision}
attribute vec2 position;
varying vec2 uv;
void main() {
// Convert (-1, 1) to (0, 1)
uv = 0.5 * position + 0.5;
gl_Position = vec4(position, 0.0, 1.0);
}`,
frag: `
${customGlsl.precision}
${myREGL}
varying vec2 uv;
uniform sampler2D prevState;
uniform mat4 sun;
void main() {
vec4 sdf = texture2D(prevState, uv);
gl_FragColor = vec4(sdf.xyz, 1.0);
vec3 d;
// Draw the ray trace shadow
${
drawShadow
? `
d = dist(prevState, uv, sun[0].xy);
gl_FragColor = vec4(vec3(d.x), 1.0);
`
: ``
}
// Draw the colorful ray trace shadow
${
drawColorfulShadow
? `
d = dist(prevState, uv, sun[0].xy);
gl_FragColor = vec4(vec3(d), 1.0);
`
: ``
}
// Draw the sun in a small red circle
if (dist(uv, sun[0].xy) < 0.01) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
}`,
attributes: {
position: [-4, -4, 4, -4, 0, 4]
},
count: 3,
depth: false,
uniforms: {
prevState: ({ tick }) => state[tick % 2],
tick: ({ tick }) => tick,
sun: regl.prop("sun")
}
})