Browse Source

fix tile atlas stuff 2: fix harder

feature/replace-renderer
Martin Dørum 3 years ago
parent
commit
c76c0e01b1
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      libcygnet/src/shaders.cc

+ 7
- 2
libcygnet/src/shaders.cc View File

@@ -12,7 +12,11 @@ const char *spriteVx = R"glsl(
varying vec2 v_texCoord;

void main() {
float pixoffset = (1.0 - vertex.y * 2.0) / (TILE_SIZE * frameInfo.x * 2.0);
// Here, I'm basically treating 1/(TILE_SIZE*16) as half the size of a "pixel".
// It's just an arbitrary small number, but it works as an offset to make sure
// neighbouring parts of the atlas don't bleed into the frame we actually
// want to draw due to (nearest neighbour) interpolation.
float pixoffset = (1.0 - vertex.y * 2.0) / (frameInfo.x * TILE_SIZE * 16.0);
v_texCoord = vec2(
vertex.x,
(frameInfo.x * frameInfo.z + (frameInfo.x * vertex.y)) /
@@ -62,8 +66,9 @@ const char *chunkFr = R"glsl(
vec4 tileColor = texture2D(tiles, tilePos / vec2(CHUNK_WIDTH, CHUNK_HEIGHT));
float tileID = floor((tileColor.r * 256.0 + tileColor.a) * 256.0);

// 1/(TILE_SIZE*16) plays the same role here as in the sprite vertex shader.
vec2 offset = v_tileCoord - tilePos;
vec2 pixoffset = (1.0 - offset * 2.0) / (TILE_SIZE * 2.0);
vec2 pixoffset = (1.0 - offset * 2.0) / (TILE_SIZE * 16.0);
vec2 atlasPos = vec2(
pixoffset.x + tileID + offset.x,
pixoffset.y + floor(tileID / tileAtlasSize.x) + offset.y);

Loading…
Cancel
Save