From e18f6512bcc68d8c5243f8bec1d4dc56604b9d71 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 18 Aug 2024 03:33:02 +0900 Subject: [PATCH] subtiling wip --- .../terrarum/worlddrawer/BlocksDrawer.kt | 1 - src/shaders/tiling.frag | 20 ++++++++++++------- .../terrain_variable_subtiling_full.kra | 3 +++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 work_files/graphics/terrain/terrain_variable_subtiling_full.kra diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index 9722c2030..4fe1d9543 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -892,7 +892,6 @@ internal object BlocksDrawer { shader.setUniform2fv("tilesInAtlas", App.tileMaker.SHADER_SIZE_KEYS, 2, 2) shader.setUniform2fv("atlasTexSize", App.tileMaker.SHADER_SIZE_KEYS, 0, 2) shader.setUniformf("colourFilter", vertexColour) - shader.setUniformf("screenDimension", Gdx.graphics.width / magn, Gdx.graphics.height / magn) shader.setUniformi("tilesAtlas", 0) shader.setUniformi("tilesBlendAtlas", 2) shader.setUniformi("tilemap", 1) diff --git a/src/shaders/tiling.frag b/src/shaders/tiling.frag index c41cb4dce..5b1d972ac 100644 --- a/src/shaders/tiling.frag +++ b/src/shaders/tiling.frag @@ -7,8 +7,7 @@ precision mediump float; #endif -//layout(origin_upper_left) in vec4 gl_FragCoord; // commented; requires #version 150 or later -// gl_FragCoord is origin to bottom-left +layout(origin_upper_left,pixel_center_integer) in vec4 gl_FragCoord; in vec4 v_color; in vec2 v_texCoords; @@ -16,7 +15,6 @@ in vec2 v_texCoords; uniform sampler2D u_texture; -uniform vec2 screenDimension; uniform vec2 tilesInAxes; // size of the tilemap texture; vec2(tiles_in_horizontal, tiles_in_vertical) uniform sampler2D tilemap; // RGBA8888 @@ -41,6 +39,7 @@ uniform float drawBreakage = 1.0; // set it to 0f to not draw breakage, 1f to dr uniform float mulBlendIntensity = 1.0; // used my MUL-blending drawings; works about the same way as the Layer Opacity slider of Photoshop/Krita/etc. const vec2 bc = vec2(1.0, 0.0); //binary constant +const vec2 haalf = vec2(0.5, 0.5); out vec4 fragColor; @@ -50,7 +49,7 @@ ivec2 getTileXY(int tileNumber) { // return: int=0x(aa)rrggbb int _colToInt(vec4 color) { - return int(color.b * 255) | (int(color.g * 255) << 8) | (int(color.r * 255) << 16);// | (int(color.a * 255) << 24); + return int(color.b * 255) | (int(color.g * 255) << 8) | (int(color.r * 255) << 16) | (int(color.a * 255) << 24); } // 0x00ggbb where int=0xaarrggbb @@ -71,6 +70,13 @@ int getTileFlipRotFromColor(vec4 color) { return (_colToInt(color) >> 16) & 0xF; } +// 0baaaa_aaa0_0[24] where int=0baaaaaaaa_rrrrrrrr_... +// in other words, least significant bit of the alpha value is unused. +// return: [0..127] +int getSubtileFromColor(vec4 color) { + return (_colToInt(color) >> 25) & 0x7F; +} + mat3x2[] flipRotMat = mat3x2[]( mat3x2( 1.0, 0.0, 0.0, 1.0, tileSizeInPx.x*0.0, tileSizeInPx.y*0.0), @@ -98,11 +104,11 @@ void main() { // default gl_FragCoord takes half-integer (represeting centre of the pixel) -- could be useful for phys solver? // This one, however, takes exact integer by rounding down. // vec2 overscannedScreenDimension = tilesInAxes * tileSizeInPx; // how many tiles will fit into a screen; one used by the tileFromMap; we need this because screen size is not integer multiple of the tile size - vec2 flippedFragCoord = vec2(gl_FragCoord.x, screenDimension.y - gl_FragCoord.y) + cameraTranslation; // NO IVEC2!!; this flips Y + vec2 fragCoord = gl_FragCoord.xy + cameraTranslation + haalf; // NO IVEC2!!; this flips Y // get required tile numbers // - vec4 tileFromMap = texture(tilemap, flippedFragCoord / overscannedScreenDimension); // raw tile number + vec4 tileFromMap = texture(tilemap, fragCoord / overscannedScreenDimension); // raw tile number int tile = getTileFromColor(tileFromMap); int breakage = getBreakageFromColor(tileFromMap); int flipRot = getTileFlipRotFromColor(tileFromMap); @@ -112,7 +118,7 @@ void main() { // calculate the UV coord value for texture sampling // // don't really need highp here; read the GLES spec - vec2 uvCoordForTile = uvFlipRot(flipRot, mod(flippedFragCoord, tileSizeInPx)) * _tileSizeInPx * _tilesInAtlas; // 0..0.00390625 regardless of tile position in atlas + vec2 uvCoordForTile = uvFlipRot(flipRot, mod(fragCoord, tileSizeInPx)) * _tileSizeInPx * _tilesInAtlas; // 0..0.00390625 regardless of tile position in atlas vec2 uvCoordOffsetTile = tileXY * _tilesInAtlas; // where the tile starts in the atlas, using uv coord (0..1) vec2 uvCoordOffsetBreakage = breakageXY * _tilesInAtlas; diff --git a/work_files/graphics/terrain/terrain_variable_subtiling_full.kra b/work_files/graphics/terrain/terrain_variable_subtiling_full.kra new file mode 100644 index 000000000..2b6011ac0 --- /dev/null +++ b/work_files/graphics/terrain/terrain_variable_subtiling_full.kra @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3dc262b3dd2ef865210c34e0d0c043e21842a090898402a598e20cd0d80d1299 +size 535761