mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-14 15:46:06 +09:00
now I can't even tell if it's working as intended or not
This commit is contained in:
@@ -24,11 +24,15 @@ uniform sampler2D backgroundTexture;
|
||||
uniform ivec2 tilesInAtlas = ivec2(256, 256);
|
||||
uniform ivec2 atlasTexSize = ivec2(4096, 4096);
|
||||
|
||||
uniform vec4 colourFilter = vec4(1, 1, 1, 1);
|
||||
|
||||
uniform vec2 cameraTranslation = vec2(0, 0); // Y-flipped
|
||||
uniform ivec2 cameraTranslation = ivec2(0, 0);
|
||||
uniform int tileSizeInPx = 16;
|
||||
|
||||
|
||||
vec4 nocolour = vec4(0,0,0,0);
|
||||
|
||||
|
||||
ivec2 getTileXY(int tileNumber) {
|
||||
return ivec2(tileNumber % int(tilesInAtlas.x), tileNumber / int(tilesInAtlas.x));
|
||||
}
|
||||
@@ -47,7 +51,7 @@ 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; // one used by the tileFromMap
|
||||
vec2 flippedFragCoord = vec2(gl_FragCoord.x, screenDimension.y - gl_FragCoord.y); // NO IVEC2!!; this flips Y
|
||||
vec2 flippedFragCoord = vec2(gl_FragCoord.x, screenDimension.y - gl_FragCoord.y) + cameraTranslation; // NO IVEC2!!; this flips Y
|
||||
|
||||
vec2 pxCoord = flippedFragCoord.xy;
|
||||
|
||||
@@ -63,10 +67,13 @@ void main() {
|
||||
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 + cameraTranslation / tileSizeInPx) * singleTileSizeInUV; // where the tile starts in the atlas, using uv coord (0..1)
|
||||
highp vec2 uvCoordOffset = tileXY * singleTileSizeInUV; // where the tile starts in the atlas, using uv coord (0..1)
|
||||
|
||||
highp vec2 finalUVCoordForTile = uvCoordForTile + uvCoordOffset;// where we should be actually looking for in atlas, using UV coord (0..1)
|
||||
|
||||
|
||||
gl_FragColor = v_color * texture2D(tilesAtlas, finalUVCoordForTile);
|
||||
if (tileXY.x == 0 && tileXY.y == 0)
|
||||
gl_FragColor = nocolour;
|
||||
else
|
||||
gl_FragColor = colourFilter * texture2D(tilesAtlas, finalUVCoordForTile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user