diff --git a/examples/shader/default.go b/examples/shader/default.go index f23f5df55..6150431fc 100644 --- a/examples/shader/default.go +++ b/examples/shader/default.go @@ -21,8 +21,12 @@ var Cursor vec2 var ScreenSize vec2 func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - // Note that the value of position.xy is indeterministic as the destination image is somewhere on a texture atlas. - pos := position.xy/imageDstTextureSize() + Cursor/ScreenSize/4 + // Normalize the position to [0, 1]. + pos := position.xy / imageDstTextureSize() + origin, size := imageDstRegionOnTexture() + pos -= origin + pos /= size + pos += Cursor / ScreenSize / 4 clr := 0.0 clr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10) clr += sin(pos.y*sin(Time/10)*40) + cos(pos.x*sin(Time/25)*40)