From ebcc2ef4bfbec61a3b178510831782960d664ca0 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 20 Aug 2024 22:01:59 +0900 Subject: [PATCH] old tiling is adapted to subtiling (no fliprot/breakage yet) --- .../terrarum/worlddrawer/BlocksDrawer.kt | 40 +++++++++++-------- .../terrarum/worlddrawer/CreateTileAtlas.kt | 2 +- src/shaders/tiling.frag | 20 ++++++---- .../terrain_variable_subtiling_full.kra | 4 +- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index 0f3096645..d6b491f16 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -458,7 +458,7 @@ internal object BlocksDrawer { (fillThis * 16f - 0.5f).floorToInt().coerceIn(0, 15) } else if (treeLeavesTiles.binarySearch(rawTileNum) >= 0) { - getNearbyTilesInfoTrees(x, y, mode).swizzle8(rawTileNum, hash) + getNearbyTilesInfoTrees(x, y, mode)//.swizzle8(rawTileNum, hash) } else if (treeTrunkTiles.binarySearch(rawTileNum) >= 0) { hash = 0 @@ -466,17 +466,17 @@ internal object BlocksDrawer { } else if (platformTiles.binarySearch(rawTileNum) >= 0) { hash %= 2 - getNearbyTilesInfoPlatform(x, y).swizzleH2(rawTileNum, hash) + getNearbyTilesInfoPlatform(x, y)//.swizzleH2(rawTileNum, hash) } else if (wallStickerTiles.binarySearch(rawTileNum) >= 0) { hash = 0 getNearbyTilesInfoWallSticker(x, y) } else if (connectMutualTiles.binarySearch(rawTileNum) >= 0) { - getNearbyTilesInfoConMutual(x, y, mode).swizzle8(rawTileNum, hash) + getNearbyTilesInfoConMutual(x, y, mode)//.swizzle8(rawTileNum, hash) } else if (connectSelfTiles.binarySearch(rawTileNum) >= 0) { - getNearbyTilesInfoConSelf(x, y, mode, rawTileNum).swizzle8(rawTileNum, hash) + getNearbyTilesInfoConSelf(x, y, mode, rawTileNum)//.swizzle8(rawTileNum, hash) } else { 0 @@ -510,8 +510,10 @@ internal object BlocksDrawer { tileNumber = 2 // black solid } - val thisTileX = tileNumber % App.tileMaker.TILES_IN_X - val thisTileY = tileNumber / App.tileMaker.TILES_IN_X + val subtileNum = tileNumber.tileToSubtile() + + val thisTileX = subtileNum % App.tileMaker.TILES_IN_X + val thisTileY = subtileNum / App.tileMaker.TILES_IN_X val breakage = if (mode == TERRAIN || mode == ORES) world.getTerrainDamage(x, y) else if (mode == WALL) world.getWallDamage(x, y) else 0f if (breakage.isNaN()) throw IllegalStateException("Block breakage at ($x, $y) is NaN (mode=$mode)") @@ -519,15 +521,20 @@ internal object BlocksDrawer { val breakingStage = if (mode == TERRAIN || mode == WALL || mode == ORES) (breakage / maxHealth).coerceIn(0f, 1f).times(BREAKAGE_STEPS).roundToInt() else 0 // draw a tile - writeToBuffer(mode, bufferBaseX*2+0, bufferBaseY*2+0, thisTileX, thisTileY, breakingStage, hash) - writeToBuffer(mode, bufferBaseX*2+1, bufferBaseY*2+0, thisTileX, thisTileY, breakingStage, hash) - writeToBuffer(mode, bufferBaseX*2+0, bufferBaseY*2+1, thisTileX, thisTileY, breakingStage, hash) - writeToBuffer(mode, bufferBaseX*2+1, bufferBaseY*2+1, thisTileX, thisTileY, breakingStage, hash) + writeToBuffer(mode, bufferBaseX*2+0, bufferBaseY*2+0, thisTileX+0, thisTileY+0, breakingStage, hash) + writeToBuffer(mode, bufferBaseX*2+1, bufferBaseY*2+0, thisTileX+1, thisTileY+0, breakingStage, hash) + writeToBuffer(mode, bufferBaseX*2+0, bufferBaseY*2+1, thisTileX+0, thisTileY+2, breakingStage, hash) + writeToBuffer(mode, bufferBaseX*2+1, bufferBaseY*2+1, thisTileX+1, thisTileY+2, breakingStage, hash) tempRenderTypeBuffer[bufferBaseY, bufferBaseX] = (nearbyTilesInfo or rawTileNum.shl(16)).toLong() } } +// println("App.tileMaker.TILES_IN_X = ${App.tileMaker.TILES_IN_X}\tApp.tileMaker.atlas.width = ${App.tileMaker.atlas.width}") +// println("tilesTerrain.horizontalCount = ${tilesTerrain.horizontalCount}") } + private fun Int.tileToSubtile() = (this / App.tileMaker.TILES_IN_X) * 4*App.tileMaker.TILES_IN_X + + (this % App.tileMaker.TILES_IN_X) * 2 + private val swizzleMap8 = arrayOf( arrayOf(0,1,2,3,4,5,6,7), /* normal */ arrayOf(4,3,2,1,0,7,6,5), /* horz flip */ @@ -798,7 +805,8 @@ internal object BlocksDrawer { } /** - * Raw format of RGBA8888. + * @param sheetX x-coord of the SUBTILE in an atlas + * @param sheetY y-coord of the SUBTILE in an atlas * * @return Raw colour bits in RGBA8888 format */ @@ -938,14 +946,14 @@ internal object BlocksDrawer { var hTilesInVertical = -1; private set fun resize(screenW: Int, screenH: Int) { - tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilToInt().times(2) + 2 - tilesInVertical = (App.scr.hf / TILE_SIZE).ceilToInt().times(2) + 2 - hTilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilToInt() + 1 hTilesInVertical = (App.scr.hf / TILE_SIZE).ceilToInt() + 1 - val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilToInt().times(2) + 1 - val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilToInt().times(2) + 1 + tilesInHorizontal = hTilesInHorizontal * 2 + tilesInVertical = hTilesInVertical * 2 + + val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilToInt().times(2) + 2 + val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilToInt().times(2) + 2 // only update if it's really necessary if (oldTH != tilesInHorizontal || oldTV != tilesInVertical) { diff --git a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt index 85faa6640..f2d358817 100644 --- a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt +++ b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt @@ -243,7 +243,7 @@ class CreateTileAtlas { } // test print - PixmapIO2.writeTGA(Gdx.files.absolute("${App.defaultDir}/atlas.tga"), atlas, false) +// PixmapIO2.writeTGA(Gdx.files.absolute("${App.defaultDir}/atlas.tga"), atlas, false) // PixmapIO2.writeTGA(Gdx.files.absolute("${AppLoader.defaultDir}/atlasGlow.tga"), atlasGlow, false) diff --git a/src/shaders/tiling.frag b/src/shaders/tiling.frag index fd33a23e5..53587c164 100644 --- a/src/shaders/tiling.frag +++ b/src/shaders/tiling.frag @@ -15,7 +15,7 @@ in vec2 v_texCoords; uniform sampler2D u_texture; -uniform vec2 tilesInAxes; // size of the tilemap texture; vec2(tiles_in_horizontal, tiles_in_vertical) +uniform vec2 tilesInAxes; // 8x8 uniform sampler2D tilemap; // RGBA8888 uniform sampler2D tilemap2; // RGBA8888 @@ -25,11 +25,11 @@ uniform sampler2D tilesBlendAtlas; // alternative terrain for the weather mix (e uniform float tilesBlend = 0.0; // percentage of blending [0f..1f]. 0: draws tilesAtlas, 1: draws tilesBlendAtlas uniform vec2 tilesInAtlas = vec2(256.0, 256.0); -uniform vec2 atlasTexSize = vec2(4096.0, 4096.0); +uniform vec2 atlasTexSize = vec2(2048.0, 2048.0); vec2 _tilesInAtlas = vec2(1.0, 1.0) / tilesInAtlas; -vec2 tileSizeInPx = atlasTexSize * _tilesInAtlas; // should be like ivec2(16.0, 16.0) -vec2 _tileSizeInPx = vec2(1.0, 1.0) / tileSizeInPx; // should be like ivec2(0.06125, 0.06125) +vec2 tileSizeInPx = atlasTexSize * _tilesInAtlas; // should be like ivec2(8.0, 8.0) +vec2 _tileSizeInPx = vec2(1.0, 1.0) / tileSizeInPx; // should be like ivec2(0.125, 0.125) uniform vec4 colourFilter = vec4(1, 1, 1, 1); // used by WALL to darken it @@ -62,8 +62,8 @@ ivec3 _colToInt(vec4 map1, vec4 map2) { return ivec3( (col1.r << 16) | (col1.g << 8) | col1.b, // tile - col2.b, // breakage - col2.g // fliprot + 0,//col2.b, // breakage + 0//col2.g // fliprot ); } @@ -129,6 +129,12 @@ void main() { vec4 finalColor = fma(mix(finalTile, finalBreakage, finalBreakage.a), bc.xxxy, finalTile * bc.yyyx); - fragColor = mix(colourFilter, colourFilter * finalColor, mulBlendIntensity); +// fragColor = mix(colourFilter, colourFilter * finalColor, mulBlendIntensity); + fragColor = finalTile; + + + // SUBTILE fixme: + // - breakage tile samples wrong coord -- needs bigtile-to-subtile adaptation + // - somehow make fliprot work again -- needs bigtile-to-subtile adaptation } diff --git a/work_files/graphics/terrain/terrain_variable_subtiling_full.kra b/work_files/graphics/terrain/terrain_variable_subtiling_full.kra index 2b6011ac0..5ee89bc36 100644 --- a/work_files/graphics/terrain/terrain_variable_subtiling_full.kra +++ b/work_files/graphics/terrain/terrain_variable_subtiling_full.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3dc262b3dd2ef865210c34e0d0c043e21842a090898402a598e20cd0d80d1299 -size 535761 +oid sha256:fdc13fac8df34f162e351b235758a8a3949c2228b44ed3c958c6ba1d6d348ef1 +size 575227