mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
light: seems like the problem is the ram access time
This commit is contained in:
@@ -491,6 +491,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
/** RENDER CODE GOES HERE */
|
/** RENDER CODE GOES HERE */
|
||||||
//renderGame(batch)
|
//renderGame(batch)
|
||||||
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
||||||
|
AppLoader.debugTimers["Ingame.render-Light"] =
|
||||||
|
(AppLoader.debugTimers["Ingame.render"] as Long) - ((AppLoader.debugTimers["Renderer.LightSequential"] as? Long) ?: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun updateGame(delta: Float) {
|
protected fun updateGame(delta: Float) {
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ object LightmapRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// O((5*9)n) == O(n) where n is a size of the map.
|
// O((5*9)n) == O(n) where n is a size of the map.
|
||||||
// Because of inevitable overlaps on the area, it only works with ADDITIVE blend (aka maxblend)
|
// Because of inevitable overlaps on the area, it only works with MAX blend
|
||||||
|
|
||||||
|
|
||||||
// each usually takes 8 000 000..12 000 000 miliseconds total when not threaded
|
// each usually takes 8 000 000..12 000 000 miliseconds total when not threaded
|
||||||
@@ -415,33 +415,33 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private val ambientAccumulator = Color(0f,0f,0f,0f)
|
//private val ambientAccumulator = Color(0f,0f,0f,0f)
|
||||||
private val lightLevelThis = Color(0f,0f,0f,0f)
|
private val lightLevelThis = Color(0f,0f,0f,0f)
|
||||||
private var thisTerrain = 0
|
private var thisTerrain = 0
|
||||||
private var thisWall = 0
|
private var thisWall = 0
|
||||||
private val thisTileLuminosity = Color(0f,0f,0f,0f)
|
private val thisTileLuminosity = Color(0f,0f,0f,0f)
|
||||||
private val thisTileOpacity = Color(0f,0f,0f,0f)
|
private val thisTileOpacity = Color(0f,0f,0f,0f)
|
||||||
|
private val thisTileOpacity2 = Color(0f,0f,0f,0f) // thisTileOpacity * sqrt(2)
|
||||||
private val sunLight = Color(0f,0f,0f,0f)
|
private val sunLight = Color(0f,0f,0f,0f)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the light simulation, using main lightmap as one of the input.
|
* Calculates the light simulation, using main lightmap as one of the input.
|
||||||
*
|
|
||||||
* @param pass one-based
|
|
||||||
*/
|
*/
|
||||||
private fun calculate(x: Int, y: Int): Color {
|
private fun calculate(x: Int, y: Int): Color {
|
||||||
|
|
||||||
// O(9n) == O(n) where n is a size of the map
|
// O(9n) == O(n) where n is a size of the map
|
||||||
// TODO devise multithreading on this
|
// TODO devise multithreading on this
|
||||||
|
|
||||||
ambientAccumulator.set(0f,0f,0f,0f)
|
//ambientAccumulator.set(0f,0f,0f,0f)
|
||||||
|
|
||||||
// this six fetch tasks take 2 ms ?!
|
// this six fetch tasks take 2 ms ?!
|
||||||
lightLevelThis.set(0f,0f,0f,0f)
|
lightLevelThis.set(colourNull)
|
||||||
thisTerrain = world.getTileFromTerrain(x, y) ?: Block.STONE
|
thisTerrain = world.getTileFromTerrain(x, y) ?: Block.STONE
|
||||||
thisWall = world.getTileFromWall(x, y) ?: Block.STONE
|
thisWall = world.getTileFromWall(x, y) ?: Block.STONE
|
||||||
thisTileLuminosity.set(BlockCodex[thisTerrain].luminosity) // already been div by four
|
thisTileLuminosity.set(BlockCodex[thisTerrain].luminosity) // already been div by four
|
||||||
thisTileOpacity.set(BlockCodex[thisTerrain].opacity) // already been div by four
|
thisTileOpacity.set(BlockCodex[thisTerrain].opacity) // already been div by four
|
||||||
|
thisTileOpacity2.set(thisTileOpacity); thisTileOpacity2.mul(1.41421356f)
|
||||||
sunLight.set(world.globalLight); sunLight.mul(DIV_FLOAT)
|
sunLight.set(world.globalLight); sunLight.mul(DIV_FLOAT)
|
||||||
|
|
||||||
|
|
||||||
@@ -465,26 +465,31 @@ object LightmapRenderer {
|
|||||||
lightLevelThis maxBlend (lanternMap[Point2i(x, y)] ?: colourNull)
|
lightLevelThis maxBlend (lanternMap[Point2i(x, y)] ?: colourNull)
|
||||||
|
|
||||||
// calculate ambient
|
// calculate ambient
|
||||||
/* + * +
|
/* + * + 0 4 1
|
||||||
* * @ *
|
* * @ * 6 @ 7
|
||||||
* + * +
|
* + * + 2 5 3
|
||||||
* sample ambient for eight points and apply attenuation for those
|
* sample ambient for eight points and apply attenuation for those
|
||||||
* maxblend eight values and use it
|
* maxblend eight values and use it
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// will "overwrite" what's there in the lightmap if it's the first pass
|
// will "overwrite" what's there in the lightmap if it's the first pass
|
||||||
// takes about 2 ms
|
// takes about 2 ms on 6700K
|
||||||
/* + */ambientAccumulator.set(ambientAccumulator maxBlend darkenColoured(getLightInternal(x - 1, y - 1) ?: colourNull, scaleSqrt2(thisTileOpacity)))
|
val amb = Array(8) {
|
||||||
/* + */ambientAccumulator.set(ambientAccumulator maxBlend darkenColoured(getLightInternal(x + 1, y - 1) ?: colourNull, scaleSqrt2(thisTileOpacity)))
|
when (it) {
|
||||||
/* + */ambientAccumulator.set(ambientAccumulator maxBlend darkenColoured(getLightInternal(x - 1, y + 1) ?: colourNull, scaleSqrt2(thisTileOpacity)))
|
/* + */0 -> darkenColoured(getLightInternal(x - 1, y - 1) ?: colourNull, thisTileOpacity2)
|
||||||
/* + */ambientAccumulator.set(ambientAccumulator maxBlend darkenColoured(getLightInternal(x + 1, y + 1) ?: colourNull, scaleSqrt2(thisTileOpacity)))
|
/* + */1 -> darkenColoured(getLightInternal(x + 1, y - 1) ?: colourNull, thisTileOpacity2)
|
||||||
|
/* + */2 -> darkenColoured(getLightInternal(x - 1, y + 1) ?: colourNull, thisTileOpacity2)
|
||||||
|
/* + */3 -> darkenColoured(getLightInternal(x + 1, y + 1) ?: colourNull, thisTileOpacity2)
|
||||||
|
|
||||||
/* * */ambientAccumulator.set(ambientAccumulator maxBlend darkenColoured(getLightInternal(x, y - 1) ?: colourNull, thisTileOpacity))
|
/* * */4 -> darkenColoured(getLightInternal(x, y - 1) ?: colourNull, thisTileOpacity)
|
||||||
/* * */ambientAccumulator.set(ambientAccumulator maxBlend darkenColoured(getLightInternal(x, y + 1) ?: colourNull, thisTileOpacity))
|
/* * */5 -> darkenColoured(getLightInternal(x, y + 1) ?: colourNull, thisTileOpacity)
|
||||||
/* * */ambientAccumulator.set(ambientAccumulator maxBlend darkenColoured(getLightInternal(x - 1, y) ?: colourNull, thisTileOpacity))
|
/* * */6 -> darkenColoured(getLightInternal(x - 1, y) ?: colourNull, thisTileOpacity)
|
||||||
/* * */ambientAccumulator.set(ambientAccumulator maxBlend darkenColoured(getLightInternal(x + 1, y) ?: colourNull, thisTileOpacity))
|
/* * */7 -> darkenColoured(getLightInternal(x + 1, y) ?: colourNull, thisTileOpacity)
|
||||||
|
else -> throw InternalError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val ret = lightLevelThis maxBlend ambientAccumulator
|
val ret = amb.fold(lightLevelThis) { acc, color -> acc maxBlend color }
|
||||||
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
@@ -514,6 +519,7 @@ object LightmapRenderer {
|
|||||||
var lightBuffer: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888)
|
var lightBuffer: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
private val colourNull = Color(0)
|
private val colourNull = Color(0)
|
||||||
|
private val epsilon = 1f/2048f
|
||||||
|
|
||||||
private var _lightBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
|
private var _lightBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
@@ -862,7 +868,7 @@ object LightmapRenderer {
|
|||||||
hdr(this.a)
|
hdr(this.a)
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun Color.nonZero() = this.r != 0f || this.g != 0f || this.b != 0f || this.a != 0f
|
private fun Color.nonZero() = this.r >= epsilon || this.g >= epsilon || this.b >= epsilon || this.a >= epsilon
|
||||||
|
|
||||||
val histogram: Histogram
|
val histogram: Histogram
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
Reference in New Issue
Block a user