Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue where interpolation can cause the wrong tile to be rendered. #279

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/render/shaders/tilemap.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ var<uniform> tilemap_data: TilemapData;
#include 0

struct VertexOutput {
@location(0) uv: vec3<f32>,
@location(0) uv: vec2<f32>,
@location(1) color: vec4<f32>,
@location(2) @interpolate(flat) tile_id: f32,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally we could just use a u32 here. 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah why not use integers? that seems like the best way to ensure everything is correct

@builtin(position) position: vec4<f32>,
};

Expand Down Expand Up @@ -122,7 +123,8 @@ fn vertex(
x4[u32(vertex_uv.y)]
);

out.uv = vec3<f32>(atlas_uvs[v_index % 4u], f32(texture_index));
out.uv = vec2<f32>(atlas_uvs[v_index % 4u]);
out.tile_id = f32(texture_index);
// out.uv = out.uv + 1e-5;
out.position = view.view_proj * mesh_data.world_position;
out.color = color;
Expand All @@ -136,7 +138,7 @@ var sprite_sampler: sampler;

@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
var color = textureSample(sprite_texture, sprite_sampler, in.uv.xy, i32(in.uv.z)) * in.color;
var color = textureSample(sprite_texture, sprite_sampler, in.uv.xy, i32(round(in.tile_id))) * in.color;
if (color.a < 0.001) {
discard;
}
Expand Down