diff --git a/assets/graphics/blocks/init.tga b/assets/graphics/blocks/init.tga index 0bce37c20..70eca8f57 100644 --- a/assets/graphics/blocks/init.tga +++ b/assets/graphics/blocks/init.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c931ae5000269636172b2413fa38d1db04f303bda324fadd372e3127261368e1 +oid sha256:ee4adf16c852def2979824c8888a83925ee859b314a40f5c139b48a321fb74fa size 67602 diff --git a/assets/mods/basegame/blocks/16.tga b/assets/mods/basegame/blocks/16.tga index 40fa4385a..1d11835f4 100644 --- a/assets/mods/basegame/blocks/16.tga +++ b/assets/mods/basegame/blocks/16.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:445bdf04fbb74c783d48f818129b46b55f842ea527a1601d41c840090ecf7e5f +oid sha256:bfb8139fd2ae8dc1f70ecdebd403d25051aa977bedaa051883a9f393d895da69 size 56594 diff --git a/assets/mods/basegame/blocks/17.tga b/assets/mods/basegame/blocks/17.tga index d3d7548d9..b5815b805 100644 --- a/assets/mods/basegame/blocks/17.tga +++ b/assets/mods/basegame/blocks/17.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0b41dfb388bb7b76bf5ce11868afcbe6c497d8e87a724a92880084edad9fc5ce +oid sha256:5df59b8e2c11e93f93684b96571ba54e8294ce1b7251a097e4583a1a0902ab4f size 56594 diff --git a/assets/mods/basegame/blocks/18.tga b/assets/mods/basegame/blocks/18.tga index 5da261529..c23beebef 100644 --- a/assets/mods/basegame/blocks/18.tga +++ b/assets/mods/basegame/blocks/18.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:36c4599bccc01c0b4ab011643bb5eafcb4684206b9217dc63a885a89dcd65a23 +oid sha256:bff1d9e16c37d0dc9042e39956ecd0a38d133e3b4701822d90086adf00d8a7ad size 56594 diff --git a/assets/mods/basegame/blocks/19.tga b/assets/mods/basegame/blocks/19.tga index 8d79e13fd..5ff5650bc 100644 --- a/assets/mods/basegame/blocks/19.tga +++ b/assets/mods/basegame/blocks/19.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9f1a39522d3ade95a5da93c2796cf167e6588c1797b5ea67739b904bd43e6703 +oid sha256:b194abbf3d8047a2749b88ac8c23015d349ab9413a4d57979b416feb63752ba1 size 56594 diff --git a/assets/mods/basegame/blocks/20.tga b/assets/mods/basegame/blocks/20.tga index a97a21569..f8563f8cd 100644 --- a/assets/mods/basegame/blocks/20.tga +++ b/assets/mods/basegame/blocks/20.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:42cd8ef30aea9524e4eeb930f6a6aba4ad14231a7b9a380699b91e64e802956f +oid sha256:25ce3c34bc15624618255881ea07ce1351c3fa7d2b71cdf9adeb47add15dea96 size 56594 diff --git a/assets/mods/basegame/blocks/21.tga b/assets/mods/basegame/blocks/21.tga index a646b4c15..89c8ef673 100755 --- a/assets/mods/basegame/blocks/21.tga +++ b/assets/mods/basegame/blocks/21.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8f6d8e8857e51a8dc298966aee7dbed3c1476336927b3e78984d40d0a6e8053b +oid sha256:1d6534442095ae33810582aaabdbe4db8215c8d6aa98e7f46481252437609915 size 56594 diff --git a/assets/mods/basegame/blocks/35.tga b/assets/mods/basegame/blocks/35.tga index bb82b205c..e3c6295b3 100644 --- a/assets/mods/basegame/blocks/35.tga +++ b/assets/mods/basegame/blocks/35.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:422e9e7043e48ee22e06df187f4f5d7499461008e265662f12eb89d012e152e5 +oid sha256:91290165dd65bfd28a1ef701104024369c39201881ceaaea89110371c0593f7f size 56594 diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 3d74bc85e..bee7e4783 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -277,7 +277,7 @@ object IngameRenderer : Disposable { if ((!gamePaused && !App.isScreenshotRequested()) || newWorldLoadedLatch) { measureDebugTime("Renderer.LightRun*") { - // recalculate for even frames, or if the sign of the cam-x changed + // recalculate for every three frame, or if the sign of the cam-x changed if (App.GLOBAL_RENDER_TIMER % 3 == 0L || Math.abs(WorldCamera.x - oldCamX) >= world.width * 0.85f * TILE_SIZEF || newWorldLoadedLatch) { LightmapRenderer.recalculate(actorsRenderFarBehind + actorsRenderBehind + actorsRenderFront + actorsRenderMidTop + actorsRenderMiddle + actorsRenderOverlay) } diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index c60b5efd1..998d83b84 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -75,7 +75,9 @@ internal object BlocksDrawer { val ORES = GameWorld.ORES val FLUID = -2 val OCCLUSION = 31337 - val BLURMAP = 31338 + val BLURMAP_BASE = 31338 + val BLURMAP_TERR = BLURMAP_BASE + TERRAIN + val BLURMAP_WALL = BLURMAP_BASE + WALL private const val OCCLUSION_TILE_NUM_BASE = 16 @@ -98,7 +100,8 @@ internal object BlocksDrawer { private lateinit var oreTilesBuffer: UnsafeLong2D // stores subtiles (dimension is doubled) private lateinit var fluidTilesBuffer: UnsafeLong2D // stores subtiles (dimension is doubled) private lateinit var occlusionBuffer: UnsafeLong2D // stores subtiles (dimension is doubled) - private lateinit var blurMap: UnsafeLong2D // stores subtiles (dimension is doubled) + private lateinit var blurMapTerr: UnsafeLong2D // stores subtiles (dimension is doubled) + private lateinit var blurMapWall: UnsafeLong2D // stores subtiles (dimension is doubled) private lateinit var tempRenderTypeBuffer: UnsafeLong2D // this one is NOT dimension doubled; 0x tttt 00 ii where t=rawTileNum, i=nearbyTilesInfo private var tilesBuffer: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888) private var tilesBuffer2: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888) @@ -257,8 +260,9 @@ internal object BlocksDrawer { } catch (e: ClassCastException) { } - if (!world.layerTerrain.ptrDestroyed) { - measureDebugTime("Renderer.Tiling") { + if (doTilemapUpdate) { + // rendering tilemap only updates every three frame + measureDebugTime("Renderer.Tiling*") { drawTiles(WALL) drawTiles(TERRAIN) // regular tiles drawTiles(ORES) @@ -334,7 +338,7 @@ internal object BlocksDrawer { } private val occlusionRenderTag = CreateTileAtlas.RenderTag( - OCCLUSION_TILE_NUM_BASE, CreateTileAtlas.RenderTag.CONNECT_SELF, CreateTileAtlas.RenderTag.MASK_47, 0 + OCCLUSION_TILE_NUM_BASE, CreateTileAtlas.RenderTag.CONNECT_SELF, CreateTileAtlas.RenderTag.MASK_47, 0, 0 ) private lateinit var renderOnF3Only: Array @@ -583,19 +587,21 @@ internal object BlocksDrawer { else 0 if (mode == TERRAIN || mode == WALL) { - // TODO translate nearbyTilesInfo into proper subtile number + // translate nearbyTilesInfo into proper subtile number + val nearbyTilesInfo = getNearbyTilesInfoDeblocking(mode, x, y) + val subtiles = if (nearbyTilesInfo == null) + listOf( + Point2i(130, 1), Point2i(130, 1), Point2i(130, 1), Point2i(130, 1) + ) + else + (0..3).map { + Point2i(126, 0) + deblockerNearbyTilesToSubtile[it][nearbyTilesInfo] + } - // TEST CODE - val subtiles = arrayOf( - Point2i(130, 0), - Point2i(131, 0), - Point2i(131, 1), - Point2i(130, 1), - ) - /*TL*/writeToBufferSubtile(BLURMAP, bufferBaseX * 2 + 0, bufferBaseY * 2 + 0, subtiles[0].x, subtiles[0].y, 0, 0) - /*TR*/writeToBufferSubtile(BLURMAP, bufferBaseX * 2 + 1, bufferBaseY * 2 + 0, subtiles[1].x, subtiles[1].y, 0, 0) - /*BR*/writeToBufferSubtile(BLURMAP, bufferBaseX * 2 + 1, bufferBaseY * 2 + 1, subtiles[2].x, subtiles[2].y, 0, 0) - /*BL*/writeToBufferSubtile(BLURMAP, bufferBaseX * 2 + 0, bufferBaseY * 2 + 1, subtiles[3].x, subtiles[3].y, 0, 0) + /*TL*/writeToBufferSubtile(BLURMAP_BASE + mode, bufferBaseX * 2 + 0, bufferBaseY * 2 + 0, subtiles[0].x, subtiles[0].y, 0, 0) + /*TR*/writeToBufferSubtile(BLURMAP_BASE + mode, bufferBaseX * 2 + 1, bufferBaseY * 2 + 0, subtiles[1].x, subtiles[1].y, 0, 0) + /*BR*/writeToBufferSubtile(BLURMAP_BASE + mode, bufferBaseX * 2 + 1, bufferBaseY * 2 + 1, subtiles[2].x, subtiles[2].y, 0, 0) + /*BL*/writeToBufferSubtile(BLURMAP_BASE + mode, bufferBaseX * 2 + 0, bufferBaseY * 2 + 1, subtiles[3].x, subtiles[3].y, 0, 0) } if (renderTag.maskType >= CreateTileAtlas.RenderTag.MASK_SUBTILE_GENERIC) { @@ -796,6 +802,48 @@ internal object BlocksDrawer { return ret } + private fun getNearbyTilesInfoDeblocking(mode: Int, x: Int, y: Int): Int? { + val tileThis = world.getTileFrom(mode, x, y) + val nearbyTiles = getNearbyTilesPos4(x, y).map { world.getTileFrom(mode, it.x, it.y) } + + val renderTagThis = App.tileMaker.getRenderTag(tileThis) + + if (renderTagThis.postProcessing != CreateTileAtlas.RenderTag.POSTPROCESS_DEBLOCKING) return null + + when (renderTagThis.connectionType) { + CreateTileAtlas.RenderTag.CONNECT_SELF -> { + var ret = 0 + for (i in nearbyTiles.indices) { + if (nearbyTiles[i] == tileThis) { + ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3 + } + } + return ret + } + CreateTileAtlas.RenderTag.CONNECT_MUTUAL -> { + // make sure to not connect to tiles with no deblocking + var ret = 0 + for (i in nearbyTiles.indices) { + if (BlockCodex[nearbyTiles[i]].isSolidForTileCnx && isConnectMutual(nearbyTiles[i]) && + App.tileMaker.getRenderTag(nearbyTiles[i]).postProcessing == CreateTileAtlas.RenderTag.POSTPROCESS_DEBLOCKING + ) { + ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3 + } + } + + return ret + } + else -> return null + } + } + + private val deblockerNearbyTilesToSubtile: Array> = arrayOf( + arrayOf(Point2i(0,0),Point2i(0,0),Point2i(0,0),Point2i(0,0),Point2i(3,0),Point2i(3,0),Point2i(3,0),Point2i(3,0),Point2i(2,0),Point2i(2,0),Point2i(2,0),Point2i(2,0),Point2i(4,0),Point2i(4,0),Point2i(4,0),Point2i(4,0)), /*TL*/ + arrayOf(Point2i(1,0),Point2i(3,0),Point2i(1,0),Point2i(3,0),Point2i(1,0),Point2i(3,0),Point2i(1,0),Point2i(3,0),Point2i(3,1),Point2i(4,0),Point2i(3,1),Point2i(4,0),Point2i(3,1),Point2i(4,0),Point2i(3,1),Point2i(4,0)), /*TR*/ + arrayOf(Point2i(1,1),Point2i(2,1),Point2i(3,1),Point2i(4,0),Point2i(1,1),Point2i(2,1),Point2i(3,1),Point2i(4,0),Point2i(1,1),Point2i(2,1),Point2i(3,1),Point2i(4,0),Point2i(1,1),Point2i(2,1),Point2i(3,1),Point2i(4,0)), /*BR*/ + arrayOf(Point2i(0,1),Point2i(0,1),Point2i(2,0),Point2i(2,0),Point2i(2,1),Point2i(2,1),Point2i(4,0),Point2i(4,0),Point2i(0,1),Point2i(0,1),Point2i(2,0),Point2i(2,0),Point2i(2,1),Point2i(2,1),Point2i(4,0),Point2i(4,0)), /*BL*/ + ) + private fun getNearbyTilesInfoConMutual(x: Int, y: Int, mode: Int): Int { val nearbyTiles: List = getNearbyTilesPos(x, y).map { world.getTileFrom(mode, it.x, it.y) } @@ -1075,7 +1123,6 @@ internal object BlocksDrawer { ORES -> oreTilesBuffer FLUID -> fluidTilesBuffer OCCLUSION -> occlusionBuffer - BLURMAP -> blurMap else -> throw IllegalArgumentException() } @@ -1092,7 +1139,8 @@ internal object BlocksDrawer { ORES -> oreTilesBuffer FLUID -> fluidTilesBuffer OCCLUSION -> occlusionBuffer - BLURMAP -> blurMap + BLURMAP_TERR -> blurMapTerr + BLURMAP_WALL -> blurMapWall else -> throw IllegalArgumentException() } @@ -1107,6 +1155,9 @@ internal object BlocksDrawer { private var _blurTilesBuffer: Texture = Texture(1, 1, Pixmap.Format.RGBA8888) private val occlusionIntensity = 0.25f // too low value and dark-coloured walls won't darken enough + private val doTilemapUpdate: Boolean + get() = (!world.layerTerrain.ptrDestroyed && App.GLOBAL_RENDER_TIMER % 3 == 0L) + private fun renderUsingBuffer(mode: Int, projectionMatrix: Matrix4, drawGlow: Boolean, drawEmissive: Boolean) { //Gdx.gl.glClearColor(.094f, .094f, .094f, 0f) //Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) @@ -1117,7 +1168,7 @@ internal object BlocksDrawer { val tileAtlas = when (mode) { - TERRAIN, ORES, WALL, OCCLUSION, FLUID, BLURMAP -> tilesTerrain + TERRAIN, ORES, WALL, OCCLUSION, FLUID, BLURMAP_TERR, BLURMAP_WALL -> tilesTerrain else -> throw IllegalArgumentException() } val sourceBuffer = when(mode) { @@ -1133,35 +1184,33 @@ internal object BlocksDrawer { else -> Color.WHITE } - // write to colour buffer // As the texture size is very small, multithreading it would be less effective - for (y in 0 until tilesBuffer.height) { - for (x in 0 until tilesBuffer.width) { - val colRaw = sourceBuffer[y, x] - val colMain = colRaw.toInt() - val colSub = colRaw.ushr(32).toInt() - - tilesBuffer.setColor(colMain) - tilesBuffer.drawPixel(x, y) - - tilesBuffer2.setColor(colSub) - tilesBuffer2.drawPixel(x, y) - } - } - - // write blurmap to its own buffer for TERRAIN and WALL - if (mode == TERRAIN || mode == WALL) { + // TODO making it run sporadically without graphical issue would improve the tiling performance +// if (doTilemapUpdate) { for (y in 0 until tilesBuffer.height) { for (x in 0 until tilesBuffer.width) { - val colRaw = blurMap[y, x] + val colRaw = sourceBuffer[y, x] val colMain = colRaw.toInt() + val colSub = colRaw.ushr(32).toInt() - blurTilesBuffer.setColor(colMain) - blurTilesBuffer.drawPixel(x, y) + tilesBuffer.setColor(colMain) + tilesBuffer.drawPixel(x, y) + + tilesBuffer2.setColor(colSub) + tilesBuffer2.drawPixel(x, y) + + // write blurmap to its own buffer for TERRAIN and WALL + if (mode == TERRAIN || mode == WALL) { + val colRaw = (if (mode == TERRAIN) blurMapTerr else blurMapWall)[y, x] + val colMain = colRaw.toInt() + + blurTilesBuffer.setColor(colMain) + blurTilesBuffer.drawPixel(x, y) + } } } - } +// } _tilesBufferAsTex.dispose() @@ -1256,7 +1305,8 @@ internal object BlocksDrawer { oreTilesBuffer = UnsafeLong2D(tilesInHorizontal, tilesInVertical) fluidTilesBuffer = UnsafeLong2D(tilesInHorizontal, tilesInVertical) occlusionBuffer = UnsafeLong2D(tilesInHorizontal, tilesInVertical) - blurMap = UnsafeLong2D(tilesInHorizontal, tilesInVertical) + blurMapTerr = UnsafeLong2D(tilesInHorizontal, tilesInVertical) + blurMapWall = UnsafeLong2D(tilesInHorizontal, tilesInVertical) tempRenderTypeBuffer = UnsafeLong2D(hTilesInHorizontal, hTilesInVertical) tilesBuffer.dispose() @@ -1346,7 +1396,8 @@ internal object BlocksDrawer { if (::oreTilesBuffer.isInitialized) oreTilesBuffer.destroy() if (::fluidTilesBuffer.isInitialized) fluidTilesBuffer.destroy() if (::occlusionBuffer.isInitialized) occlusionBuffer.destroy() - if (::blurMap.isInitialized) blurMap.destroy() + if (::blurMapTerr.isInitialized) blurMapTerr.destroy() + if (::blurMapWall.isInitialized) blurMapWall.destroy() if (::tempRenderTypeBuffer.isInitialized) tempRenderTypeBuffer.destroy() if (::batch.isInitialized) batch.tryDispose() diff --git a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt index 977fd0592..c829bfc32 100644 --- a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt +++ b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt @@ -87,7 +87,7 @@ class CreateTileAtlas { lateinit var tagsByTileNum: HashArray; private set lateinit var itemSheetNumbers: HashMap // TileID, Int private set - private val defaultRenderTag = RenderTag(3, RenderTag.CONNECT_SELF, RenderTag.MASK_NA, 0) // 'update' block + private val defaultRenderTag = RenderTag(3, RenderTag.CONNECT_SELF, RenderTag.MASK_NA, 0, 0) // 'update' block var initialised = false private set @@ -478,20 +478,23 @@ class CreateTileAtlas { val maskType = if (tilesPixmap.width >= 3*W_SUBTILE_GENERIC) MASK_SUBTILE_GRASS else MASK_SUBTILE_GENERIC var connectionType0 = 0 var tilingMode = 0 + var postProcessing = 0 for (x in 0 until 4) { // val pixelY0 = (tilesPixmap.getPixel(x, 0).and(255) >= 128).toInt(x) val pixelY1 = (tilesPixmap.getPixel(x, 1).and(255) >= 128).toInt(x) val pixelY2 = (tilesPixmap.getPixel(x, 2).and(255) >= 128).toInt(x) + val pixelY3 = (tilesPixmap.getPixel(x, 3).and(255) >= 128).toInt(x) tilingMode += pixelY1 connectionType0 += pixelY2 + postProcessing += pixelY3 } val connectionType = when (connectionType0) { 1 -> CONNECT_MUTUAL 2 -> CONNECT_SELF else -> throw IllegalArgumentException("$connectionType0") } - addTag(blockID, connectionType, maskType, tilingMode) + addTag(blockID, connectionType, maskType, tilingMode, postProcessing) // println("drawToAtlantes tile: $blockID with mode $tilingMode") drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, maskType) } @@ -541,13 +544,13 @@ class CreateTileAtlas { * This function must precede the drawToAtlantes() function, as the marking requires the variable * 'atlasCursor' and the draw function modifies it! */ - private fun addTag(id: ItemID, connectionType: Int, maskType: Int, tilingMode: Int = TILING_FULL) { + private fun addTag(id: ItemID, connectionType: Int, maskType: Int, tilingMode: Int = TILING_FULL, postProcessing: Int = 0) { if (tags.containsKey(id)) { throw Error("Block $id already exists") } - tags[id] = RenderTag(atlasCursor, connectionType, maskType, tilingMode) - tagsByTileNum[atlasCursor.toLong()] = RenderTag(atlasCursor, connectionType, maskType, tilingMode) + tags[id] = RenderTag(atlasCursor, connectionType, maskType, tilingMode, postProcessing) + tagsByTileNum[atlasCursor.toLong()] = RenderTag(atlasCursor, connectionType, maskType, tilingMode, postProcessing) printdbg(this, "tileName ${id} ->> tileNumber ${atlasCursor}") } @@ -714,7 +717,7 @@ class CreateTileAtlas { /** * @param tileNumber ordinal number of a tile in the texture atlas */ - data class RenderTag(val tileNumber: Int, val connectionType: Int, val maskType: Int, val tilingMode: Int) { + data class RenderTag(val tileNumber: Int, val connectionType: Int, val maskType: Int, val tilingMode: Int, val postProcessing: Int) { companion object { const val CONNECT_MUTUAL = 0 const val CONNECT_SELF = 1 @@ -740,6 +743,9 @@ class CreateTileAtlas { const val TILING_BRICK_LARGE = 4 const val TILING_BRICK_LARGE_NOFLIP = 5 + const val POSTPROCESS_NONE = 0 + const val POSTPROCESS_DEBLOCKING = 1 + fun maskTypeToTileCount(maskType: Int) = when (maskType) { MASK_NA -> 1 MASK_16 -> 16 diff --git a/src/shaders/tiling.frag b/src/shaders/tiling.frag index 91697a6eb..265374a46 100644 --- a/src/shaders/tiling.frag +++ b/src/shaders/tiling.frag @@ -191,8 +191,8 @@ void main() { vec4 tileU = getFragColorForOnscreenCoord1(fragCoord + blurU); vec4 tileD = getFragColorForOnscreenCoord1(fragCoord + blurD); - vec4 blurH = (tileC + tileC + tileL + tileR) * _four; - vec4 blurV = (tileC + tileC + tileU + tileD) * _four; + vec4 blurH = (tileC + tileL + tileR) * _three; + vec4 blurV = (tileC + tileU + tileD) * _three; vec4 blurPower = tile_breakage_blur[2]; vec4 finalTile = mix( @@ -206,5 +206,5 @@ void main() { vec4 finalColor = fma(mix(finalTile, finalBreakage, finalBreakage.a), bc.xxxy, finalTile * bc.yyyx); fragColor = mix(colourFilter, colourFilter * finalColor, mulBlendIntensity); -// fragColor = blurPower; +// fragColor = mix(fragColor, blurPower, 0.18); // debug overlay }