import type { FloatSym , Vec2Sym , Vec2Term , Vec3Sym } from "@thi.ng/shader-ast" ; import { fit1101 } from "@thi.ng/shader-ast-stdlib/math/fit" ; import { aspectCorrectedUV } from "@thi.ng/shader-ast-stdlib/screen/uv" ; import { ret } from "@thi.ng/shader-ast/ast/function" ; import { float , int , vec3 , vec4 } from "@thi.ng/shader-ast/ast/lit" ; import { add , eq , mul , neg } from "@thi.ng/shader-ast/ast/ops" ; import { $xy } from "@thi.ng/shader-ast/ast/swizzle" ; import { sym } from "@thi.ng/shader-ast/ast/sym" ; import { distance , fract , min , mix , sin , } from "@thi.ng/shader-ast/builtin/math" ; import { type , MainImageFn , shaderToy , type , ShaderToyUniforms , } from "@thi.ng/webgl-shadertoy" ; import { glCanvas } from "@thi.ng/webgl/canvas" ; interface DemoUniforms extends ShaderToyUniforms { bright : FloatSym ; } const mainImage = ( gl , unis ) => { let uv ; let mp ; let d1 ; let d2 ; let col ; const rings = ( p , speed = 0.25 , freq = 50 ) => sin ( mul ( add ( distance ( uv , p ) , fract ( mul ( unis . time , speed ) ) ) , freq ) ) ; return [ ( uv = sym ( aspectCorrectedUV ( $xy ( gl . gl_FragCoord ) , unis . resolution ) ) ) , ( mp = sym ( aspectCorrectedUV ( unis . mouse , unis . resolution ) ) ) , ( d1 = sym ( rings ( mp ) ) ) , ( d2 = sym ( rings ( neg ( mp ) ) ) ) , ( col = sym ( mul ( vec3 ( fit1101 ( min ( d1 , d2 ) ) ) , mix ( vec3 ( 1 ) , mul ( vec3 ( d1 , 0 , d2 ) , unis . bright ) , float ( eq ( unis . mouseButtons , int ( 1 ) ) ) ) ) ) ) , ret ( vec4 ( col , 1 ) ) , ] ; } ; const canvas = glCanvas ( { width : window . innerWidth , height : window . innerHeight , parent : document . body , version : 1 , } ) ; const toy = shaderToy ( { canvas : canvas . canvas , gl : canvas . gl , main : mainImage , uniforms : { bright : [ "float" , 1 ] , } , } ) ; toy . start ( ) ;