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

Scaled centred sprites are skewed with pixel snap #60443

Open
jusw85 opened this issue Apr 22, 2022 · 3 comments
Open

Scaled centred sprites are skewed with pixel snap #60443

jusw85 opened this issue Apr 22, 2022 · 3 comments

Comments

@jusw85
Copy link

jusw85 commented Apr 22, 2022

Godot version

3.4.4

System information

Arch Linux

Issue description

Related #42985

quality/2d/use_pixel_snap=true
2d/snapping/use_gpu_pixel_snap=true

Import a 1x1 sprite
centred=true
scale=(1, 1)

capture_005_23042022_024031

As expected.

centred=true
scale=(32,32)

capture_004_23042022_024014

Is this intended behaviour? The sprite origin is on the bottom right of the sprite instead of the centre of the scaled sprite. I expected the 32x32 sprite to be centred, with sprite origin at it's centre i.e. the sprite should be centred after being scaled.

This issue does not happen with textures with even dimensions.

Steps to reproduce

N.A.

Minimal reproduction project

TestPixelSnap2.zip

@lawnjelly
Copy link
Member

lawnjelly commented Apr 23, 2022

Have limited time today, but this seems to have been the behaviour back to at least 3.2, possibly since GPU snap was first added.

I was kind of guessing that possibly the snap was being done before the scale was applied, but that doesn't seem to be the case in the shader (I may be missing something though). Anyone else that wants to look into this is welcome BTW.

EDIT: Ah there is also a snap in the CPU code it looks like from #42985 . Maybe this issue should be closed as a duplicate?

@jusw85
Copy link
Author

jusw85 commented Apr 23, 2022

Maybe this issue should be closed as a duplicate?

Yes, I see this issue as more of the root cause, while #42985 is a bug caused by this. Perhaps #42985 could be closed while this issue is used as the tracking issue.

@kleonc
Copy link
Member

kleonc commented Apr 23, 2022

I think this shouldn't be there at all:

godot/scene/2d/sprite.cpp

Lines 102 to 104 in 3ba9803

if (Engine::get_singleton()->get_use_gpu_pixel_snap()) {
dest_offset = dest_offset.floor();
}

GPU pixel snapping should be applied after all transformations are applied (so in the shader), there's no point to apply it locally (r_dst_rect in Sprite::_get_rects is local). Transforms are applied later when drawing (by the VisualServer based on the CanvasItem passed to Texture::draw_rect_region):

godot/scene/2d/sprite.cpp

Lines 118 to 133 in 3ba9803

case NOTIFICATION_DRAW: {
if (texture.is_null()) {
return;
}
RID ci = get_canvas_item();
/*
texture->draw(ci,Point2());
break;
*/
Rect2 src_rect, dst_rect;
bool filter_clip;
_get_rects(src_rect, dst_rect, filter_clip);
texture->draw_rect_region(ci, dst_rect, src_rect, Color(1, 1, 1), false, normal_map, filter_clip);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants