drawing of the tile breakage

This commit is contained in:
minjaesong
2018-11-10 21:09:02 +09:00
parent 1aa90077a4
commit 8942f352a1
6 changed files with 58 additions and 28 deletions

View File

@@ -34,10 +34,23 @@ ivec2 getTileXY(int tileNumber) {
return ivec2(tileNumber % int(tilesInAtlas.x), tileNumber / int(tilesInAtlas.x));
}
int getTileFromColor(vec4 color) {
// return: int=0xrrggbb
int _colToInt(vec4 color) {
return int(color.b * 255) | (int(color.g * 255) << 8) | (int(color.r * 255) << 16);
}
// 0x0rggbb where int=0xaarrggbb
// return: [0..1048575]
int getTileFromColor(vec4 color) {
return _colToInt(color) & 0x0FFFFF;
}
// 0xr00000 where int=0xaarrggbb
// return: [0..15]
int getBreakageFromColor(vec4 color) {
return (_colToInt(color) >> 20) & 0xF;
}
void main() {
// READ THE FUCKING MANUAL, YOU DONKEY !! //
@@ -54,28 +67,31 @@ void main() {
mediump vec4 tileFromMap = texture2D(tilemap, flippedFragCoord / overscannedScreenDimension); // <- THE CULPRIT
int tile = getTileFromColor(tileFromMap);
int breakage = getBreakageFromColor(tileFromMap);
ivec2 tileXY = getTileXY(tile);
ivec2 breakageXY = getTileXY(breakage + 5);
vec2 coordInTile = mod(pxCoord, tileSizeInPx) / tileSizeInPx; // 0..1 regardless of tile position in atlas
highp vec2 singleTileSizeInUV = vec2(1) / tilesInAtlas; // constant 0.00390625
highp vec2 uvCoordForTile = coordInTile * singleTileSizeInUV; // 0..0.00390625 regardless of tile position in atlas
highp vec2 uvCoordOffset = tileXY * singleTileSizeInUV; // where the tile starts in the atlas, using uv coord (0..1)
highp vec2 uvCoordOffsetBreakage = breakageXY * singleTileSizeInUV;
highp vec2 finalUVCoordForTile = uvCoordForTile + uvCoordOffset;// where we should be actually looking for in atlas, using UV coord (0..1)
highp vec2 finalUVCoordForBreakage = uvCoordForTile + uvCoordOffsetBreakage;
// TODO blend a breakage (0xrrggbb where 0xr0 -- upper 4 bits of int_red component)
// TODO finally "blend" a breakage (0xrrggbb where 0xr00000 -- upper 4 bits of int_red component)
mediump vec4 finalTile = texture2D(tilesAtlas, finalUVCoordForTile);
mediump vec4 finalBreakage = texture2D(tilesAtlas, finalUVCoordForBreakage);
gl_FragColor = colourFilter * (mix(finalTile, finalBreakage, finalBreakage.a));
// if statements considered harmful (on shader program)
// --definitely not Dijkstra
/*if (tileXY.x == 0 && tileXY.y == 0)
gl_FragColor = nocolour;
else*/
gl_FragColor = colourFilter * texture2D(tilesAtlas, finalUVCoordForTile);
}

View File

@@ -216,7 +216,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
fun updateScreen(delta: Float) {
Gdx.graphics.setTitle(Ingame.getCanonicalTitle())
//Gdx.graphics.setTitle(Ingame.getCanonicalTitle())
demoWorld.globalLight = WeatherMixer.globalLightNow
demoWorld.updateWorldTime(delta)

View File

@@ -463,7 +463,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
Gdx.graphics.setTitle(getCanonicalTitle())
//Gdx.graphics.setTitle(getCanonicalTitle())
// ASYNCHRONOUS UPDATE AND RENDER //

View File

@@ -81,7 +81,8 @@ object PlayerBuilderSigrid {
Block.STONE_QUARRIED, Block.STONE_TILE_WHITE, Block.TORCH,
Block.DAYLIGHT_CAPACITOR, Block.ICE_FRAGILE,
Block.ILLUMINATOR_WHITE, Block.ILLUMINATOR_BLACK, Block.ILLUMINATOR_ORANGE,
Block.ILLUMINATOR_GREEN, Block.ILLUMINATOR_CYAN, Block.SUNSTONE
Block.ILLUMINATOR_GREEN, Block.ILLUMINATOR_CYAN, Block.SUNSTONE,
Block.ORE_COPPER
)
val walls = arrayOf(
Block.AIR, Block.DIRT, Block.GLASS_CRUDE,

View File

@@ -179,7 +179,14 @@ internal object BlocksDrawer {
Block.ILLUMINATOR_TAN_OFF,
Block.ILLUMINATOR_WHITE_OFF,
Block.ILLUMINATOR_YELLOW,
Block.DAYLIGHT_CAPACITOR
Block.DAYLIGHT_CAPACITOR,
Block.ORE_COPPER,
Block.ORE_IRON,
Block.ORE_GOLD,
Block.ORE_SILVER,
Block.ORE_ILMENITE,
Block.ORE_AURICHALCUM
)
/**
@@ -216,12 +223,6 @@ internal object BlocksDrawer {
Block.SNOW,
Block.ICE_NATURAL,
Block.ICE_MAGICAL,
Block.ORE_COPPER,
Block.ORE_IRON,
Block.ORE_GOLD,
Block.ORE_SILVER,
Block.ORE_ILMENITE,
Block.ORE_AURICHALCUM,
Block.SANDSTONE,
Block.SANDSTONE_BLACK,
@@ -499,20 +500,28 @@ internal object BlocksDrawer {
val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE
val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y)
val maxHealth = BlockCodex[world.getTileFromTerrain(x, y)].strength
val breakingStage = (breakage / maxHealth).times(breakAnimSteps).roundInt()
// draw a tile
if (drawModeTilesBlendMul) {
// while iterating through, only the some tiles are actually eligible to be drawn as MUL,
// so obviously when we caught not eligible tile, we need to skip that by marking as Tile No. zero
if (isBlendMul(thisTile)) {
writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY)
writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY, breakingStage)
}
else {
writeToBuffer(mode, x - for_x_start, y - for_y_start, 0, 0)
writeToBuffer(mode, x - for_x_start, y - for_y_start, 0, 0, 0)
}
}
else {
// do NOT add "if (!isBlendMul(thisTile))"!
// or else they will not look like they should be when backed with wall
writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY)
writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY, breakingStage)
}
// draw a breakage
@@ -664,13 +673,17 @@ internal object BlocksDrawer {
*
* @return Raw colour bits in RGBA8888 format
*/
private fun sheetXYToTilemapColour(mode: Int, sheetX: Int, sheetY: Int): Int = when (mode) {
TERRAIN, WALL -> (tilesTerrain.horizontalCount * sheetY + sheetX).shl(8) or 255
WIRE -> (tilesWire.horizontalCount * sheetY + sheetX).shl(8) or 255
private fun sheetXYToTilemapColour(mode: Int, sheetX: Int, sheetY: Int, breakage: Int): Int = when (mode) {
// the tail ".or(255)" is there to write 1.0 to the A channel (remember, return type is RGBA)
TERRAIN, WALL ->
(tilesTerrain.horizontalCount * sheetY + sheetX).shl(8).or(255) or // the actual tile bits
breakage.and(15).shl(28) // breakage bits
WIRE -> (tilesWire.horizontalCount * sheetY + sheetX).shl(8).or(255)
else -> throw IllegalArgumentException()
}
private fun writeToBuffer(mode: Int, bufferPosX: Int, bufferPosY: Int, sheetX: Int, sheetY: Int) {
private fun writeToBuffer(mode: Int, bufferPosX: Int, bufferPosY: Int, sheetX: Int, sheetY: Int, breakage: Int) {
val sourceBuffer = when(mode) {
TERRAIN -> terrainTilesBuffer
WALL -> wallTilesBuffer
@@ -679,7 +692,7 @@ internal object BlocksDrawer {
}
sourceBuffer[bufferPosY][bufferPosX] = sheetXYToTilemapColour(mode, sheetX, sheetY)
sourceBuffer[bufferPosY][bufferPosX] = sheetXYToTilemapColour(mode, sheetX, sheetY, breakage)
}
private fun renderUsingBuffer(mode: Int, projectionMatrix: Matrix4) {

Binary file not shown.