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

Blurred sprite after movement #66527

Closed
Tracked by #86837
lorenzo-arena opened this issue Sep 28, 2022 · 13 comments
Closed
Tracked by #86837

Blurred sprite after movement #66527

lorenzo-arena opened this issue Sep 28, 2022 · 13 comments

Comments

@lorenzo-arena
Copy link

lorenzo-arena commented Sep 28, 2022

Godot version

4.0-beta1

System information

PopOS 22.04, Ryzen 3700U Vega 10 iGPU

Issue description

I'm trying to make a simple 2D pixel art movement; I have a sprite against a background and the sprite can be moved only sideways. Sometimes, but not always, after a movement when the pumpkin stops it gets blurred as in the picture (it's not moving there). Sometimes instead it is sharp and clear. Filter settings for the texture are good for pixel art, which gets rendered correctly.

blurred

Steps to reproduce

I used a CharacterBody2D with a sprite node as a children. The body has a script attached to it to move:

extends CharacterBody2D

var speed := 100

func _physics_process(delta):
	var left_right = -Input.get_action_strength("ui_left") + Input.get_action_strength("ui_right")	
	position.x += left_right * speed * delta

Minimal reproduction project

godot-66527-minimal.zip

Production edit: added the MRP to the description.

@Zireael07
Copy link
Contributor

Floating point imprecision, I guess?

Delta is a floating point value and so is get_action_strength. Does floor() (or ceil() or casting to int()) fix the issue? You could also try snapping to grid via the toolbar button.

@Calinou
Copy link
Member

Calinou commented Sep 28, 2022

Related to #57221. This is a difficult problem to solve: #57221 (comment)

@lorenzo-arena Please upload a minimal reproduction project to make this easier to troubleshoot.

@lorenzo-arena
Copy link
Author

Here is a simple project which reproduces the problem:
godot-66527-minimal.zip

Floating point imprecision, I guess?

I also tried to see if rounding fixes the issue and in fact it does: using

position.x += round(left_right * speed * delta) as float

instead of

position.x += left_right * speed * delta

doesn't produce the issue anymore.

@lorenzo-arena
Copy link
Author

Also using move_and_slide causes the issue

@lorenzo-arena
Copy link
Author

@Calinou should this be solved (even when using move_and_slide) when setting both the snap options?

@clayjohn clayjohn added this to the 4.x milestone Feb 23, 2023
@clayjohn
Copy link
Member

@Calinou should this be solved (even when using move_and_slide) when setting both the snap options?

IMO the snap options should eliminate this artifact entirely.

@lorenzo-arena
Copy link
Author

To give a couple more informations on this.. In the reproduction project I use a structure like:

  • SubViewportContainer
    • SubViewport

where the viewport has the pixel art canvas size set as the size (256x144). Stretch mode is set to viewport, and the output resolution is set to 1280x720.

In other projects if I try to set stretch mode to viewport, window size to something low res like 256x144 and then the test size to 1280x720 the blurriness don't happen. Why is this happening? Shouldn't the viewport behave in the same way?

@Calinou
Copy link
Member

Calinou commented Feb 24, 2023

In other projects if I try to set stretch mode to viewport, window size to something low res like 256x144 and then the test size to 1280x720 the blurriness don't happen. Why is this happening? Shouldn't the viewport behave in the same way?

Using the viewport stretch mode on the root viewport uses nearest-neighbor filtering, while SubViewport will use bilinear filtering unless you override the option in the CanvasItem section of the SubViewport properties.

Also, the pixel snap options are set on a per-viewport basis. The project setting only affects the root viewport; you need to enable the pixel snap properties on the SubViewport if you wish it to behave the same way.

@lorenzo-arena
Copy link
Author

Actually snapping on the right viewport seems to work, yes. I have to snap the position; vertex snapping doesn't seem to have any effect.

@dewald-els
Copy link

I'm not sure this is still relevant, but in Godot 4, switching the stretch mode to canvas_items completely removed the blurry sprites while using move_and_slide.

@lorenzo-arena
Copy link
Author

@dewald-els this is true but using canvas_items allows for subpixel positioning, which is incompatible with a real "pixel perfect" aspect

@69ShadesOfPeanut
Copy link

I'm now experiencing this issue and been searching for ages for a way to fix it

@clayjohn
Copy link
Member

I took a look at this locally and it turns out that the Viewport was mistakenly configured use linear for the default filter. The pumpkin is configured to inherit the default value while the wall is set to use nearest.

Setting the pumpkin to use nearest or setting the default to nearest makes the issue go away

@clayjohn clayjohn removed this from the 4.x milestone Sep 21, 2024
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

6 participants