mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
light whitewash impl
This commit is contained in:
@@ -18,6 +18,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
|||||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||||
import net.torvald.terrarum.modulebasegame.ui.abs
|
import net.torvald.terrarum.modulebasegame.ui.abs
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
|
import kotlin.math.roundToInt
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -718,21 +719,40 @@ object LightmapRenderer {
|
|||||||
val arrayX = x.convX()
|
val arrayX = x.convX()
|
||||||
val arrayY = y.convY()
|
val arrayY = y.convY()
|
||||||
|
|
||||||
|
val red = lightmap.getR(arrayX, arrayY)
|
||||||
|
val grn = lightmap.getG(arrayX, arrayY)
|
||||||
|
val blu = lightmap.getB(arrayX, arrayY)
|
||||||
|
val redw = (red - 1f) * (7f / 24f)
|
||||||
|
val grnw = (grn - 1f)
|
||||||
|
val bluw = (blu - 1f) * (7f / 72f)
|
||||||
|
|
||||||
val color = if (solidMultMagic == null)
|
val color = if (solidMultMagic == null)
|
||||||
gdxColorNull
|
lightBuffer.drawPixel(
|
||||||
|
x - this_x_start,
|
||||||
|
lightBuffer.height - 1 - y + this_y_start,
|
||||||
|
0
|
||||||
|
) // flip Y
|
||||||
else
|
else
|
||||||
Color(
|
lightBuffer.drawPixel(
|
||||||
lightmap.getR(arrayX, arrayY) * solidMultMagic,
|
x - this_x_start,
|
||||||
lightmap.getG(arrayX, arrayY) * solidMultMagic,
|
lightBuffer.height - 1 - y + this_y_start,
|
||||||
lightmap.getB(arrayX, arrayY) * solidMultMagic,
|
(maxOf(red, grnw, bluw) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(24) or
|
||||||
|
(maxOf(redw, grn, bluw) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(16) or
|
||||||
|
(maxOf(redw, grnw, blu) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
||||||
|
(lightmap.getA(arrayX, arrayY) * solidMultMagic).hdnorm().times(255f).roundToInt()
|
||||||
|
) // flip Y
|
||||||
|
|
||||||
|
|
||||||
|
/*Color(
|
||||||
|
maxOf(red, grnw, bluw) * solidMultMagic,
|
||||||
|
maxOf(redw, grn, bluw) * solidMultMagic,
|
||||||
|
maxOf(redw, grnw, blu) * solidMultMagic,
|
||||||
lightmap.getA(arrayX, arrayY) * solidMultMagic
|
lightmap.getA(arrayX, arrayY) * solidMultMagic
|
||||||
).normaliseToHDR()
|
).normaliseToHDR()
|
||||||
|
|
||||||
lightBuffer.setColor(color)
|
lightBuffer.setColor(color)*/
|
||||||
|
|
||||||
//lightBuffer.drawPixel(x - this_x_start, y - this_y_start)
|
|
||||||
|
|
||||||
lightBuffer.drawPixel(x - this_x_start, lightBuffer.height - 1 - y + this_y_start) // flip Y
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -807,7 +827,7 @@ object LightmapRenderer {
|
|||||||
// TODO: float LUT lookup using linear interpolation
|
// TODO: float LUT lookup using linear interpolation
|
||||||
|
|
||||||
// input: 0..1 for int 0..1023
|
// input: 0..1 for int 0..1023
|
||||||
private fun hdr(intensity: Float): Float {
|
fun hdr(intensity: Float): Float {
|
||||||
val intervalStart = (intensity * CHANNEL_MAX).floorInt()
|
val intervalStart = (intensity * CHANNEL_MAX).floorInt()
|
||||||
val intervalEnd = (intensity * CHANNEL_MAX).floorInt() + 1
|
val intervalEnd = (intensity * CHANNEL_MAX).floorInt() + 1
|
||||||
|
|
||||||
@@ -866,6 +886,8 @@ object LightmapRenderer {
|
|||||||
hdr(this.a.coerceIn(0f, 1f))
|
hdr(this.a.coerceIn(0f, 1f))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
inline fun Float.hdnorm() = hdr(this.coerceIn(0f, 1f))
|
||||||
|
|
||||||
private fun Cvec.nonZero() = this.r.abs() > epsilon ||
|
private fun Cvec.nonZero() = this.r.abs() > epsilon ||
|
||||||
this.g.abs() > epsilon ||
|
this.g.abs() > epsilon ||
|
||||||
this.b.abs() > epsilon ||
|
this.b.abs() > epsilon ||
|
||||||
|
|||||||
Reference in New Issue
Block a user