0 votes

Hey guys, just a quick question, as I really don't understand shaders, and last time I used them was in 2.1, I was wondering what is the alternative for the no more existent function texscreen() which was used to read screen with Vec2 parameter.

I have a chromatic aberration shader hacked together from multiple sources from a few years prior that I'm hopelessly trying to fix because of this, anyone able to help?

shader_type canvas_item;

uniform float r_offset_x = -0.2;
uniform float r_offset_y = 0;
uniform float g_offset_x = 0;
uniform float g_offset_y = 0;
uniform float b_offset_x = 0.2;
uniform float b_offset_y = 0;

void fragment() {
 vec2 PixelSize = TEXTURE_PIXEL_SIZE;
 vec3 r_val;
 vec3 g_val;
 vec3 b_val;

 r_val = texscreen(SCREEN_UV + vec2(r_offset_x, r_offset_y) * PixelSize); 
 g_val = texscreen(SCREEN_UV + vec2(g_offset_x, g_offset_y) * PixelSize); 
 b_val = texscreen(SCREEN_UV + vec2(b_offset_x, b_offset_y) * PixelSize); 

 vec3 Chromatic_Aberration = vec3(r_val.r, g_val.g, b_val.b);

 COLOR.rgb = Chromatic_Aberration;
}
in Engine by (128 points)

1 Answer

+1 vote
Best answer

If you are writing a screen-reading shader, you may replace TEXTURE_PIXEL_SIZE by SCREEN_PIXEL_SIZE.
Also, replace texscreen by texture(SCREEN_TEXTURE, the_uv);

by (27,966 points)
selected by

First of all thank you very much, as this worked for the chromatic aberration, now I tried adding the pixelization effect from the official demos like this:

shader_type canvas_item;

uniform float size_x=0.005;
uniform float size_y=0.005;

uniform float r_offset_x = -0.2;
uniform float r_offset_y = 0;
uniform float g_offset_x = 0;
uniform float g_offset_y = 0;
uniform float b_offset_x = 0.2;
uniform float b_offset_y = 0;

void fragment() {
vec2 uv = SCREEN_UV;
uv-=mod(uv,vec2(size_x,size_y));

vec2 PixelSize = TEXTURE_PIXEL_SIZE;
vec4 r_val = texture(SCREEN_TEXTURE, uv + vec2(r_offset_x, r_offset_y) * PixelSize);
vec4 g_val = texture(SCREEN_TEXTURE, uv + vec2(g_offset_x, g_offset_y) * PixelSize);
vec4 b_val = texture(SCREEN_TEXTURE, uv + vec2(b_offset_x, b_offset_y) * PixelSize);

vec3 Chromatic_Aberration = vec3(r_val.r, g_val.g, b_val.b);

COLOR.rgb = Chromatic_Aberration;
//COLOR.rgb= textureLod(SCREEN_TEXTURE,uv,0.0).rgb;
}

But for some reason I get left with a weird screen tearing, as shown in picture attached.

enter image description here

Both of these shaders work great now separately but combining them creates this kinda mess :/. Can't get my head around this stuff somehow.

Scratch that, fixed it by using textureLod() function instead.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.