Godot Shaders & Visual Shaders

🌈 Godot Shading Language: CanvasItem & Spatial Shaders

Godot features a custom GLSL-like shading language with built-in render modes, automatic PBR lighting hooks, and fast spatial transforms.


🏛️ Shader Types in Godot 4

Shader Type Target Node Key Functions
shader_type spatial; 3D Meshes (MeshInstance3D) vertex(), fragment(), light()
shader_type canvas_item; 2D Sprites & UI (Sprite2D, Control) vertex(), fragment(), light()
shader_type particles; Particle systems (GPUParticles3D/2D) start(), process()
shader_type sky; Procedural skyboxes sky()

💻 1. 2D Hologram / Shield Hit Shader

shader_type canvas_item;

uniform vec4 shield_color : source_color = vec4(0.0, 0.8, 1.0, 1.0);
uniform float scanline_speed = 3.0;
uniform float scanline_count = 50.0;

void fragment() {
    vec4 base_tex = texture(TEXTURE, UV);
    
    // Scanline wave modulation
    float scanline = sin(UV.y * scanline_count + TIME * scanline_speed);
    scanline = smoothstep(0.2, 0.8, scanline);
    
    COLOR = base_tex * shield_color;
    COLOR.a *= (0.5 + 0.5 * scanline);
}