Skip to content

Commit

Permalink
Fixed blocks UV
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 12, 2023
1 parent 33b61fb commit 8161d84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/graphics/BlocksRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ vec4 BlocksRenderer::pickSoftLight(int x, int y, int z, ivec3 right, ivec3 up) c
// Get texture atlas UV region for block face
inline UVRegion uvfor(const Block& def, uint face, int atlas_size) {
float uvsize = 1.0f / (float)atlas_size;
float us = 0.0097; // TODO: replace with correct calculations (including 0.36)
float us = 1.0f / (float)atlas_size / (float)atlas_size * ATLAS_MARGIN_SIZE * 0.8f;
const uint id = def.textureFaces[face];
float u = (id % atlas_size) * uvsize;
float v = 1.0f - (id / atlas_size + 1) * uvsize;
return UVRegion(u+us, v+us, u + uvsize - us * 0.36f, v + uvsize - us * 0.36f);
return UVRegion(u+us, v+us, u + uvsize - us, v + uvsize - us);
}

void BlocksRenderer::render(const voxel* voxels, int atlas_size) {
Expand Down
6 changes: 4 additions & 2 deletions src/graphics/ImageData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ ImageData* add_atlas_margins(ImageData* image, int grid_size) {
if (srcdata[((soy+ly) * srcwidth + sox + lx) * 4 + 3]) {
for (int c = 0; c < 3; c++) {
int val = srcdata[((soy+ly) * srcwidth + sox + lx) * 4 + c];
dstdata[((doy+ly) * dstwidth + dox + lx + 1) * 4 + c] = val;
dstdata[((doy+ly + 1) * dstwidth + dox + lx) * 4 + c] = val;
if (dstdata[((doy+ly) * dstwidth + dox + lx + 1) * 4 + 3] == 0)
dstdata[((doy+ly) * dstwidth + dox + lx + 1) * 4 + c] = val;
if (dstdata[((doy+ly + 1) * dstwidth + dox + lx) * 4 + 3] == 0)
dstdata[((doy+ly + 1) * dstwidth + dox + lx) * 4 + c] = val;
}
}
}
Expand Down

0 comments on commit 8161d84

Please sign in to comment.