performance improvements by disabling tile deblocking

This commit is contained in:
minjaesong
2024-09-13 13:18:01 +09:00
parent 34a7a9285d
commit ec59000ae9
8 changed files with 53 additions and 54 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -607,7 +607,7 @@ internal object BlocksDrawer {
(breakage / maxHealth).coerceIn(0f, 1f).times(BREAKAGE_STEPS).roundToInt() (breakage / maxHealth).coerceIn(0f, 1f).times(BREAKAGE_STEPS).roundToInt()
else 0 else 0
if (mode == TERRAIN || mode == WALL) { /*if (mode == TERRAIN || mode == WALL) {
// translate nearbyTilesInfo into proper subtile number // translate nearbyTilesInfo into proper subtile number
val nearbyTilesInfo = getNearbyTilesInfoDeblocking(mode, x, y) val nearbyTilesInfo = getNearbyTilesInfoDeblocking(mode, x, y)
val subtiles = if (nearbyTilesInfo == null) val subtiles = if (nearbyTilesInfo == null)
@@ -623,7 +623,7 @@ internal object BlocksDrawer {
/*TR*/writeToBufferSubtile(BLURMAP_BASE + mode, bufferBaseX * 2 + 1, bufferBaseY * 2 + 0, subtiles[1].x, subtiles[1].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) /*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) /*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) { if (renderTag.maskType >= CreateTileAtlas.RenderTag.MASK_SUBTILE_GENERIC) {
hash = getHashCoord(x, y, 268435456, mode, renderTag.tileNumber) hash = getHashCoord(x, y, 268435456, mode, renderTag.tileNumber)
@@ -1173,7 +1173,7 @@ internal object BlocksDrawer {
private var _tilesBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888) private var _tilesBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
private var _tilesBufferAsTex2: Texture = Texture(1, 1, Pixmap.Format.RGBA8888) private var _tilesBufferAsTex2: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
private var _blurTilesBuffer: Texture = Texture(1, 1, Pixmap.Format.RGBA8888) // 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 occlusionIntensity = 0.25f // too low value and dark-coloured walls won't darken enough
private val doTilemapUpdate: Boolean private val doTilemapUpdate: Boolean
@@ -1279,26 +1279,26 @@ internal object BlocksDrawer {
_tilesBufferAsTex2 = Texture(drawBuffer2) _tilesBufferAsTex2 = Texture(drawBuffer2)
_tilesBufferAsTex2.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) _tilesBufferAsTex2.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
_blurTilesBuffer.dispose() // _blurTilesBuffer.dispose()
_blurTilesBuffer = Texture(blurTilesBuffer) // _blurTilesBuffer = Texture(blurTilesBuffer)
_blurTilesBuffer.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) // _blurTilesBuffer.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
if (drawEmissive) { if (drawEmissive) {
nullTex.bind(4) // nullTex.bind(4)
_tilesBufferAsTex2.bind(3) _tilesBufferAsTex2.bind(3)
_tilesBufferAsTex.bind(2) _tilesBufferAsTex.bind(2)
tilesEmissive.texture.bind(1) tilesEmissive.texture.bind(1)
tilesEmissive.texture.bind(0) // for some fuck reason, it must be bound as last tilesEmissive.texture.bind(0) // for some fuck reason, it must be bound as last
} }
else if (drawGlow) { else if (drawGlow) {
nullTex.bind(4) // nullTex.bind(4)
_tilesBufferAsTex2.bind(3) _tilesBufferAsTex2.bind(3)
_tilesBufferAsTex.bind(2) _tilesBufferAsTex.bind(2)
tilesGlow.texture.bind(1) tilesGlow.texture.bind(1)
tilesGlow.texture.bind(0) // for some fuck reason, it must be bound as last tilesGlow.texture.bind(0) // for some fuck reason, it must be bound as last
} }
else { else {
_blurTilesBuffer.bind(4) // _blurTilesBuffer.bind(4)
_tilesBufferAsTex2.bind(3) _tilesBufferAsTex2.bind(3)
_tilesBufferAsTex.bind(2) _tilesBufferAsTex.bind(2)
tilesTerrainNext.texture.bind(1) tilesTerrainNext.texture.bind(1)
@@ -1312,7 +1312,7 @@ internal object BlocksDrawer {
shaderTiling.setUniformi("tilesBlendAtlas", 1) shaderTiling.setUniformi("tilesBlendAtlas", 1)
shaderTiling.setUniformi("tilemap", 2) shaderTiling.setUniformi("tilemap", 2)
shaderTiling.setUniformi("tilemap2", 3) shaderTiling.setUniformi("tilemap2", 3)
shaderTiling.setUniformi("deblockingMap", 4) // shaderTiling.setUniformi("deblockingMap", 4)
shaderTiling.setUniformi("tilemapDimension", drawBuffer1.width, drawBuffer1.height) shaderTiling.setUniformi("tilemapDimension", drawBuffer1.width, drawBuffer1.height)
shaderTiling.setUniformf("tilesInAxes", tilesInHorizontal.toFloat(), tilesInVertical.toFloat()) shaderTiling.setUniformf("tilesInAxes", tilesInHorizontal.toFloat(), tilesInVertical.toFloat())
shaderTiling.setUniformi("cameraTranslation", camTransX, camTransY) // usage of 'fmod' and '%' were depend on the for_x_start, which I can't just do naive int div shaderTiling.setUniformi("cameraTranslation", camTransX, camTransY) // usage of 'fmod' and '%' were depend on the for_x_start, which I can't just do naive int div
@@ -1457,7 +1457,7 @@ internal object BlocksDrawer {
blurTilesBuffer.dispose() blurTilesBuffer.dispose()
_tilesBufferAsTex.dispose() _tilesBufferAsTex.dispose()
_tilesBufferAsTex2.dispose() _tilesBufferAsTex2.dispose()
_blurTilesBuffer.dispose() // _blurTilesBuffer.dispose()
tilesQuad.tryDispose() tilesQuad.tryDispose()
shaderTiling.dispose() shaderTiling.dispose()
shaderDeblock.dispose() shaderDeblock.dispose()

View File

@@ -471,9 +471,8 @@ class CreateTileAtlas {
// 0000 (0): INVALID // 0000 (0): INVALID
// 1000 (1): connect-mutual // 1000 (1): connect-mutual
// 0100 (2): connect-self // 0100 (2): connect-self
// Line 3: Request for Post-Processing // Line 3: Request for Post-Processing (currently does nothing)
// 0000 (0): do nothing // 0000 (0): do nothing
// 1000 (1): subtile deblocking
// NOTE: For this system, the "NORANDTILE" tag is ignored // NOTE: For this system, the "NORANDTILE" tag is ignored
val maskType = if (tilesPixmap.width >= 3*W_SUBTILE_GENERIC) MASK_SUBTILE_GRASS else MASK_SUBTILE_GENERIC val maskType = if (tilesPixmap.width >= 3*W_SUBTILE_GENERIC) MASK_SUBTILE_GRASS else MASK_SUBTILE_GENERIC
var connectionType0 = 0 var connectionType0 = 0

View File

@@ -12,7 +12,7 @@ uniform sampler2D tilemap; // RGBA8888
uniform sampler2D tilemap2; // RGBA8888 uniform sampler2D tilemap2; // RGBA8888
uniform sampler2D tilesAtlas; // terrain, wire, fluids, etc. uniform sampler2D tilesAtlas; // terrain, wire, fluids, etc.
uniform sampler2D tilesBlendAtlas; // alternative terrain for the weather mix (e.g. yellowed grass) uniform sampler2D tilesBlendAtlas; // alternative terrain for the weather mix (e.g. yellowed grass)
uniform sampler2D deblockingMap; //uniform sampler2D deblockingMap;
uniform vec2 tilesInAxes; // 8x8 uniform vec2 tilesInAxes; // 8x8
uniform float tilesBlend = 0.0; // percentage of blending [0f..1f]. 0: draws tilesAtlas, 1: draws tilesBlendAtlas uniform float tilesBlend = 0.0; // percentage of blending [0f..1f]. 0: draws tilesAtlas, 1: draws tilesBlendAtlas
@@ -78,15 +78,15 @@ vec2 uvFlipRot(int op, vec2 uv) {
return (flipRotMat[op] * vec3(uv, 1.0)).xy; return (flipRotMat[op] * vec3(uv, 1.0)).xy;
} }
const vec4 _four = vec4(1.0 / 4.0); //const vec4 _four = vec4(1.0 / 4.0);
const vec4 _three = vec4(1.0 / 3.0); //const vec4 _three = vec4(1.0 / 3.0);
const vec4 _two = vec4(1.0 / 2.0); //const vec4 _two = vec4(1.0 / 2.0);
const vec4 zero = vec4(0.0); //const vec4 zero = vec4(0.0);
const float blur = 1.0; //const float blur = 1.0;
const vec2 blurU = vec2(0.0, -blur); //const vec2 blurU = vec2(0.0, -blur);
const vec2 blurD = vec2(0.0, +blur); //const vec2 blurD = vec2(0.0, +blur);
const vec2 blurL = vec2(-blur, 0.0); //const vec2 blurL = vec2(-blur, 0.0);
const vec2 blurR = vec2(+blur, 0.0); //const vec2 blurR = vec2(+blur, 0.0);
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 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
@@ -96,11 +96,11 @@ vec4[2] getTileNumbersFromMap(vec2 fragCoord) {
return vec4[2](tileFromMap, tileFromMap2); return vec4[2](tileFromMap, tileFromMap2);
} }
vec4 getBlurmapNumbersFromMap(vec2 fragCoord) { //vec4 getBlurmapNumbersFromMap(vec2 fragCoord) {
return texture(deblockingMap, fragCoord / overscannedScreenDimension);// raw tile number // return texture(deblockingMap, fragCoord / overscannedScreenDimension);// raw tile number
} //}
vec4[3] getFragColorForOnscreenCoord(vec2 fragCoord) { vec4[2] getFragColorForOnscreenCoord(vec2 fragCoord) {
vec4[] tileFromMap = getTileNumbersFromMap(fragCoord); vec4[] tileFromMap = getTileNumbersFromMap(fragCoord);
ivec3 tbf = _colToInt(tileFromMap[0], tileFromMap[1]); ivec3 tbf = _colToInt(tileFromMap[0], tileFromMap[1]);
int tile = tbf.x; int tile = tbf.x;
@@ -111,11 +111,11 @@ vec4[3] getFragColorForOnscreenCoord(vec2 fragCoord) {
ivec2 tileQ = tileXYnQ.zw; ivec2 tileQ = tileXYnQ.zw;
ivec2 breakageXY = tileNumberToXY(2*(breakage + 5)).xy; // +5 is hard-coded constant that depends on the contents of the atlas ivec2 breakageXY = tileNumberToXY(2*(breakage + 5)).xy; // +5 is hard-coded constant that depends on the contents of the atlas
vec4 blurFromMap = getBlurmapNumbersFromMap(fragCoord); // vec4 blurFromMap = getBlurmapNumbersFromMap(fragCoord);
ivec3 tbf2 = _colToInt(blurFromMap, zero); // ivec3 tbf2 = _colToInt(blurFromMap, zero);
int blurTileNum = tbf2.x; // int blurTileNum = tbf2.x;
ivec4 blurXYnQ = tileNumberToXY(blurTileNum); // ivec4 blurXYnQ = tileNumberToXY(blurTileNum);
ivec2 blurXY = blurXYnQ.xy; // ivec2 blurXY = blurXYnQ.xy;
// calculate the UV coord value for texture sampling // // calculate the UV coord value for texture sampling //
@@ -124,13 +124,13 @@ vec4[3] getFragColorForOnscreenCoord(vec2 fragCoord) {
vec2 uvCoordForTile1 = mod(fragCoord, tileSizeInPx) * _tileSizeInPx * _tilesInAtlas;// 0..0.00390625 regardless of tile position in atlas vec2 uvCoordForTile1 = 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 uvCoordOffsetTile = tileXY * _tilesInAtlas; // where the tile starts in the atlas, using uv coord (0..1)
vec2 uvCoordOffsetBreakage = (breakageXY + tileQ) * _tilesInAtlas; vec2 uvCoordOffsetBreakage = (breakageXY + tileQ) * _tilesInAtlas;
vec2 uvCoordOffsetBlurmap = blurXY * _tilesInAtlas; // vec2 uvCoordOffsetBlurmap = blurXY * _tilesInAtlas;
// get final UV coord for the actual sampling // // get final UV coord for the actual sampling //
vec2 finalUVCoordForTile = uvCoordForTile + uvCoordOffsetTile;// where we should be actually looking for in atlas, using UV coord (0..1) vec2 finalUVCoordForTile = uvCoordForTile + uvCoordOffsetTile;// where we should be actually looking for in atlas, using UV coord (0..1)
vec2 finalUVCoordForBreakage = uvCoordForTile1 + uvCoordOffsetBreakage; vec2 finalUVCoordForBreakage = uvCoordForTile1 + uvCoordOffsetBreakage;
vec2 finalUVCoordForBlurmap = uvCoordForTile1 + uvCoordOffsetBlurmap; // vec2 finalUVCoordForBlurmap = uvCoordForTile1 + uvCoordOffsetBlurmap;
// blending a breakage tex with main tex // // blending a breakage tex with main tex //
@@ -139,8 +139,8 @@ vec4[3] getFragColorForOnscreenCoord(vec2 fragCoord) {
return vec4[]( return vec4[](
mix(tileCol, tileAltCol, tilesBlend), mix(tileCol, tileAltCol, tilesBlend),
texture(tilesAtlas, finalUVCoordForBreakage), texture(tilesAtlas, finalUVCoordForBreakage)
texture(tilesAtlas, finalUVCoordForBlurmap) // texture(tilesAtlas, finalUVCoordForBlurmap)
); );
} }
@@ -178,20 +178,20 @@ void main() {
vec4[] tile_breakage_blur = getFragColorForOnscreenCoord(fragCoord); vec4[] tile_breakage_blur = getFragColorForOnscreenCoord(fragCoord);
vec4 tileC = tile_breakage_blur[0]; vec4 tileC = tile_breakage_blur[0];
vec4 tileL = getFragColorForOnscreenCoord1(fragCoord + blurL); // vec4 tileL = getFragColorForOnscreenCoord1(fragCoord + blurL);
vec4 tileR = getFragColorForOnscreenCoord1(fragCoord + blurR); // vec4 tileR = getFragColorForOnscreenCoord1(fragCoord + blurR);
vec4 tileU = getFragColorForOnscreenCoord1(fragCoord + blurU); // vec4 tileU = getFragColorForOnscreenCoord1(fragCoord + blurU);
vec4 tileD = getFragColorForOnscreenCoord1(fragCoord + blurD); // vec4 tileD = getFragColorForOnscreenCoord1(fragCoord + blurD);
vec4 blurH = (tileC + tileL + tileR) * _three; // vec4 blurH = (tileC + tileL + tileR) * _three;
vec4 blurV = (tileC + tileU + tileD) * _three; // vec4 blurV = (tileC + tileU + tileD) * _three;
vec4 blurPower = tile_breakage_blur[2]; // vec4 blurPower = tile_breakage_blur[2];
vec4 finalTile = mix( vec4 finalTile = tileC;//mix(
mix(tileC, blurH, blurPower.x), // mix(tileC, blurH, blurPower.x),
mix(tileC, blurV, blurPower.y), // mix(tileC, blurV, blurPower.y),
0.5 // 0.5
); // );
vec4 finalBreakage = drawBreakage * tile_breakage_blur[1]; // drawBreakeage = 0 to not draw, = 1 to draw vec4 finalBreakage = drawBreakage * tile_breakage_blur[1]; // drawBreakeage = 0 to not draw, = 1 to draw