0 votes

how do i get and set the screen shader inside a gdscript function?
my plan is to change the gamma, ive seen some tutorials but im not sure how to get the screen shader atm

Godot version 3.2-stable
in Engine by (12 points)

2 Answers

0 votes

To access the shader parameters, use material.set_shader_param (" uniform_name ", value)
To make a shader that affects the entire screen, you have to have a node with an opaque color that covers the entire screen and is drawn last.
For example a ColorRect in the last position of the tree.
In the shader SCREEN_TEXTURE is used, this is the texture of everything that the node has behind. I leave you an example:


Node2d ---> whit script
---ColorRect ---> whit shader, cover all the screen


extends Node2D

func _ready():
    $ColorRect.material.set_shader_param("brightness", 1.4)
    $ColorRect.material.set_shader_param("contrast", 0.8)

ShaderMaterial in ColorRect:

shader_type canvas_item;

uniform float brightness = 1.0;
uniform float contrast = 1.0;
uniform float saturation = 1.0;

void fragment() {
    vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;

    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;
by (2,058 points)
0 votes

Godot Shading language has a special texture, SCREENTEXTURE (and DEPTHTEXTURE for depth, in the case of 3D). It takes as argument the UV of the screen and returns a vec3 RGB with the color. A special built-in varying: SCREENUV can be used to obtain the UV for the current fragment. As a result, this simple canvasitem fragment shader:

void fragment() {
results in an invisible object, because it just shows what lies behind.

The reason why textureLod must be used is because, when Godot copies back a chunk of the screen, it also does an efficient separatable gaussian blur to its mipmaps.

This allows for not only reading from the screen, but reading from it with different amounts of blur at no cost.NTGD Needle Valve

by (14 points)
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.