examples/shader: make the default shader deterministic

Updates #1431
Updates #2638
This commit is contained in:
Hajime Hoshi 2023-05-04 23:49:02 +09:00
parent 1de600e397
commit 038cacf97f

View File

@ -21,8 +21,12 @@ var Cursor vec2
var ScreenSize vec2 var ScreenSize vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 { 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. // Normalize the position to [0, 1].
pos := position.xy/imageDstTextureSize() + Cursor/ScreenSize/4 pos := position.xy / imageDstTextureSize()
origin, size := imageDstRegionOnTexture()
pos -= origin
pos /= size
pos += Cursor / ScreenSize / 4
clr := 0.0 clr := 0.0
clr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10) 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) clr += sin(pos.y*sin(Time/10)*40) + cos(pos.x*sin(Time/25)*40)