mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
better smooth-linear function
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.clut
|
package net.torvald.terrarum.modulebasegame.clut
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import com.badlogic.gdx.graphics.Pixmap
|
import com.badlogic.gdx.graphics.Pixmap
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
@@ -13,7 +12,6 @@ import net.torvald.terrarum.App
|
|||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.abs
|
import net.torvald.terrarum.abs
|
||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.HALF_PI
|
import net.torvald.terrarum.modulebasegame.worldgenerator.HALF_PI
|
||||||
import java.lang.Math.pow
|
|
||||||
import kotlin.math.*
|
import kotlin.math.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,7 +126,23 @@ object Skybox : Disposable {
|
|||||||
private fun Double.coerceInSmoothly(low: Double, high: Double): Double {
|
private fun Double.coerceInSmoothly(low: Double, high: Double): Double {
|
||||||
val x = this.coerceIn(low, high)
|
val x = this.coerceIn(low, high)
|
||||||
val x2 = ((x - low) * (high - low).pow(-1.0))
|
val x2 = ((x - low) * (high - low).pow(-1.0))
|
||||||
return FastMath.interpolateLinear(polynomialDecay2(0.5, 2, x2), low, high)
|
// return FastMath.interpolateLinear(polynomialDecay2(0.5, 2, x2), low, high)
|
||||||
|
return FastMath.interpolateLinear(smoothLinear(x2), low, high)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the idea what the fuck is going on here, please refer to https://www.desmos.com/calculator/d2otu5deub
|
||||||
|
*/
|
||||||
|
private fun smoothLinear(x: Double): Double {
|
||||||
|
val k = 0.11269 // a magic number
|
||||||
|
val d = 1.127016653 // also a magic number
|
||||||
|
val a = -1.0 / 0.2
|
||||||
|
return if (x < k)
|
||||||
|
-a.pow(1) * x.pow(2)
|
||||||
|
else if (x > 1.0 - k)
|
||||||
|
a.pow(1) * (1.0 - x).pow(2) + 1.0
|
||||||
|
else
|
||||||
|
d * (x - 0.5) + 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTexturmaps(albedo: Double): Array<Texture> {
|
private fun getTexturmaps(albedo: Double): Array<Texture> {
|
||||||
|
|||||||
Reference in New Issue
Block a user