From a6685df5d16bfba10be595b9b54eede5d6b841ca Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 5 Oct 2022 23:26:46 +0900 Subject: [PATCH] experimental new lighting can be toggled with config "fx_newlight" --- src/net/torvald/terrarum/DefaultConfig.kt | 2 + .../terrarum/worlddrawer/LightmapRenderer.kt | 63 +++++++++++-------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt index b5d1f28c8..f8f28a5fa 100644 --- a/src/net/torvald/terrarum/DefaultConfig.kt +++ b/src/net/torvald/terrarum/DefaultConfig.kt @@ -110,6 +110,8 @@ object DefaultConfig { "screenmagnifying" to 1.0, + "fx_newlight" to true, + // settings regarding debugger diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt index dad9cf2e5..25471b61d 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt @@ -326,7 +326,11 @@ object LightmapRenderer { // why dark spots appear in the first place) // - Multithreading? I have absolutely no idea. // - If you naively slice the screen (job area) to multithread, the seam will appear. - r1(lightmap);r2(lightmap);//r3(lightmap);r4(lightmap) + r1(lightmap);r2(lightmap); + + if (!App.getConfigBoolean("fx_newlight")) { + r3(lightmap);r4(lightmap) + } } App.measureDebugTime("Renderer.Precalculate2") { @@ -338,10 +342,13 @@ object LightmapRenderer { } } - /*App.measureDebugTime("Renderer.LightRuns2") { - r1(lightmap);r2(lightmap);r3(lightmap);r4(lightmap) // two looks better than one + App.measureDebugTime("Renderer.LightRuns2") { + r1(lightmap);r2(lightmap); + if (!App.getConfigBoolean("fx_newlight")) { + r3(lightmap);r4(lightmap) // two looks better than one + } // no rendering trickery will eliminate the need of 2nd pass, even the "decay out" - }*/ + } } private fun buildLanternAndShadowMap(actorContainer: List) { @@ -580,7 +587,7 @@ object LightmapRenderer { } private fun swipeLight(sx: Int, sy: Int, ex: Int, ey: Int, dx: Int, dy: Int, lightmap: UnsafeCvecArray) { swipeX = sx; swipeY = sy - distFromLightSrc.broadcast(0) + if (App.getConfigBoolean("fx_newlight")) distFromLightSrc.broadcast(0) while (swipeX*dx <= ex*dx && swipeY*dy <= ey*dy) { // conduct the task #1 // spread towards the end @@ -590,16 +597,18 @@ object LightmapRenderer { swipeX += dx swipeY += dy - distFromLightSrc.add(1) + if (App.getConfigBoolean("fx_newlight")) { + distFromLightSrc.add(1) - if (_mapLightLevelThis.getR(swipeX - dx, swipeY - dy) <= _mapLightLevelThis.getR(swipeX, swipeY)) distFromLightSrc.r = 0 - if (_mapLightLevelThis.getG(swipeX - dx, swipeY - dy) <= _mapLightLevelThis.getG(swipeX, swipeY)) distFromLightSrc.g = 0 - if (_mapLightLevelThis.getB(swipeX - dx, swipeY - dy) <= _mapLightLevelThis.getB(swipeX, swipeY)) distFromLightSrc.b = 0 - if (_mapLightLevelThis.getA(swipeX - dx, swipeY - dy) <= _mapLightLevelThis.getA(swipeX, swipeY)) distFromLightSrc.a = 0 + if (_mapLightLevelThis.getR(swipeX - dx, swipeY - dy) <= _mapLightLevelThis.getR(swipeX, swipeY)) distFromLightSrc.r = 0 + if (_mapLightLevelThis.getG(swipeX - dx, swipeY - dy) <= _mapLightLevelThis.getG(swipeX, swipeY)) distFromLightSrc.g = 0 + if (_mapLightLevelThis.getB(swipeX - dx, swipeY - dy) <= _mapLightLevelThis.getB(swipeX, swipeY)) distFromLightSrc.b = 0 + if (_mapLightLevelThis.getA(swipeX - dx, swipeY - dy) <= _mapLightLevelThis.getA(swipeX, swipeY)) distFromLightSrc.a = 0 + } } swipeX = ex; swipeY = ey - distFromLightSrc.broadcast(0) + if (App.getConfigBoolean("fx_newlight")) distFromLightSrc.broadcast(0) while (swipeX*dx >= sx*dx && swipeY*dy >= sy*dy) { // conduct the task #2 // spread towards the start @@ -608,12 +617,14 @@ object LightmapRenderer { swipeX -= dx swipeY -= dy - distFromLightSrc.add(1) + if (App.getConfigBoolean("fx_newlight")) { + distFromLightSrc.add(1) - if (_mapLightLevelThis.getR(swipeX + dx, swipeY + dy) <= _mapLightLevelThis.getR(swipeX, swipeY)) distFromLightSrc.r = 0 - if (_mapLightLevelThis.getG(swipeX + dx, swipeY + dy) <= _mapLightLevelThis.getG(swipeX, swipeY)) distFromLightSrc.g = 0 - if (_mapLightLevelThis.getB(swipeX + dx, swipeY + dy) <= _mapLightLevelThis.getB(swipeX, swipeY)) distFromLightSrc.b = 0 - if (_mapLightLevelThis.getA(swipeX + dx, swipeY + dy) <= _mapLightLevelThis.getA(swipeX, swipeY)) distFromLightSrc.a = 0 + if (_mapLightLevelThis.getR(swipeX + dx, swipeY + dy) <= _mapLightLevelThis.getR(swipeX, swipeY)) distFromLightSrc.r = 0 + if (_mapLightLevelThis.getG(swipeX + dx, swipeY + dy) <= _mapLightLevelThis.getG(swipeX, swipeY)) distFromLightSrc.g = 0 + if (_mapLightLevelThis.getB(swipeX + dx, swipeY + dy) <= _mapLightLevelThis.getB(swipeX, swipeY)) distFromLightSrc.b = 0 + if (_mapLightLevelThis.getA(swipeX + dx, swipeY + dy) <= _mapLightLevelThis.getA(swipeX, swipeY)) distFromLightSrc.a = 0 + } } } @@ -789,18 +800,20 @@ object LightmapRenderer { if (x !in 0 until LIGHTMAP_WIDTH || y !in 0 until LIGHTMAP_HEIGHT) return colourNull - /*return lightmap.getVec(x, y).lanewise { it, ch -> - it * (1f - darken.lane(ch) * lightScalingMagic) - }*/ + if (App.getConfigBoolean("fx_newlight")) { + val newDarken: Cvec = darken.lanewise { it, ch -> + darkenConv(1f - it * lightScalingMagic) + } - val newDarken: Cvec = darken.lanewise { it, ch -> - darkenConv(1f - it * lightScalingMagic) + return lightmap.getVec(x, y).lanewise { it, ch -> + (it * ((newDarken.lane(ch) - distFromLightSrc.lane(ch)) / newDarken.lane(ch))).coerceAtLeast(0f) + } } - - return lightmap.getVec(x, y).lanewise { it, ch -> - (it * ((newDarken.lane(ch) - distFromLightSrc.lane(ch)) / newDarken.lane(ch))).coerceAtLeast(0f) + else { + return lightmap.getVec(x, y).lanewise { it, ch -> + it * (1f - darken.lane(ch) * lightScalingMagic) + } } - } /** infix is removed to clarify the association direction */