diff --git a/examples/shader/lighting.go b/examples/shader/lighting.go index 20921b101..fb2b22e00 100644 --- a/examples/shader/lighting.go +++ b/examples/shader/lighting.go @@ -21,8 +21,12 @@ var Cursor vec2 var ScreenSize vec2 func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + srcOrigin, srcSize := imageSrcRegionOnTexture() + pos := (texCoord - srcOrigin) / srcSize + pos *= ScreenSize + lightpos := vec3(Cursor, 50) - lightdir := normalize(lightpos - position.xyz) + lightdir := normalize(lightpos - vec3(pos, 0)) normal := normalize(imageSrc1UnsafeAt(texCoord) - 0.5) const ambient = 0.25 diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir)) diff --git a/examples/shader/radialblur.go b/examples/shader/radialblur.go index 0cb4521e4..4b50d3757 100644 --- a/examples/shader/radialblur.go +++ b/examples/shader/radialblur.go @@ -21,7 +21,11 @@ var Cursor vec2 var ScreenSize vec2 func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - dir := normalize(position.xy - Cursor) + srcOrigin, srcSize := imageSrcRegionOnTexture() + pos := (texCoord - srcOrigin) / srcSize + pos *= ScreenSize + + dir := normalize(pos - Cursor) clr := imageSrc2UnsafeAt(texCoord) samples := [...]float{ @@ -34,7 +38,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { } sum /= 10 + 1 - dist := distance(position.xy, Cursor) + dist := distance(pos, Cursor) t := clamp(dist/256, 0, 1) return mix(clr, sum, t) } diff --git a/examples/shader/water.go b/examples/shader/water.go index 4dccf6a20..7af02d28c 100644 --- a/examples/shader/water.go +++ b/examples/shader/water.go @@ -21,22 +21,23 @@ var Cursor vec2 var ScreenSize vec2 func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - srcsize := imageSrcTextureSize() - ypx := texCoord.y * srcsize.y + srcOrigin, srcSize := imageSrcRegionOnTexture() + pos := (texCoord - srcOrigin) / srcSize + pos *= ScreenSize - border := ScreenSize.y*0.6 + 4*cos(Time*3+ypx/10) - if position.y < border { + border := ScreenSize.y*0.6 + 4*cos(Time*3+pos.y/10) + if pos.y < border { return imageSrc2UnsafeAt(texCoord) } - rorigin, _ := imageSrcRegionOnTexture() - - xoffset := (4 / srcsize.x) * cos(Time*3+ypx/10) - yoffset := (20 / srcsize.y) * (1.0 + cos(Time*3+ypx/40)) - bordertex := border / srcsize.y + // TODO: As the texture size can vary, using srcTexSize here seems wrong (#1431). + srcTexSize := imageSrcTextureSize() + xoffset := (4 / srcTexSize.x) * cos(Time*3+pos.y/10) + yoffset := (20 / srcTexSize.y) * (1.0 + cos(Time*3+pos.y/40)) + bordertex := border / srcTexSize.y clr := imageSrc2At(vec2( texCoord.x+xoffset, - -(texCoord.y+yoffset-rorigin.y)+bordertex*2+rorigin.y, + -(texCoord.y+yoffset-srcOrigin.y)+bordertex*2+srcOrigin.y, )).rgb overlay := vec3(0.5, 1, 1)