mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
internal/ui: simplify the screen shader
This commit is contained in:
parent
5bb70f485e
commit
7c55065490
@ -36,6 +36,7 @@ var Scale float
|
|||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
sourceSize := imageSrcTextureSize()
|
sourceSize := imageSrcTextureSize()
|
||||||
|
// texelSize is one pixel size in texel sizes.
|
||||||
texelSize := 1 / sourceSize
|
texelSize := 1 / sourceSize
|
||||||
halfScaledTexelSize := texelSize / 2 / Scale
|
halfScaledTexelSize := texelSize / 2 / Scale
|
||||||
|
|
||||||
@ -51,8 +52,15 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
c2 := imageSrc0UnsafeAt(vec2(p0.x, p1.y))
|
c2 := imageSrc0UnsafeAt(vec2(p0.x, p1.y))
|
||||||
c3 := imageSrc0UnsafeAt(p1)
|
c3 := imageSrc0UnsafeAt(p1)
|
||||||
|
|
||||||
rateCenter := vec2(1, 1) - halfScaledTexelSize
|
// 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(p0 * sourceSize) - rateCenter) * Scale) + rateCenter, 0, 1)
|
p := fract(p1 * sourceSize)
|
||||||
|
|
||||||
|
// rate indicates how much the 4 colors are mixed. rate is in between [0, 1].
|
||||||
|
//
|
||||||
|
// 0 <= p < 1/Scale: The rate is in between [0, 1)
|
||||||
|
// 1/Scale <= p: Don't care. Adjacent colors (e.g. c0 vs c1 in an X direction) should be the same.
|
||||||
|
rate := clamp(p*Scale, 0, 1)
|
||||||
|
|
||||||
return mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y)
|
return mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y)
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user