Skip to content

Commit

Permalink
Fixes colMul premultiplied color in FSprites (#1448)
Browse files Browse the repository at this point in the history
Fixes colMul premultiplied color
  • Loading branch information
soywiz authored Mar 23, 2023
1 parent 6ba0d6c commit 72179db
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ open class FSprites(val maxSize: Int) {
val baseSize = TEMP(VarType.Float2)
val texSize = TEMP(VarType.Float2)
SET(baseSize, a_uv1 - a_uv0)
SET(v_Col, a_colMul)
SET(v_Col, vec4(a_colMul["rgb"] * a_colMul["a"], a_colMul["a"])) // Pre-multiply color here
SET(v_TexId, a_texId)

//SET(texSize, u_i_texSizeN[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.soywiz.korge.view.fast

import com.soywiz.korge.testing.*
import com.soywiz.korge.tests.*
import com.soywiz.korge.view.*
import com.soywiz.korim.bitmap.*
import com.soywiz.korim.color.*
import com.soywiz.korma.geom.*
import kotlin.test.*

Expand All @@ -25,4 +27,31 @@ class FSpritesJvmTest : ViewsForTesting(log = true) {
}
assertScreenshot(this, includeBackground = true)
}

@Test
fun testAlpha() = korgeScreenshotTest(SizeInt(20, 20), bgcolor = Colors.GREEN) {
val bmp = Bitmap32(10, 10, Colors.RED).premultiplied()
image(bmp).xy(0, 0)
image(bmp) {
xy(0, 10)
alpha = .5
}

val fSprites = FSprites(2)
addChild(fSprites.createView(bmp))
with(fSprites) {
val left = fSprites.alloc()
left.xy(10f, 0f)
left.colorMul = Colors.WHITE
left.setTexIndex(0)
left.setTex(bmp.slice())

val right = fSprites.alloc()
right.xy(10f, 10f)
right.colorMul = Colors.WHITE.withAf(.5f)
right.setTexIndex(0)
right.setTex(bmp.slice())
}
assertScreenshot(this, includeBackground = true)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 72179db

Please sign in to comment.