Loading...
Loading...
Write Godot 4.x shaders in the Godot Shading Language: canvas_item shaders for 2D and spatial shaders for 3D, with vertex/fragment functions, uniforms (source_color, hint_range), TIME/UV animation, and screen-reading via hint_screen_texture. Use when authoring .gdshader files, writing fragment/vertex code, making 2D/3D visual effects, or porting 3.x shaders (SCREEN_TEXTURE, hint_color) to 4.x.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills godot-shaderscanvas_itemspatialTIMEUVuniform.gdshaderShaderMaterialshader-programmingshader_type canvas_item;CanvasItemshader_type spatial;particlesskyfogShaderMaterialShaderMaterial.gdshadermaterialfragment()COLORALBEDOEMISSIONALPHAvertex()light()uniformsource_colorhint_rangeTIMEtexture(tex, UV)material.set_shader_parameter("name", value)shader_type canvas_item;
uniform vec4 tint : source_color = vec4(1.0); // source_color = sRGB-correct color
uniform float scroll_speed : hint_range(0.0, 2.0) = 0.3;
void fragment() {
vec2 uv = UV;
uv.x += TIME * scroll_speed; // scroll horizontally over time
COLOR = texture(TEXTURE, uv) * tint; // TEXTURE = the node's texture
}shader_type canvas_item;
uniform sampler2D noise : repeat_enable; // a NoiseTexture2D
uniform float amount : hint_range(0.0, 1.0) = 0.0;
void fragment() {
vec4 tex = texture(TEXTURE, UV);
float n = texture(noise, UV).r;
if (n < amount) {
discard; // cut the pixel away
}
COLOR = tex;
}shader_type spatial;
uniform vec4 base_color : source_color = vec4(0.2, 0.5, 1.0, 1.0);
uniform vec3 rim_color : source_color = vec3(0.6, 0.8, 1.0);
uniform float rim_power : hint_range(0.5, 8.0) = 3.0;
void fragment() {
ALBEDO = base_color.rgb;
// VIEW and NORMAL are view-space built-ins; rim is strong at grazing angles.
float rim = pow(1.0 - dot(NORMAL, VIEW), rim_power);
EMISSION = rim_color * rim;
}shader_type canvas_item;
// 4.x: declare the screen as a uniform with hint_screen_texture.
uniform sampler2D screen_tex : hint_screen_texture, filter_linear_mipmap;
uniform float blur : hint_range(0.0, 4.0) = 1.0;
void fragment() {
vec2 px = SCREEN_PIXEL_SIZE * blur;
vec4 c = texture(screen_tex, SCREEN_UV);
c += texture(screen_tex, SCREEN_UV + vec2(px.x, 0.0));
c += texture(screen_tex, SCREEN_UV - vec2(px.x, 0.0));
COLOR = c / 3.0;
}$Sprite2D.material.set_shader_parameter("amount", 0.7)SCREEN_TEXTUREuniform sampler2D x : hint_screen_texture;SCREEN_UVhint_colorsource_colorhint_albedohint_whitesource_colorhint_rangehint_depth_texturehint_normal_roughness_texturecanvas_itemCOLORspatialALBEDOEMISSIONALPHAROUGHNESSMETALLICCOLORsource_colorALPHA < 1.0repeat_enable: repeat_enableTIMEfract()mod()discardALPHACOLOR.avaryinglight()vertex()references/shading-language.mdshader-programminggodot-3d-essentialsgodot-ui-control