add slight texture inset for layer UVs.

This commit is contained in:
2025-09-13 12:28:37 -04:00
parent fe32c74967
commit 9afb845a36
4 changed files with 12 additions and 5 deletions

View File

@@ -65,6 +65,11 @@ struct Canvas
0, 1, uvMin.x, uvMax.y \ 0, 1, uvMin.x, uvMax.y \
} }
#define ATLAS_UV_MIN(type) (ATLAS_POSITION(type) / TEXTURE_ATLAS_SIZE)
#define ATLAS_UV_MAX(type) ((ATLAS_POSITION(type) + ATLAS_SIZE(type)) / TEXTURE_ATLAS_SIZE)
#define ATLAS_UV_ARGS(type) ATLAS_UV_MIN(type), ATLAS_UV_MAX(type)
#define ATLAS_UV_VERTICES(type) UV_VERTICES(ATLAS_UV_MIN(type), ATLAS_UV_MAX(type))
mat4 canvas_transform_get(Canvas* self, vec2 pan, f32 zoom, OriginType origin); mat4 canvas_transform_get(Canvas* self, vec2 pan, f32 zoom, OriginType origin);
void canvas_axes_draw(Canvas* self, GLuint& shader, mat4& transform, vec4& color); void canvas_axes_draw(Canvas* self, GLuint& shader, mat4& transform, vec4& color);
void canvas_bind(Canvas* self); void canvas_bind(Canvas* self);

View File

@@ -38,8 +38,9 @@ void generate_preview_draw(GeneratePreview* self)
const s32 column = index % columns; const s32 column = index % columns;
vec2 crop = startPosition + vec2(size.x * column, size.y * row); vec2 crop = startPosition + vec2(size.x * column, size.y * row);
vec2 uvMin = crop / vec2(texture.size); vec2 textureSize = vec2(texture.size);
vec2 uvMax = (crop + size) / vec2(texture.size); vec2 uvMin = (crop + vec2(0.5f)) / textureSize;
vec2 uvMax = (crop + size - vec2(0.5f)) / textureSize;
f32 vertices[] = UV_VERTICES(uvMin, uvMax); f32 vertices[] = UV_VERTICES(uvMin, uvMax);
mat4 generateTransform = transform * quad_model_get(size, {}, pivot); mat4 generateTransform = transform * quad_model_get(size, {}, pivot);

View File

@@ -134,8 +134,9 @@ void preview_draw(Preview* self)
Texture& texture = spritesheet->texture; Texture& texture = spritesheet->texture;
if (texture.isInvalid) return; if (texture.isInvalid) return;
vec2 uvMin = frame.crop / vec2(texture.size); vec2 inset = 0.5f / vec2(texture.size);
vec2 uvMax = (frame.crop + frame.size) / vec2(texture.size); vec2 uvMin = frame.crop / vec2(texture.size) + inset;
vec2 uvMax = (frame.crop + frame.size) / vec2(texture.size) - inset;
f32 vertices[] = UV_VERTICES(uvMin, uvMax); f32 vertices[] = UV_VERTICES(uvMin, uvMax);
canvas_texture_draw(&self->canvas, shaderTexture, texture.id, layerTransform, vertices, frameTint, frameColorOffset); canvas_texture_draw(&self->canvas, shaderTexture, texture.id, layerTransform, vertices, frameTint, frameColorOffset);