fixed & improved Round Log shading

This commit is contained in:
octarine-noise
2016-01-30 00:56:33 +01:00
parent 4720667f53
commit 3e6f98885f
3 changed files with 18 additions and 3 deletions

View File

@@ -45,6 +45,19 @@ fun brSum(multiplier: Float?, vararg brightness: Int): Int {
return result
}
fun brWeighted(br1: Int, weight1: Float, br2: Int, weight2: Float): Int {
val w1int = (weight1 * 256.0f + 0.5f).toInt()
val w2int = (weight2 * 256.0f + 0.5f).toInt()
var result = 0
brightnessComponents.forEachIndexed { idx, shift ->
val comp1 = (br1 shr shift) and 15
val comp2 = (br2 shr shift) and 15
val compWeighted = (comp1 * w1int + comp2 * w2int) / 256
result = result or ((compWeighted and 15) shl shift)
}
return result
}
data class HSB(var hue: Float, var saturation: Float, var brightness: Float) {
companion object {
fun fromColor(color: Int): HSB {

View File

@@ -106,7 +106,7 @@ interface Shader {
red = min(shading1.red * weight1 + shading2.red * weight2, 1.0f)
green = min(shading1.green * weight1 + shading2.green * weight2, 1.0f)
blue = min(shading1.blue * weight1 + shading2.blue * weight2, 1.0f)
brightness = brSum(null, shading1.brightness brMul weight1, shading2.brightness brMul weight2)
brightness = brWeighted(shading1.brightness, weight1, shading2.brightness, weight2)
}
/**