mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 13:21:51 +09:00
skybox: taller grad window, smooth grad clamping
This commit is contained in:
@@ -166,6 +166,19 @@ final public class FastMath {
|
||||
return ((1f - scale) * startValue) + (scale * endValue);
|
||||
}
|
||||
|
||||
public static double interpolateLinear(double scale, double startValue, double endValue) {
|
||||
if (startValue == endValue) {
|
||||
return startValue;
|
||||
}
|
||||
if (scale <= 0.0) {
|
||||
return startValue;
|
||||
}
|
||||
if (scale >= 1.0) {
|
||||
return endValue;
|
||||
}
|
||||
return ((1.0 - scale) * startValue) + (scale * endValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Linear interpolation from startValue to endValue by the given percent.
|
||||
* Basically: ((1 - percent) * startValue) + (percent * endValue)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package net.torvald.terrarum.modulebasegame.clut
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.CIEXYZ
|
||||
import net.torvald.colourutil.toColor
|
||||
import net.torvald.colourutil.toRGB
|
||||
@@ -100,18 +102,35 @@ object Skybox : Disposable {
|
||||
private fun polynomialDecay(p: Double, q: Int, x: Double): Double {
|
||||
val sign = if (q % 2 == 1) -1 else 1
|
||||
val a1 = -1.0 / p
|
||||
val a2 = -1.0 / (1.0 - p)
|
||||
val a2 = 1.0 / (1.0 - p)
|
||||
val q = q.toDouble()
|
||||
return if (x < p)
|
||||
sign * a1.pow(q - 1.0) * x.pow(q) + 1.0
|
||||
else
|
||||
sign * a1.pow(q - 1.0) * (x - 1.0).pow(q)
|
||||
sign * a2.pow(q - 1.0) * (x - 1.0).pow(q)
|
||||
}
|
||||
|
||||
private fun polynomialDecay2(p: Double, q: Int, x: Double): Double {
|
||||
val sign = if (q % 2 == 1) 1 else -1
|
||||
val a1 = -1.0 / p
|
||||
val a2 = 1.0 / (1.0 - p)
|
||||
val q = q.toDouble()
|
||||
return if (x < p)
|
||||
sign * a1.pow(q - 1.0) * x.pow(q)
|
||||
else
|
||||
sign * a2.pow(q - 1.0) * (x - 1.0).pow(q) + 1.0
|
||||
}
|
||||
|
||||
private fun superellipsoidDecay(p: Double, x: Double): Double {
|
||||
return 1.0 - (1.0 - (1.0 - x).pow(1.0 / p)).pow(p)
|
||||
}
|
||||
|
||||
private fun Double.coerceInSmoothly(low: Double, high: Double): Double {
|
||||
val x = this.coerceIn(low, high)
|
||||
val x2 = ((x - low) * (high - low).pow(-1.0))
|
||||
return FastMath.interpolateLinear(polynomialDecay2(0.5, 2, x2), low, high)
|
||||
}
|
||||
|
||||
private fun getTexturmaps(albedo: Double): Array<Texture> {
|
||||
return Array(elevCnt * turbCnt) {
|
||||
|
||||
@@ -124,14 +143,16 @@ object Skybox : Disposable {
|
||||
|
||||
// printdbg(this, "elev $elevationDeg turb $turbidity")
|
||||
|
||||
for (y in 0 until gradSize) {
|
||||
for (yp in 0 until gradSize) {
|
||||
val yi = yp - 6
|
||||
val xf = -elevationDeg / 90.0
|
||||
var yf = (y + 0.5) / gradSize.toDouble()
|
||||
var yf = (yi / 116.0).coerceInSmoothly(0.0, 0.95)
|
||||
|
||||
// experiments visualisation: https://www.desmos.com/calculator/5crifaekwa
|
||||
// if (elevationDeg < 0) yf *= 1.0 - pow(xf, 0.333)
|
||||
// if (elevationDeg < 0) yf *= -2.0 * asin(xf - 1.0) / PI
|
||||
if (elevationDeg < 0) yf *= superellipsoidDecay(1.0 / 3.0, xf)
|
||||
val theta = yf.mapCircle() * HALF_PI
|
||||
val theta = (yf.mapCircle() * HALF_PI)
|
||||
// vertical angle, where 0 is zenith, ±90 is ground (which is odd)
|
||||
|
||||
val xyz = CIEXYZ(
|
||||
@@ -142,8 +163,9 @@ object Skybox : Disposable {
|
||||
val xyz2 = xyz.scaleToFit(elevationDeg)
|
||||
val rgb = xyz2.toRGB().toColor()
|
||||
|
||||
// pixmap.setColor(if (yp in 17 until 17 + 94) Color.LIME else Color.CORAL)
|
||||
pixmap.setColor(rgb)
|
||||
pixmap.drawPixel(0, y)
|
||||
pixmap.drawPixel(0, yp)
|
||||
}
|
||||
|
||||
val texture = Texture(pixmap).also {
|
||||
|
||||
@@ -208,7 +208,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
App.fontSmallNumbers.draw(batch, "$SOL $soldegCol$soldegStr", gap + 7f*(sol), line(mvY))
|
||||
App.fontSmallNumbers.draw(batch, "$TAU $turbCol$turbidity", gap + 7f*(sol), line(mvY + 1))
|
||||
|
||||
|
||||
App.fontSmallNumbers.draw(batch, "${ccG}p ${WeatherMixer.parallaxPos.toDouble().toIntAndFrac(1,2)}", gap + 7f*51, line(mvY))
|
||||
|
||||
try {
|
||||
world?.let {
|
||||
|
||||
@@ -152,7 +152,9 @@ internal object WeatherMixer : RNGConsumer {
|
||||
}
|
||||
|
||||
var turbidity = 4.0; private set
|
||||
private var gH = 1.5f * App.scr.height
|
||||
private var gH = (4f/3f) * App.scr.height
|
||||
|
||||
internal var parallaxPos = 0f; private set
|
||||
|
||||
private val HALF_DAY = DAY_LENGTH / 2
|
||||
/**
|
||||
@@ -187,6 +189,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
-+ <- 0.0 =
|
||||
*/
|
||||
val parallax = ((parallaxZeroPos - WorldCamera.gdxCamY.div(TILE_SIZEF)) / parallaxDomainSize).times(-1f).coerceIn(-1f, 1f)
|
||||
parallaxPos = parallax
|
||||
// println(parallax) // parallax value works as intended.
|
||||
|
||||
gdxBlendNormalStraightAlpha()
|
||||
|
||||
Reference in New Issue
Block a user