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

Fix sprite crunch at half-pixels #86670

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 16 additions & 1 deletion drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,22 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend

if (c->type != Item::Command::TYPE_MESH) {
// For Meshes, this gets updated below.
_update_transform_2d_to_mat2x3(base_transform * draw_transform, state.instance_data_array[r_index].world);
Transform2D final_transform = base_transform * draw_transform;

// Make sure to round nearest filtered textures to avoid sprite "crunching".
// We don't round linear filtered textures because it would look identical to nearest filtering.
switch (p_item->texture_filter) {
adamscott marked this conversation as resolved.
Show resolved Hide resolved
case RS::CanvasItemTextureFilter::CANVAS_ITEM_TEXTURE_FILTER_NEAREST:
case RS::CanvasItemTextureFilter::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:
case RS::CanvasItemTextureFilter::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC: {
final_transform.set_origin(final_transform.get_origin().round());
} break;
default: {
// Do nothing.
}
}

_update_transform_2d_to_mat2x3(final_transform, state.instance_data_array[r_index].world);
}

// Zero out most fields.
Expand Down
14 changes: 14 additions & 0 deletions servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend

PushConstant push_constant;
Transform2D base_transform = p_canvas_transform_inverse * p_item->final_transform;

// Make sure to round nearest filtered textures to avoid sprite "crunching".
// We don't round linear filtered textures because it would look identical to nearest filtering.
switch (p_item->texture_filter) {
case RS::CanvasItemTextureFilter::CANVAS_ITEM_TEXTURE_FILTER_NEAREST:
case RS::CanvasItemTextureFilter::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:
case RS::CanvasItemTextureFilter::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC: {
base_transform.set_origin(base_transform.get_origin().round());
} break;
default: {
// Do nothing.
}
}

Transform2D draw_transform;
_update_transform_2d_to_mat2x3(base_transform, push_constant.world);

Expand Down
Loading