diff --git a/assets/mods/basegame/weathers/main_skybox.png b/assets/mods/basegame/weathers/main_skybox.png new file mode 100644 index 000000000..7f2e81e21 --- /dev/null +++ b/assets/mods/basegame/weathers/main_skybox.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee25e84e63f8ad63e8b3b1bd1005bb259220da8f068d22cb7e60c775ded9e565 +size 492946 diff --git a/src/net/torvald/terrarum/modulebasegame/clut/GenerateSkyboxTextureAtlas.kt b/src/net/torvald/terrarum/modulebasegame/clut/GenerateSkyboxTextureAtlas.kt index 0c8104edd..34397e5df 100644 --- a/src/net/torvald/terrarum/modulebasegame/clut/GenerateSkyboxTextureAtlas.kt +++ b/src/net/torvald/terrarum/modulebasegame/clut/GenerateSkyboxTextureAtlas.kt @@ -22,7 +22,7 @@ fun main() { // y: increasing turbidity (1.0 .. 10.0, in steps of 0.333) // x: elevations (-75 .. 75 in steps of 1, then albedo of [0.1, 0.3, 0.5, 0.7, 0.9]) val texh = Skybox.gradSize * Skybox.turbCnt - val texw = 2 * Skybox.elevCnt * 5 + val texw = Skybox.elevCnt * Skybox.albedoCnt val TGA_HEADER_SIZE = 18 val bytes = ByteArray(TGA_HEADER_SIZE + texw * texh * 4 + 26) @@ -83,10 +83,10 @@ fun main() { val rgb = xyz2.toRGB().toColor() val colour = rgb.toIntBits().toLittle() - val imgOffX = 2 * (albedo0 * Skybox.elevCnt + elev0) + val imgOffX = (albedo0 * Skybox.elevCnt + elev0) val imgOffY = texh - 1 - (Skybox.gradSize * turb0 + yp) val fileOffset = TGA_HEADER_SIZE + 4 * (imgOffY * texw + imgOffX) - for (i in 0..7) { + for (i in 0..3) { bytes[fileOffset + i] = colour[bytesLut[i]] } } diff --git a/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt b/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt index 28436404a..e5eb0ec74 100644 --- a/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt +++ b/src/net/torvald/terrarum/modulebasegame/clut/Skybox.kt @@ -29,11 +29,13 @@ object Skybox : Disposable { private lateinit var tex: Texture private lateinit var texRegions: TextureRegionPack + private lateinit var texStripRegions: TextureRegionPack fun loadlut() { tex = Texture(ModMgr.getGdxFile("basegame", "weathers/main_skybox.png")) tex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) texRegions = TextureRegionPack(tex, 2, gradSize - 2, 0, 2, 0, 1) + texStripRegions = TextureRegionPack(tex, elevCnt - 2, gradSize - 2, 2, 2, 1, 1) } // use internal LUT @@ -47,12 +49,18 @@ object Skybox : Disposable { // use external LUT operator fun get(elevationDeg: Double, turbidity: Double, albedo: Double): TextureRegion { val elev = elevationDeg.coerceIn(-75.0, 75.0).roundToInt().plus(75) - val turb = turbidity.coerceIn(1.0, 10.0).minus(1.0).times(3.0).roundToInt() + val turb = turbidity.coerceIn(1.0, 10.0).minus(1.0).times(5.0).roundToInt() val alb = albedo.coerceIn(0.1, 0.9).minus(0.1).times(5.0).roundToInt() //printdbg(this, "elev $elevationDeg->$elev; turb $turbidity->$turb; alb $albedo->$alb") return texRegions.get(alb * elevCnt + elev, turb) } + fun getStrip(turbidity: Double, albedo: Double): TextureRegion { + 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) + } + private fun Float.scaleFun() = (1f - 1f / 2f.pow(this/6f)) * 0.97f @@ -82,8 +90,8 @@ object Skybox : Disposable { val elevations = (0..150) // val elevationsD = elevations.map { -75.0 + it } // -75, -74, -73, ..., 74, 75 // (specifically using whole number of angles because angle units any finer than 1.0 would make "hack" sunsut happen too fast) - val turbidities = (0..27) // 1, 1.333, 1.666, 2, 2,333, ... , 10.0 - val turbiditiesD = turbidities.map { 1.0 + it / 3.0 } + val turbidities = (0..45) // 1, 1.2, 1.4, 1.6, ..., 10.0 + val turbiditiesD = turbidities.map { 1.0 + it / 5.0 } val albedos = arrayOf(0.1, 0.3, 0.5, 0.7, 0.9) val elevCnt = elevations.count() val turbCnt = turbidities.count() diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index 33df34a6d..0763a033d 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -195,29 +195,22 @@ internal object WeatherMixer : RNGConsumer { gdxBlendNormalStraightAlpha() - val degThis = if (timeNow < HALF_DAY) - solarElev.floorToDouble() - else - solarElev.ceilToDouble() - val degNext = degThis + if (timeNow < HALF_DAY) 1 else -1 // Skybox.get has internal coerceIn - val thisTurbidity = forceTurbidity ?: turbidity // TODO trilinear with (deg, turb, alb) - val texture1 = Skybox[degThis, thisTurbidity, 0.1] - val texture2 = Skybox[degNext, thisTurbidity, 0.1] - val lerpScale = (if (timeNow < HALF_DAY) solarElev - degThis else -(solarElev - degThis)).toFloat() + val texture1 = Skybox.getStrip(thisTurbidity, 0.3) // println("degThis=$degThis, degNext=$degNext, lerp=$lerpScale") + val stripXcentre = ((solarElev + 75.0) / 150.0).toFloat() + val backMag = texture1.regionWidth * App.scr.wf * 2f + val backX = -stripXcentre * backMag + val gradY = -(gH - App.scr.height) * ((parallax + 1f) / 2f) batch.inUse { batch.shader = null batch.color = Color.WHITE - batch.draw(texture1, -App.scr.halfwf, gradY, 2f * App.scr.wf, gH) - - batch.color = Color(1f, 1f, 1f, lerpScale) - batch.draw(texture2, -App.scr.halfwf, gradY, 2f * App.scr.wf, gH) + batch.draw(texture1, backX, gradY, backMag + App.scr.wf, gH) batch.color = Color.WHITE }