mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
corrected wrong implementation of Color.toXYZ() and CIEXYZ.toRGB()
Former-commit-id: a2d68b1a3a48b17b54562bd3c90b5dde0fe4dbc4 Former-commit-id: e4284b113b2af11538333f74546ce6692be9dd39
This commit is contained in:
12
README.md
12
README.md
@@ -24,19 +24,27 @@ Any contribution in this project must be made sorely in English, so be sure to u
|
|||||||
* Writing tests
|
* Writing tests
|
||||||
* Code review
|
* Code review
|
||||||
* Guidelines
|
* Guidelines
|
||||||
- Quintessential: write code that even an imbecile can understand.
|
- Well-documented. (comments, people, comments!)
|
||||||
|
|
||||||
|
|
||||||
### Contributing translations ###
|
### Contributing translations ###
|
||||||
|
|
||||||
* Writing text
|
* Writing text
|
||||||
You will need to fiddle with .csv files in ./res/locales
|
You will need to fiddle with .json files in ./res/locales/<Language code>
|
||||||
* Languagus with apparent grammatical gender
|
* Languagus with apparent grammatical gender
|
||||||
Any gender discrimination should *not* exist in this game, so please choose vocabularies that is gender-neutral. If such behaviour is not possible in the target language, please use male gender, but try your best to avoid the situation.
|
Any gender discrimination should *not* exist in this game, so please choose vocabularies that is gender-neutral. If such behaviour is not possible in the target language, please use male gender, but try your best to avoid the situation.
|
||||||
|
|
||||||
Note: Right-to-left languages (arabic, hebrew, etc.) are not supported.
|
Note: Right-to-left languages (arabic, hebrew, etc.) are not supported.
|
||||||
|
|
||||||
|
|
||||||
|
### Contributing artworks ###
|
||||||
|
|
||||||
|
* RGB we mean is always sRGB, _pure white_ we say is always D65 (6 500 K). If you have a monitor calibration device, this is our desired target.
|
||||||
|
* Master material for picture (e.g. psd) can be either RGB/8 or Lab/16.
|
||||||
|
* To comply with the game's art style, only the 12-bit colours must be used (each channel: 0x00, 0x11, 0x22 .. 0xEE, 0xFF), though there is some exception.
|
||||||
|
* Every final audio must be in OGG/Vorbis, q 10.
|
||||||
|
|
||||||
|
|
||||||
## Who do I talk to? ##
|
## Who do I talk to? ##
|
||||||
|
|
||||||
* Repo owner or admin
|
* Repo owner or admin
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ import org.newdawn.slick.Color
|
|||||||
* Created by minjaesong on 16-09-01.
|
* Created by minjaesong on 16-09-01.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
object CIELchUtil {
|
object CIELChUtil {
|
||||||
|
|
||||||
/** Sweet Lch linear gradient */
|
/** Sweet Lch linear gradient */
|
||||||
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
|
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
|
||||||
val from = fromCol.toLch()
|
val from = fromCol.toLCh()
|
||||||
val to = toCol.toLch()
|
val to = toCol.toLCh()
|
||||||
val newL = FastMath.interpolateLinear(scale, from.L, to.L)
|
val newL = FastMath.interpolateLinear(scale, from.L, to.L)
|
||||||
val newC = FastMath.interpolateLinear(scale, from.c, to.c)
|
val newC = FastMath.interpolateLinear(scale, from.C, to.C)
|
||||||
val newAlpha = FastMath.interpolateLinear(scale, from.alpha, to.alpha)
|
val newAlpha = FastMath.interpolateLinear(scale, from.alpha, to.alpha)
|
||||||
val newH: Float
|
val newH: Float
|
||||||
|
|
||||||
@@ -31,25 +31,25 @@ object CIELchUtil {
|
|||||||
else
|
else
|
||||||
newH = FastMath.interpolateLinear(scale, from.h, to.h)
|
newH = FastMath.interpolateLinear(scale, from.h, to.h)
|
||||||
|
|
||||||
return CIELch(newL, newC, newH, newAlpha).toRGB()
|
return CIELCh(newL, newC, newH, newAlpha).toRGB()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun CIELab.toLch(): CIELch {
|
fun CIELab.toLCh(): CIELCh {
|
||||||
val c = (a.sqr() + b.sqr()).sqrt()
|
val c = (a.sqr() + b.sqr()).sqrt()
|
||||||
val h = FastMath.atan2(b, a)
|
val h = FastMath.atan2(b, a)
|
||||||
|
|
||||||
return CIELch(L, c, h, alpha)
|
return CIELCh(L, c, h, alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun CIELch.toLab(): CIELab {
|
fun CIELCh.toLab(): CIELab {
|
||||||
val a = c * FastMath.cos(h)
|
val a = C * FastMath.cos(h)
|
||||||
val b = c * FastMath.sin(h)
|
val b = C * FastMath.sin(h)
|
||||||
|
|
||||||
return CIELab(L, a, b, alpha)
|
return CIELab(L, a, b, alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Color.toLch() = this.toXYZ().toLab().toLch()
|
private fun Color.toLCh() = this.toXYZ().toLab().toLCh()
|
||||||
private fun CIELch.toRGB() = this.toLab().toXYZ().toRGB()
|
private fun CIELCh.toRGB() = this.toLab().toXYZ().toRGB()
|
||||||
|
|
||||||
private fun Float.sqr() = this * this
|
private fun Float.sqr() = this * this
|
||||||
private fun Float.sqrt() = Math.sqrt(this.toDouble()).toFloat()
|
private fun Float.sqrt() = Math.sqrt(this.toDouble()).toFloat()
|
||||||
@@ -59,7 +59,7 @@ object CIELchUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param L : Luminosity in 0.0 - 1.0
|
* @param L : Luminosity in 0.0 - 1.0
|
||||||
* @param c : Chroma (saturation) in 0.0 - 1.0
|
* @param C : Chroma (saturation) in 0.0 - 1.0
|
||||||
* @param h : Hue in radian (-pi to pi)
|
* @param h : Hue in radian (-pi to pi)
|
||||||
*/
|
*/
|
||||||
data class CIELch(var L: Float = 0f, var c: Float = 0f, var h: Float = 0f, var alpha: Float = 1f)
|
data class CIELCh(var L: Float = 0f, var C: Float = 0f, var h: Float = 0f, var alpha: Float = 1f)
|
||||||
@@ -42,17 +42,40 @@ object CIELabUtil {
|
|||||||
private fun CIELab.toRGB() = this.toXYZ().toRGB()
|
private fun CIELab.toRGB() = this.toXYZ().toRGB()
|
||||||
|
|
||||||
fun Color.toXYZ(): CIEXYZ {
|
fun Color.toXYZ(): CIEXYZ {
|
||||||
val x = 0.4124564f * r + 0.3575761f * g + 0.1804375f * b
|
val newR = if (r > 0.04045f)
|
||||||
val y = 0.2126729f * r + 0.7151522f * g + 0.0721750f * b
|
((r + 0.055f) / 1.055f).powerOf(2.4f)
|
||||||
val z = 0.0193339f * r + 0.1191920f * g + 0.9503041f * b
|
else r / 12.92f
|
||||||
|
val newG = if (g > 0.04045f)
|
||||||
|
((g + 0.055f) / 1.055f).powerOf(2.4f)
|
||||||
|
else g / 12.92f
|
||||||
|
val newB = if (b > 0.04045f)
|
||||||
|
((b + 0.055f) / 1.055f).powerOf(2.4f)
|
||||||
|
else b / 12.92f
|
||||||
|
|
||||||
|
val x = 0.4124564f * newR + 0.3575761f * newG + 0.1804375f * newB
|
||||||
|
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, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun CIEXYZ.toRGB(): Color {
|
fun CIEXYZ.toRGB(): Color {
|
||||||
val r = 3.2404542f * x + -1.5371385f * y + -0.4985314f * z
|
var r = 3.2404542f * x + -1.5371385f * y + -0.4985314f * z
|
||||||
val g = -0.9692660f * x + 1.8760108f * y + 0.0415560f * z
|
var g = -0.9692660f * x + 1.8760108f * y + 0.0415560f * z
|
||||||
val b = 0.0556434f * x + -0.2040259f * y + 1.0572252f * 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
|
||||||
|
else
|
||||||
|
r *= 12.92f
|
||||||
|
if (g > 0.0031308f)
|
||||||
|
g = 1.055f * r.powerOf(1f / 2.4f) - 0.055f
|
||||||
|
else
|
||||||
|
g *= 12.92f
|
||||||
|
if (b > 0.0031308f)
|
||||||
|
b = 1.055f * r.powerOf(1f / 2.4f) - 0.055f
|
||||||
|
else
|
||||||
|
b *= 12.92f
|
||||||
|
|
||||||
return Color(r, g, b, alpha)
|
return Color(r, g, b, alpha)
|
||||||
}
|
}
|
||||||
@@ -93,6 +116,7 @@ object CIELabUtil {
|
|||||||
|
|
||||||
private fun Float.cbrt() = FastMath.pow(this, 1f / 3f)
|
private fun Float.cbrt() = FastMath.pow(this, 1f / 3f)
|
||||||
private fun Float.cube() = this * this * this
|
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)
|
data class CIEXYZ(var x: Float = 0f, var y: Float = 0f, var z: Float = 0f, val alpha: Float = 1f)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package net.torvald.terrarum.weather
|
|||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.JsonFetcher
|
import net.torvald.JsonFetcher
|
||||||
import net.torvald.colourutil.CIELchUtil
|
import net.torvald.colourutil.CIELChUtil
|
||||||
import net.torvald.colourutil.ColourUtil
|
import net.torvald.colourutil.ColourUtil
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
@@ -110,7 +110,7 @@ object WeatherMixer {
|
|||||||
val scale = (timeInSec % dataPointDistance).toFloat() / dataPointDistance // [0.0, 1.0]
|
val scale = (timeInSec % dataPointDistance).toFloat() / dataPointDistance // [0.0, 1.0]
|
||||||
|
|
||||||
//val newCol = ColourUtil.getGradient(scale, colourThis, colourNext)
|
//val newCol = ColourUtil.getGradient(scale, colourThis, colourNext)
|
||||||
val newCol = CIELchUtil.getGradient(scale, colourThis, colourNext)
|
val newCol = CIELChUtil.getGradient(scale, colourThis, colourNext)
|
||||||
|
|
||||||
/* // very nice monitor code
|
/* // very nice monitor code
|
||||||
// 65 -> 66 | 300 | 19623 | RGB8(255, 0, 255) -[41%]-> RGB8(193, 97, 23) | * `230`40`160`
|
// 65 -> 66 | 300 | 19623 | RGB8(255, 0, 255) -[41%]-> RGB8(193, 97, 23) | * `230`40`160`
|
||||||
|
|||||||
Reference in New Issue
Block a user