all: rename arguments in Fragment

Updates #2767
This commit is contained in:
Hajime Hoshi 2023-09-21 01:33:27 +09:00
parent d7a8f73a37
commit 20ef839e03
12 changed files with 38 additions and 38 deletions

View File

@ -31,11 +31,11 @@ func Warp(pos vec2) vec2 {
return pos/2 + 0.5
}
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
// Adjust the texture position to [0, 1].
origin := imageSrc0Origin()
size := imageSrc0Size()
pos := texCoord
pos := srcPos
pos -= origin
pos /= size

View File

@ -21,12 +21,12 @@ package main
var Time float
var Cursor vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
center := imageDstSize() / 2
amount := (center - Cursor) / 10
var clr vec3
clr.r = imageSrc2At(texCoord + amount).r
clr.g = imageSrc2UnsafeAt(texCoord).g
clr.b = imageSrc2At(texCoord - amount).b
clr.r = imageSrc2At(srcPos + amount).r
clr.g = imageSrc2UnsafeAt(srcPos).g
clr.b = imageSrc2At(srcPos - amount).b
return vec4(clr, 1)
}

View File

@ -21,8 +21,8 @@ package main
var Time float
var Cursor vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
pos := (position.xy - imageDstOrigin()) / imageDstSize()
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
pos := (dstPos.xy - imageDstOrigin()) / imageDstSize()
pos += Cursor / imageDstSize() / 4
clr := 0.0
clr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10)

View File

@ -21,16 +21,16 @@ package main
var Time float
var Cursor vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
// Triangle wave to go 0-->1-->0...
limit := abs(2*fract(Time/3) - 1)
level := imageSrc3UnsafeAt(texCoord).x
level := imageSrc3UnsafeAt(srcPos).x
// Add a white border
if limit-0.1 < level && level < limit {
alpha := imageSrc0UnsafeAt(texCoord).w
alpha := imageSrc0UnsafeAt(srcPos).w
return vec4(alpha)
}
return step(limit, level) * imageSrc0UnsafeAt(texCoord)
return step(limit, level) * imageSrc0UnsafeAt(srcPos)
}

View File

@ -21,13 +21,13 @@ package main
var Time float
var Cursor vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
pos := position.xy - imageDstOrigin()
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
pos := dstPos.xy - imageDstOrigin()
lightpos := vec3(Cursor, 50)
lightdir := normalize(lightpos - vec3(pos, 0))
normal := normalize(imageSrc1UnsafeAt(texCoord) - 0.5)
normal := normalize(imageSrc1UnsafeAt(srcPos) - 0.5)
const ambient = 0.25
diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))
return imageSrc0UnsafeAt(texCoord) * (ambient + diffuse)
return imageSrc0UnsafeAt(srcPos) * (ambient + diffuse)
}

View File

@ -21,18 +21,18 @@ package main
var Time float
var Cursor vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
pos := position.xy - imageDstOrigin()
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
pos := dstPos.xy - imageDstOrigin()
dir := normalize(pos - Cursor)
clr := imageSrc2UnsafeAt(texCoord)
clr := imageSrc2UnsafeAt(srcPos)
samples := [...]float{
-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,
}
sum := clr
for i := 0; i < len(samples); i++ {
sum += imageSrc2At(texCoord + dir*samples[i])
sum += imageSrc2At(srcPos + dir*samples[i])
}
sum /= 10 + 1

View File

@ -18,8 +18,8 @@
package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
pos := position.xy
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
pos := dstPos.xy
pos -= imageDstOrigin()
pos /= imageDstSize()
return vec4(pos.x, pos.y, 0, 1)

View File

@ -21,20 +21,20 @@ package main
var Time float
var Cursor vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
pos := position.xy - imageDstOrigin()
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
pos := dstPos.xy - imageDstOrigin()
border := imageDstSize().y*0.6 + 4*cos(Time*3+pos.y/10)
if pos.y < border {
return imageSrc2UnsafeAt(texCoord)
return imageSrc2UnsafeAt(srcPos)
}
xoffset := 4 * cos(Time*3+pos.y/10)
yoffset := 20 * (1 + cos(Time*3+pos.y/40))
srcOrigin := imageSrc0Origin()
clr := imageSrc2At(vec2(
texCoord.x+xoffset,
-(texCoord.y+yoffset-srcOrigin.y)+border*2+srcOrigin.y,
srcPos.x+xoffset,
-(srcPos.y+yoffset-srcOrigin.y)+border*2+srcOrigin.y,
)).rgb
overlay := vec3(0.5, 1, 1)

View File

@ -28,10 +28,10 @@ const screenShaderSrc = `//kage:unit pixels
package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
// Blend source colors in a square region, which size is 1/scale.
scale := imageDstSize()/imageSrc0Size()
pos := texCoord
pos := srcPos
p0 := pos - 1/2.0/scale
p1 := pos + 1/2.0/scale

View File

@ -67,18 +67,18 @@ func adjustTexelForAddressRepeat(p vec2) vec2 {
}
{{end}}
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
{{if eq .Filter .FilterNearest}}
{{if eq .Address .AddressUnsafe}}
clr := imageSrc0UnsafeAt(texCoord)
clr := imageSrc0UnsafeAt(srcPos)
{{else if eq .Address .AddressClampToZero}}
clr := imageSrc0At(texCoord)
clr := imageSrc0At(srcPos)
{{else if eq .Address .AddressRepeat}}
clr := imageSrc0At(adjustTexelForAddressRepeat(texCoord))
clr := imageSrc0At(adjustTexelForAddressRepeat(srcPos))
{{end}}
{{else if eq .Filter .FilterLinear}}
p0 := texCoord - 1/2.0
p1 := texCoord + 1/2.0
p0 := srcPos - 1/2.0
p1 := srcPos + 1/2.0
{{if eq .Address .AddressRepeat}}
p0 = adjustTexelForAddressRepeat(p0)

View File

@ -154,8 +154,8 @@ func imageSrc%[1]dAt(pos vec2) vec4 {
shaderSuffix += `
var __projectionMatrix mat4
func __vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2, vec4) {
return __projectionMatrix * vec4(position, 0, 1), texCoord, color
func __vertex(dstPos vec2, srcPos vec2, color vec4) (vec4, vec2, vec4) {
return __projectionMatrix * vec4(dstPos, 0, 1), srcPos, color
}
`
return shaderSuffix, nil

View File

@ -84,7 +84,7 @@ func init() {
package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
return vec4(0)
}`))
if err != nil {