internal/builtinshader: refactoring

This commit is contained in:
Hajime Hoshi 2024-10-22 14:29:46 +09:00
parent 0fe63e8adb
commit 0a73cbfce4

View File

@ -173,9 +173,8 @@ package main
func Fragment(dstPos vec4, srcPos vec2) vec4 {
// Blend source colors in a square region, which size is 1/scale.
scale := imageDstSize()/imageSrc0Size()
pos := srcPos
p0 := pos - 1/2.0/scale
p1 := pos + 1/2.0/scale
p0 := srcPos - 1/2.0/scale
p1 := srcPos + 1/2.0/scale
// Texels must be in the source rect, so it is not necessary to check.
c0 := imageSrc0UnsafeAt(p0)
@ -183,7 +182,6 @@ func Fragment(dstPos vec4, srcPos vec2) vec4 {
c2 := imageSrc0UnsafeAt(vec2(p0.x, p1.y))
c3 := imageSrc0UnsafeAt(p1)
// p is the p1 value in one pixel assuming that the pixel's upper-left is (0, 0) and the lower-right is (1, 1).
rate := clamp(fract(p1)*scale, 0, 1)
return mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y)
}