Shaders
Various Godot shader info
Also check the shader section of this manual!
Knowhow
Tiling and offset
This can be easily archived:
uniform sampler2D texture_albedo:
source_color,
filter_linear_mipmap,
repeat_disable; // repeat_enable for looping texture
uniform vec2 tiling = vec2(1.0, 1.0);
uniform vec2 offset;
void vertex() {
UV = UV * tiling + offset * TIME; // Time for animated, remove for static
}
Masking
Simply multiply the alpha with another texture (one channel, for example red):
ALPHA *= texture(mask, UV).r; // take red intensity as mask
ALPHA *= UV.r; // represents a horizontal gradient
ALPHA *= UV.g; // represents a vertical gradient
Distortion
Simply add a displacement texture to the UV
float noise_val = texture(noise_texture, UV).r;
vec2 distortion_uv = UV + noise_tex * distortion_intensity;
Particle shading
Particle age can be used in the shader via
varying float lifetime;
void vertex() {
lifetime = INSTANCE_CUSTOM.y;
}
A fade in and out effect can be created via
varying float life_time; // the actual age
varying float life_alpha; // the age faded in and out
void vertex() {
life_time = INSTANCE_CUSTOM.y;
if (life_time<fade_in){
life_alpha = 1.0 - abs( lifetime - fade_in ) / fade_in;
}
else
{
life_alpha = 1.0 - ( lifetime - fade_in ) / (1.0 - fade_in);
}
}
Remap between two values (not pretty)
final_color.a = clamp((clamp(tex.a * life_alpha, .5-cutoff_range, .5+cutoff_range) - .5 + cutoff_range) / cutoff_range, 0.0, 1.0);
Time
Time is a global built-in. (No idea why those are located in the fog shader ref)
It repeats after every 3,600 seconds (which can be changed with the rollover setting). It's affected by time_scale but not by pausing.
COLOR.a = smoothstep(end_time, start_time, TIME);
Screen Space Render
from Reddit
There is simply no option for implementing a full screen shader or a shader that utilizes screen-space without doing some janky nonsense to make it work
You can follow this documentation page to setup a quad or just a triangle mesh and apply a screen space shader.
There's also a new CompositorEffect API is available in Godot 4.3 for screen-space shaders. You'll be able to hook to the different rendering passes Godot does.
If I want to apply a post-processing effect to a group of objects without applying it to other objects
If it's in 2D you can use a CanvasGroup In 3D you still need to use a SubViewport as far as I can see.
let's say I want to always render a player's gun in front of their view model.
You can use a shader for that no need to use viewports. More info here (Twitter) and here (Youtube).
Public available custom shaders
GodotShaders.com: Great resource for shaders!
| Shader | Notes |
|---|---|
| Terrain Layered Shader | create large terrains on premade meshes using tiling textures. Youtube Tutorial |
| Additive Linear Volume | Simple method for volumetric lighting effects |
| Standard Lighting Shader Include | to simplify writing custom light functions. |
| Parallax Mapping | For portal effects |
Addons
Acerola Compute by Acerola. Abstraction Layer for Godot shaders.
Tutorials / Knowhow
AcerolaFX by Acerola:
Simplifying Shaders by Acerola. Github Project