removed unnecessary class Light10B, minor fixes for LightmapRenderer

Former-commit-id: 4cddfb080cc689738d9bf308f7d08852f4c78a8b
Former-commit-id: 2354b2483f30e70862a327c1b9688a19bd1b2f66
This commit is contained in:
Song Minjae
2016-09-07 22:58:42 +09:00
parent d817c586e9
commit 9b9b65efba
31 changed files with 3718 additions and 134 deletions

View File

@@ -7,7 +7,8 @@ import net.torvald.colourutil.CIELabUtil.toXYZ
import org.newdawn.slick.Color
/**
* RGB in this code is always sRGB.
* Cylindrical modification of CIELab colour space
*
* reference: http://www.brucelindbloom.com/index.html?Equations.html
*
* Created by minjaesong on 16-09-01.
@@ -15,7 +16,7 @@ import org.newdawn.slick.Color
object CIELChUtil {
/** Sweet LCh linear gradient */
/** Sweet LCh_ab linear gradient */
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
val from = fromCol.toLCh()
val to = toCol.toLCh()
@@ -48,8 +49,8 @@ object CIELChUtil {
return CIELab(L, a, b, alpha)
}
private fun Color.toLCh() = this.toXYZ().toLab().toLCh()
private fun CIELCh.toRGB() = this.toLab().toXYZ().toRGB()
fun Color.toLCh() = this.toXYZ().toLab().toLCh()
fun CIELCh.toRGB() = this.toLab().toXYZ().toRGB()
private fun Float.sqr() = this * this
private fun Float.sqrt() = Math.sqrt(this.toDouble()).toFloat()

View File

