Skip to content

Commit

Permalink
internal/builtinshader: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Oct 22, 2024
1 parent 0fe63e8 commit 0a73cbf
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions internal/builtinshader/shader.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,15 @@ 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)
c1 := imageSrc0UnsafeAt(vec2(p1.x, p0.y))
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)
}
Expand Down

0 comments on commit 0a73cbf

Please sign in to comment.