examples/shader: add comments

Updates #1431
This commit is contained in:
Hajime Hoshi 2023-04-13 14:16:53 +09:00
parent 0776a54712
commit 1c14ba8eeb
2 changed files with 4 additions and 0 deletions

View File

@ -22,6 +22,8 @@ var ScreenSize vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 { func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
center := ScreenSize / 2 center := ScreenSize / 2
// Convert a pixel to a texel by dividing by the texture size.
// TODO: This is confusing. Add a function to treat pixels (#1431).
amount := (center - Cursor) / 10 / imageSrcTextureSize() amount := (center - Cursor) / 10 / imageSrcTextureSize()
var clr vec3 var clr vec3
clr.r = imageSrc2At(texCoord + amount).r clr.r = imageSrc2At(texCoord + amount).r

View File

@ -30,6 +30,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return imageSrc2UnsafeAt(texCoord) return imageSrc2UnsafeAt(texCoord)
} }
// Convert a pixel to a texel by dividing by the texture size.
// TODO: This is confusing. Add a function to treat pixels (#1431).
srcTexSize := imageSrcTextureSize() srcTexSize := imageSrcTextureSize()
xoffset := (4 / srcTexSize.x) * cos(Time*3+pos.y/10) xoffset := (4 / srcTexSize.x) * cos(Time*3+pos.y/10)
yoffset := (20 / srcTexSize.y) * (1.0 + cos(Time*3+pos.y/40)) yoffset := (20 / srcTexSize.y) * (1.0 + cos(Time*3+pos.y/40))