@@ -4,9 +4,18 @@ import com.jme3.math.FastMath
import org.newdawn.slick.Color
/**
* A modification of CIEXYZ that is useful for surface colours
*
* If you are trying to mix some colour with other, especially one that
* requires additive mixing (such as illuminant), USE CIELuvUtil, this is
* not for you.
*
* RGB in this code is always sRGB.
* reference: http://www.brucelindbloom.com/index.html?Equations.html
*
* If you're using Mac, you can play around with this colour space with
* ColorSync Utility's calculator.
*
* Created by minjaesong on 16-09-01.
*/
object CIELabUtil {
@@ -38,10 +47,12 @@ object CIELabUtil {
return CIELab(newL, newA, newB, newAlpha).toRGB()
}
private fun Color.toLab() = this.toXYZ().toLab()
private fun CIELab.toRGB() = this.toXYZ().toRGB()
fun Color.toLab() = this.toXYZ().toLab()
fun RGB.toLab() = this.toXYZ().toLab()
fun CIELab.toRGB() = this.toXYZ().toRGB()
fun CIELab.toRawRGB() = this.toXYZ().toRawRGB()
fun Color.toXYZ(): CIEXYZ {
fun RGB.toXYZ(): CIEXYZ {
val newR = if (r > 0.04045f)
((r + 0.055f) / 1.055f).powerOf(2.4f)
else r / 12.92f
@@ -56,13 +67,15 @@ object CIELabUtil {
val y = 0.2126729f * newR + 0.7151522f * newG + 0.0721750f * newB
val z = 0.0193339f * newR + 0.1191920f * newG + 0.9503041f * newB
return CIEXYZ(x, y, z, a)
return CIEXYZ(x, y, z, alpha)
}
fun CIEXYZ.toRGB(): Color {
var r = 3.2404542f * x - 1.5371385f * y - 0.4985314f * z
var g = -0.9692660f * x + 1.8760108f * y + 0.0415560f * z
var b = 0.0556434f * x - 0.2040259f * y + 1.0572252f * z
fun Color.toXYZ(): CIEXYZ = RGB(this).toXYZ()
fun CIEXYZ.toRawRGB(): RGB {
var r = 3.2404542f * X - 1.5371385f * Y - 0.4985314f * Z
var g = -0.9692660f * X + 1.8760108f * Y + 0.0415560f * Z
var b = 0.0556434f * X - 0.2040259f * Y + 1.0572252f * Z
if (r > 0.0031308f)
r = 1.055f * r.powerOf(1f / 2.4f) - 0.055f
@@ -77,13 +90,18 @@ object CIELabUtil {
else
b *= 12.92f
return Color(r, g, b, alpha)
return RGB(r, g, b, alpha)
}
fun CIEXYZ.toRGB(): Color {
val rgb = this.toRawRGB()
return Color(rgb.r, rgb.g, rgb.b, rgb.alpha)
}
fun CIEXYZ.toLab(): CIELab {
val x = pivotXYZ(x / whitePoint.x)
val y = pivotXYZ(y / whitePoint.y)
val z = pivotXYZ(z / whitePoint.z)
val x = pivotXYZ(X / D65.X)
val y = pivotXYZ(Y / D65.Y)
val z = pivotXYZ(Z / D65.Z)
val L = Math.max(0f, 116 * y - 16)
val a = 500 * (x - y)
@@ -101,23 +119,28 @@ object CIELabUtil {
val z3 = z.cube()
return CIEXYZ(
whitePoint.x * if (x3 > epsilon) x3 else (x - 16f / 116f) / 7.787f,
whitePoint.y * if (L > kappa * epsilon) (L.plus(16f) / 116f).cube() else L / kappa,
whitePoint.z * if (z3 > epsilon) z3 else (z - 16f / 116f) / 7.787f,
D65.X * if (x3 > epsilon) x3 else (x - 16f / 116f) / 7.787f,
D65.Y * if (L > kappa * epsilon) (L.plus(16f) / 116f).cube() else L / kappa,
D65.Z * if (z3 > epsilon) z3 else (z - 16f / 116f) / 7.787f,
alpha
)
}
private fun pivotXYZ(n: Float) = if (n > epsilon) n.cbrt() else (kappa * n + 16f) / 116f
val epsilon = 0.008856f
val kappa = 903.3f
val whitePoint = CIEXYZ(95.047f, 100f, 108.883f)
private fun Float.cbrt() = FastMath.pow(this, 1f / 3f)
private fun Float.cube() = this * this * this
private fun Float.powerOf(exp: Float) = FastMath.pow(this, exp)
}
data class CIEXYZ(var x: Float = 0f, var y: Float = 0f, var z: Float = 0f, val alpha: Float = 1f)
internal val D65 = CIEXYZ(95.047f, 100f, 108.883f)
val epsilon = 216.0.div(24389.0).toFloat()
val kappa = 24389.0.div(27.0).toFloat()
data class CIEXYZ(var X: Float = 0f, var Y: Float = 0f, var Z: Float = 0f, val alpha: Float = 1f)
data class CIELab(var L: Float = 0f, var a: Float = 0f, var b: Float = 0f, val alpha: Float = 1f)
data class RGB(var r: Float = 0f, var g: Float = 0f, var b: Float = 0f, val alpha: Float = 1f) {
constructor(color: Color) : this() {
r = color.r; g = color.g; b = color.b
}
}

View File

@@ -0,0 +1,102 @@
package net.torvald.colourutil
import com.jme3.math.FastMath
import org.newdawn.slick.Color
import net.torvald.colourutil.CIELabUtil.toXYZ
import net.torvald.colourutil.CIELabUtil.toRawRGB
import net.torvald.colourutil.CIELabUtil.toRGB
/**
* A modification of CIEXYZ that is useful for additive mixtures of lights.
*
* reference: http://www.brucelindbloom.com/index.html?Equations.html
*
* If you're using Mac, you can play around with this colour space with
* ColorSync Utility's calculator.
*
* Created by minjaesong on 16-09-06.
*/
object CIELuvUtil {
fun Color.brighterLuv(scale: Float): Color {
val brighten = scale + 1f
val luv = this.toLuv()
luv.L *= brighten
return luv.toRGB()
}
fun Color.darkerLuv(scale: Float): Color {
val darken = 1f - scale
val luv = this.toLuv()
luv.L *= darken
return luv.toRGB()
}
/**
* Alpha value will be overwritten to 1.0
*/
infix fun Color.additiveLuv(other: Color): Color {
val rgb = RGB(r, g, b) additiveLuv RGB(other.r, other.g, other.b)
return Color(rgb.r, rgb.g, rgb.b, a)
}
/**
* Alpha value will be overwritten to 1.0
*/
infix fun RGB.additiveLuv(other: RGB): RGB {
val thisLuv = this.toXYZ().toLuv()
val otherLuv = other.toXYZ().toLuv()
val newL = 1f - (1f - thisLuv.L) * (1 - otherLuv.L)
val newU = thisLuv.u.times(otherLuv.L / newL) + otherLuv.u.times(otherLuv.L).times(1f - thisLuv.L).div(newL)
val newV = thisLuv.v.times(otherLuv.L / newL) + otherLuv.v.times(otherLuv.L).times(1f - thisLuv.L).div(newL)
return CIELuv(newL, newU, newV).toRawRGB()
}
fun CIEXYZ.toLuv(): CIELuv {
val yRef = Y / D65.Y
val uPrime = 4f * X / (X + 15f * Y + 3f * Z)
val vPrime = 9f * Y / (X + 15f * Y + 3f * Z)
val uRefPrime = 4f * D65.X / (D65.X + 15f * D65.Y + 3f * D65.Z)
val vRefPrime = 9f * D65.Y / (D65.X + 15f * D65.Y + 3f * D65.Z)
val L = if (yRef > epsilon)
116f * yRef.cbrt() - 16f
else
kappa * yRef
val u = 13f * L * (uPrime - uRefPrime)
val v = 13f * L * (vPrime - vRefPrime)
return CIELuv(L, u, v, alpha)
}
fun CIELuv.toXYZ(): CIEXYZ {
val Y = if (L > kappa * epsilon)
L.plus(16f).div(116f).cube()
else
L.div(kappa)
val uRef = 4f * D65.X / (D65.X + 15f * D65.Y + 3f * D65.Z)
val vRef = 9f * D65.Y / (D65.X + 15f * D65.Y + 3f * D65.Z)
val a = (1f / 3f) * (52.times(L) / u.plus(13 * L * uRef)).minus(1f)
val b = -5f * Y
val c = -1f / 3f
val d = Y * (39f.times(L) / v.plus(13f * L * vRef)).minus(5f)
val X = (d - b) / (a - c)
val Z = X * a + b
return CIEXYZ(X, Y, Z, alpha)
}
fun Color.toLuv() = this.toXYZ().toLuv()
fun CIELuv.toRawRGB() = this.toXYZ().toRawRGB()
fun CIELuv.toRGB() = this.toXYZ().toRGB()
private fun Float.cbrt() = FastMath.pow(this, 1f / 3f)
private fun Float.cube() = this * this * this
}
data class CIELuv(var L: Float = 0f, var u: Float = 0f, var v: Float = 0f, val alpha: Float = 1f)