ebiten: use premultiplied-alpha format for ColorScale

Closes #2361
This commit is contained in:
Hajime Hoshi 2022-10-02 14:35:56 +09:00
parent 058b8d5635
commit b0b64e3610
2 changed files with 2 additions and 6 deletions

View File

@ -88,9 +88,5 @@ func (c *ColorScale) Scale(r, g, b, a float32) {
// ScaleWithColor multiplies the given color values to the current scale.
func (c *ColorScale) ScaleWithColor(clr color.Color) {
cr, cg, cb, ca := clr.RGBA()
if ca == 0 {
c.Scale(0, 0, 0, 0)
return
}
c.Scale(float32(cr)/float32(ca), float32(cg)/float32(ca), float32(cb)/float32(ca), float32(ca)/0xffff)
c.Scale(float32(cr)/0xffff, float32(cg)/0xffff, float32(cb)/0xffff, float32(ca)/0xffff)
}

View File

@ -1256,7 +1256,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
op.ColorScale.SetG(5.0 / 8.0)
op.ColorScale.SetB(6.0 / 8.0)
op.ColorScale.SetA(7.0 / 8.0)
op.ColorScale.Scale(1.0/4.0, 2.0/4.0, 3.0/4.0, 4.0/4.0)
op.ColorScale.ScaleWithColor(color.RGBA{0x40, 0x80, 0xc0, 0xff})
dst.DrawRectShader(w, h, s, op)
for j := 0; j < h; j++ {