Better way of zooming low res backgrounds?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stillinthe90s
:warning: Old Version Published before Godot 3 was released.

I’m using a work-around to display 320x200 backgrounds without pixel deformation, in a 2d game. (Game display width & height is also 320x200)
Simplified script:

func _ready():
 OS.set_window_fullscreen(true)
 get_tree().set_screen_stretch(2,1,Vector2(1280,800))
 Camera2D.set_zoom(Vector2(0.25,0.25))
 Camera2D.set_pos(Vector2(320/2,200/2-(ydiff/8)))
 GUILayer.set_scale(Vector2(4,4))
 get_node("/root").set_render_target_filter(true)

This makes shaders turn black when stretching above screen size (in my case 1366x768) which is problematic since fullscreen needs 4x zoom (1280x800) in order to scale pixels properly.
Stretching it to 1280x[screenheight] will get shaders working again but that will also cut off bits of the background and requires moving the GUI.
Can anyone think of a better way of doing this?

Where and how are you writing your shaders? What do you want to achieve?

Zylann | 2016-11-26 22:41

I’m not entirely sure what you mean but the shader I am using (although the black effect occurs with other shaders as well) is the BCS script shader from the screen_shaders demo:

uniform float brightness=0.8;
uniform float contrast=1.5;
uniform float saturation=1.8;

vec3 c = texscreen(SCREEN_UV);

c.rgb = mix(vec3(0.0),c.rgb,brightness);
c.rgb = mix(vec3(0.5),c.rgb,contrast);
c.rgb = mix(vec3(dot(vec3(1.0),c.rgb)*0.33333),c.rgb,saturation);

COLOR.rgb=c;

Adding the shader to different types of nodes (sprites, texture frames, texture buttons etc.) or in different canvas layers makes no difference. (Note that it does, in fact, work when stretching within the actual screen resolution.)

The work-around described in my original post is needed to display the pixel art without distorted or skewed pixels. The shader is intended to allow brightness settings.

stillinthe90s | 2016-11-27 12:25