mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-10 22:01:52 +09:00
camera moving works
This commit is contained in:
@@ -13,7 +13,7 @@ uniform sampler2D u_texture;
|
||||
|
||||
|
||||
uniform vec2 screenDimension;
|
||||
uniform vec2 tilesInAxes;
|
||||
uniform vec2 tilesInAxes; // vec2(tiles_in_horizontal, tiles_in_vertical)
|
||||
|
||||
uniform ivec2 tilemapDimension;
|
||||
uniform sampler2D tilemap; // MUST be RGBA8888
|
||||
@@ -25,7 +25,6 @@ uniform ivec2 tileInAtlas = ivec2(256, 256);
|
||||
uniform ivec2 atlasTexSize = ivec2(4096, 4096);
|
||||
|
||||
|
||||
//uniform vec2 tileInDim; // vec2(tiles_in_horizontal, tiles_in_vertical)
|
||||
uniform vec2 cameraTranslation = vec2(0, 0); // Y-flipped
|
||||
uniform int tileSizeInPx = 16;
|
||||
|
||||
@@ -46,15 +45,12 @@ void main() {
|
||||
// Make sure you don't use gl_FragCoord unknowingly! //
|
||||
|
||||
|
||||
// FIXME: cameraTranslation not working as it should
|
||||
|
||||
|
||||
// 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 pxCoord = flippedFragCoord.xy + cameraTranslation;
|
||||
vec2 pxCoord = flippedFragCoord.xy;
|
||||
|
||||
mediump vec4 tileFromMap = texture2D(tilemap, flippedFragCoord / overscannedScreenDimension); // <- THE CULPRIT
|
||||
int tile = getTileFromColor(tileFromMap);
|
||||
@@ -65,10 +61,10 @@ void main() {
|
||||
|
||||
vec2 coordInTile = mod(pxCoord, tileSizeInPx) / tileSizeInPx; // 0..1 regardless of tile position in atlas
|
||||
|
||||
highp vec2 singleTileSizeInUV = vec2(1) / tileInAtlas; // 0.00390625
|
||||
highp vec2 singleTileSizeInUV = vec2(1) / tileInAtlas; // 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 uvCoordOffset = (tileXY + cameraTranslation / tileSizeInPx) * 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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user