Weird lines appearing above low res sprites

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nayala

Hello !

I need some help about weird lines appearing above sprites. I can’t figure out what they are or what I need to do to remove them.

My scene consists of sprites (12px/10px) arranged in an hexagonal grid like that (with debug lines) :

hex grid

Really rarely when I move the camera and zoom weird lines appear, here an horizontal line :

lines

Script attached to the camera :

extends Camera2D

const MAX_ZOOM_LEVEL = 0.25
const MIN_ZOOM_LEVEL = 2.0
const ZOOM_PERCENT = 0.02

signal moved()
signal zoomed()

var _current_zoom_level = 1
var _drag = false

func _input(event):
	if event.is_action_pressed("cam_drag"):
		_drag = true
	elif event.is_action_released("cam_drag"):
		_drag = false
	elif event.is_action("cam_zoom_in"):
		_update_zoom(1-ZOOM_PERCENT, get_local_mouse_position())
	elif event.is_action("cam_zoom_out"):
		_update_zoom(1+ZOOM_PERCENT, get_local_mouse_position())
	elif event is InputEventMouseMotion && _drag:
		set_offset(get_offset() - event.relative * _current_zoom_level)
		emit_signal("moved")

func _update_zoom(percent, zoom_anchor):
	var old_zoom = _current_zoom_level
	_current_zoom_level *= percent
	if _current_zoom_level < MAX_ZOOM_LEVEL:
		_current_zoom_level = MAX_ZOOM_LEVEL
	elif _current_zoom_level > MIN_ZOOM_LEVEL:
		_current_zoom_level = MIN_ZOOM_LEVEL
	if old_zoom == _current_zoom_level:
		return
	var zoom_center = zoom_anchor - get_offset()
	var ratio = 1-_current_zoom_level/old_zoom
	set_offset(get_offset() + zoom_center*ratio) 
	set_zoom(Vector2(_current_zoom_level, _current_zoom_level))
	emit_signal("zoomed")

Stretch settings are 2d Mode and ignore Aspect.
I use default settings when importing my sprites (expect removing filtering).

So where do these lines come from ? I’ve tried using bigger sprites (48px/40px) and lines aren’t appearing.
Is it linked to pixel-perfect stuff or settings when importing sprites ?

I would really appreciate if someone can figure it out. :slight_smile:

My first thought was pixel snapping. Do you have Use Pixel Snap set to On in the settings? Rendering > Quality > Use Pixel Snap.

I’d also try importing the art using 2D Pixel preset.

i_love_godot | 2019-01-27 13:10

If you are using a TileMap, enable YSort

fpicoral | 2019-01-27 13:50

It’s way worse setting Use Pixel Snap to On :

enter image description here

Importing using 2D Pixel preset did nothing.

And i’m not using TileMap, I place each sprite for more control. (Positions are integer values)

nayala | 2019-01-27 14:53

Is it just the image, or are some lines blurry and some sharp?

i_love_godot | 2019-01-27 14:59

All the lines are sharp and they appear when I zoom with the camera (independant from the camera’s position).
As shown below different zoom levels make different lines :

enter image description here

nayala | 2019-01-27 15:18

Do the lines appear if you use integer zoom values?

i_love_godot | 2019-01-27 15:35

Zoom values aren’t integer values, since 2x zoom corresponds to set_zoom(Vector2(0.5, 0.5)) on my camera.

nayala | 2019-01-27 15:47

Yes but have you tried integer values to see if the lines still appear?

i_love_godot | 2019-01-27 16:06

Lines appear even with zoom Vector(2, 2)

nayala | 2019-01-27 16:16

I’m out of ideas I’m afraid. Hopefully someone will chip in and help you figure this out :slight_smile:

i_love_godot | 2019-01-27 17:01

No problem, thanks a lot. <3

nayala | 2019-01-27 17:16

:bust_in_silhouette: Reply From: Perasha

I have the same exact issue with my isometric pixelated tiles. A very simple fix that I found was to increase the scale of the tiles by 0.001. Not the perfect fix but so far it seems to get rid of the lines without disturbing the conformity of the tiles themselves.

I know this is an old post but I figured I’d share my findings anyway.

:bust_in_silhouette: Reply From: Scott_Chinchen

I recently encountered this same issue and the other answer provided here wasn’t sufficient to resolve it (Godot 3.0.5). I found another workaround and have a potential explanation.

The root cause of this issue appears to be an interaction between texture flags 1 (FLAG_MIPMAPS) and 2 (FLAG_REPEAT) combined with a scaled object (in my test case, a sprite).

To fix the issue, set the sprite.texture.flags property to remove either of these flags (I recommend either 5 or 6 as the default is 7). For example: get_node("Sprite").texture.flags = 5
or
get_node("Sprite").texture.flags = Texture.FLAG_MIPMAPS | Texture.FLAG_FILTER