mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 08:36:07 +09:00
much more elegant solution than stretching texture using batch
This commit is contained in:
@@ -936,7 +936,7 @@ public class App implements ApplicationListener {
|
||||
|
||||
shaderHicolour = loadShaderFromClasspath("shaders/default.vert", "shaders/hicolour.frag");
|
||||
shaderDebugDiff = loadShaderFromClasspath("shaders/default.vert", "shaders/diff.frag");
|
||||
shaderColLUT = loadShaderFromClasspath("shaders/default.vert", "shaders/passthrurgb.frag");
|
||||
shaderColLUT = loadShaderFromClasspath("shaders/default.vert", "shaders/rgbonly.frag");
|
||||
shaderGhastlyWhite = loadShaderFromClasspath("shaders/default.vert", "shaders/ghastlywhite.frag");
|
||||
|
||||
// make gamepad(s)
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import com.jme3.math.FastMath
|
||||
import com.jme3.math.Vector2f
|
||||
import net.torvald.colourutil.CIEXYZ
|
||||
import net.torvald.colourutil.toColor
|
||||
import net.torvald.colourutil.toRGB
|
||||
@@ -55,12 +56,25 @@ object Skybox : Disposable {
|
||||
return texRegions.get(alb * elevCnt + elev, turb)
|
||||
}
|
||||
|
||||
fun getStrip(turbidity: Double, albedo: Double): TextureRegion {
|
||||
fun getUV(elevationDeg: Double, turbidity: Double, albedo: Double): Pair<Texture, FloatArray> {
|
||||
val turb = turbidity.coerceIn(1.0, 10.0).minus(1.0).times(3.0).roundToInt()
|
||||
val alb = albedo.coerceIn(0.1, 0.9).minus(0.1).times(5.0).roundToInt()
|
||||
return texStripRegions.get(alb, turb)
|
||||
val region = texStripRegions.get(alb, turb)
|
||||
|
||||
val elev = elevationDeg.coerceIn(-75.0, 75.0).plus(75.0).div(150.0)
|
||||
|
||||
val u = region.u + (elev / albedoCnt).toFloat()
|
||||
|
||||
return tex to floatArrayOf(
|
||||
u,
|
||||
region.v,
|
||||
u,
|
||||
region.v2
|
||||
)
|
||||
}
|
||||
|
||||
private val texcoordEpsilon = 1f / 131072f
|
||||
|
||||
private fun Float.scaleFun() =
|
||||
(1f - 1f / 2f.pow(this/6f)) * 0.97f
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.torvald.terrarum.weather
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.random.HQRNG
|
||||
@@ -13,6 +15,7 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.gameworld.WorldTime.Companion.DAY_LENGTH
|
||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||
import net.torvald.terrarum.modulebasegame.RNGConsumer
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.clut.Skybox
|
||||
@@ -22,6 +25,10 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
|
||||
/**
|
||||
* Currently there is a debate whether this module must be part of the engine or the basegame
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -38,8 +45,6 @@ internal object WeatherMixer : RNGConsumer {
|
||||
|
||||
override val RNG = HQRNG()
|
||||
|
||||
private val renderng = HQRNG()
|
||||
|
||||
var globalLightOverridden = false
|
||||
|
||||
var weatherList: HashMap<String, ArrayList<BaseModularWeather>>
|
||||
@@ -62,6 +67,10 @@ internal object WeatherMixer : RNGConsumer {
|
||||
var forceSolarElev: Double? = null
|
||||
var forceTurbidity: Double? = null
|
||||
|
||||
val starmapTex: TextureRegion = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "weathers/astrum.png")))
|
||||
|
||||
private val shaderBlendMax = App.loadShaderFromClasspath("shaders/blendMax.vert", "shaders/blendMax.frag")
|
||||
|
||||
override fun loadFromSave(s0: Long, s1: Long) {
|
||||
super.loadFromSave(s0, s1)
|
||||
internalReset()
|
||||
@@ -162,6 +171,10 @@ internal object WeatherMixer : RNGConsumer {
|
||||
* Sub-portion of IngameRenderer. You are not supposed to directly deal with this.
|
||||
*/
|
||||
internal fun render(camera: Camera, batch: FlippingSpriteBatch, world: GameWorld) {
|
||||
drawSkybox(camera, batch, world)
|
||||
}
|
||||
|
||||
private fun drawSkybox(camera: Camera, batch: FlippingSpriteBatch, world: GameWorld) {
|
||||
val parallaxZeroPos = (world.height / 3f)
|
||||
val parallaxDomainSize = 300f
|
||||
|
||||
@@ -198,24 +211,16 @@ internal object WeatherMixer : RNGConsumer {
|
||||
val thisTurbidity = forceTurbidity ?: turbidity
|
||||
|
||||
// TODO trilinear with (deg, turb, alb)
|
||||
val texture1 = Skybox.getStrip(thisTurbidity, 0.3)
|
||||
|
||||
// println("degThis=$degThis, degNext=$degNext, lerp=$lerpScale")
|
||||
|
||||
val stripXcentre = ((solarElev + 75.0) / 150.0).toFloat()
|
||||
val backMag = 16777216f
|
||||
val backX = -stripXcentre * backMag
|
||||
|
||||
val gradY = -(gH - App.scr.height) * ((parallax + 1f) / 2f)
|
||||
val (tex, uvs) = Skybox.getUV(solarElev, thisTurbidity, 0.3)
|
||||
|
||||
batch.inUse {
|
||||
batch.shader = null
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(texture1, backX, gradY, backMag + App.scr.wf, gH)
|
||||
batch.draw(tex, 0f, gradY, App.scr.wf, gH, uvs[0], uvs[1], uvs[2], uvs[3])
|
||||
|
||||
batch.color = Color.WHITE
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private operator fun Color.times(other: Color) = Color(this.r * other.r, this.g * other.g, this.b * other.b, 1f)
|
||||
@@ -300,7 +305,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
|
||||
fun getWeatherList(classification: String) = weatherList[classification]!!
|
||||
fun getRandomWeather(classification: String) =
|
||||
getWeatherList(classification)[HQRNG().nextInt(getWeatherList(classification).size)]
|
||||
getWeatherList(classification)[RNG.nextInt(getWeatherList(classification).size)]
|
||||
|
||||
fun readFromJson(file: File): BaseModularWeather = readFromJson(file.path)
|
||||
|
||||
@@ -360,6 +365,12 @@ internal object WeatherMixer : RNGConsumer {
|
||||
}
|
||||
|
||||
fun dispose() {
|
||||
|
||||
weatherList.values.forEach { list ->
|
||||
list.forEach { weather ->
|
||||
weather.extraImages.forEach { it.tryDispose() }
|
||||
}
|
||||
}
|
||||
starmapTex.texture.dispose()
|
||||
shaderBlendMax.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user