
Godot Shaders Basics
- 457 installs
- 454 repo stars
- Updated July 28, 2026
- thedivergentai/gd-agentic-skills
godot-shaders-basics is an agent skill that teaches Godot GLSL-like shader programming for canvas_item, spatial, and post-processing effects for developers who need custom VFX and stylized rendering.
About
godot-shaders-basics is a Godot agent skill from thedivergentai/gd-agentic-skills that provides an expert blueprint for shader programming with Godot's GLSL-like language. The skill bundles 12 expert .gdshader templates plus a shader_parameter_animator.gd script covering dissolve, hit flash, hex pixelate, terrain displacement, foliage wind, triplanar mapping, depth reconstruction, and Godot 4.3 Reversed-Z full-screen quads. A NEVER section documents 12 anti-patterns—avoid unconditional discard, dynamic if/else branching, exact float compares, and hardcoded POSITION for 4.3+ full-screen effects. Developers reach for godot-shaders-basics when implementing custom 2D or 3D visual effects, post-processing, material customization, or stylized rendering with uniforms, instance uniforms, and hint_screen_texture patterns.
- godot-shaders-basics
Godot Shaders Basics by the numbers
- 457 all-time installs (skills.sh)
- +30 installs in the week ending Aug 5, 2026 (Skillselion tracking)
- Ranked #939 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/thedivergentai/gd-agentic-skills --skill godot-shaders-basicsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 457 |
|---|---|
| repo stars | ★ 454 |
| Last updated | July 28, 2026 |
| Repository | thedivergentai/gd-agentic-skills ↗ |
How do you write Godot 2D and 3D shaders?
Use godot-shaders-basics for development tasks
Who is it for?
Godot developers adding custom 2D/3D shaders, post-processing, or stylized rendering who need template starting points and performance guardrails.
Skip if: Non-Godot engines or gameplay scripting tasks with no custom shader or material work.
When should I use this skill?
The user asks for Godot shaders, GLSL fragment or vertex effects, uniforms, canvas_item VFX, spatial materials, or post-processing in Godot 4.
What you get
Custom .gdshader files, ShaderMaterial setups, animated uniform parameters, and optimized VFX or post-processing effects
- Custom .gdshader files
- ShaderMaterial configurations
- Runtime uniform animation scripts
By the numbers
- Bundles 12 expert .gdshader templates plus 1 GDScript animator
- Documents 12 NEVER shader anti-patterns for Godot performance
Files
Shader Basics
Fragment/vertex shaders, uniforms, and built-in variables define custom visual effects.
Available Scripts
vfx_port_shader.gdshader
Expert shader template with parameter validation and common effect patterns.
shader_parameter_animator.gd
Runtime shader uniform animation without AnimationPlayer - for dynamic effects.
dissolve_scissor_expert.gdshader
High-performance mask-based dissolve. Uses ALPHA_SCISSOR to enable depth-prepass optimization and shadow casting.
instance_uniform_hitflash.gdshader
Batch-friendly hit effects. Uses instance uniform to allow thousands of unique flashes in one draw call.
screenspace_hex_pixelate.gdshader
Post-processing logic for stylizing screen output. Uses hint_screen_texture and optimized coordinate quantization.
noise_terrain_displacement.gdshader
Procedural geometry displacement using NoiseTexture2D in the vertex() function for rolling terrain.
foliage_wind_sway_expert.gdshader
GPU-driven wind animation using world_vertex_coords for uniform sway across the environment.
global_grass_flatten.gdshader
World-interaction pattern using global uniform. Synchronizes player position to push grass down project-wide.
depth_world_reconstruction.gdshader
Expert depth-buffer logic. Reconstructs world-space coordinates from hint_depth_texture for water/fog effects.
triplanar_world_mapping.gdshader
UV-less texturing architecture. Seamlessly projects textures along world axes for procedural cliffs and rocks.
instance_texture_array.gdshader
Bypassing batching limits. Combines sampler2DArray with instance uniform to give unique textures to thousands of batched objects.
screenspace_full_quad.gdshader
Godot 4.3 specific full-rect shader. Handles Reversed-Z coordinate reconstruction to prevent clipping at the near plane.
NEVER Do in Shaders
- NEVER use `discard` unconditionally for optimization — It prevents the depth prepass from working effectively. A discarded pixel still costs vertex processing; sometimes not rendering the object is better [1].
- NEVER use `if/else` for dynamic states in high-performance shaders — GPUs hate branching. Use
mix(),step(), andsmoothstep()for mathematical, hardware-optimized selection [5, 21]. - NEVER compare floats exactly — Hardware precision varies;
if (v == 0.5)is unreliable. Useabs(a - b) < epsilonorstep(). - NEVER use standard Alpha Blending for massive foliage — It prevents shadows and SSR. Use Alpha Scissor or Alpha Hash (dithering) to enable depth prepass and shadow casting [7].
- NEVER hardcode `POSITION` to `vec4(VERTEX, 1.0)` for full-screen quads in 4.3+ — Godot 4.3 uses Reversed-Z depth; this will cause clipping. Use
POSITION = vec4(VERTEX.xy, 1.0, 1.0)[8, 9]. - NEVER duplicate materials to change one color/value on many enemies — Use
instance uniform. This allows unique values for thousands of nodes while maintaining a single draw call (batching) [10]. - NEVER use `TIME` without a speed multiplier — Fragment speed should be controllable via uniforms to ensure consistency across different gameplay states.
- NEVER forget `hint_source_color` for color uniforms — Without it, the engine treats colors as linear math, leading to incorrect gamma and washed-out visuals in the inspector.
- NEVER calculate complex math in `fragment()` that could be in `vertex()` —
vertex()runs once per point;fragment()runs millions of times per frame. Interpolate values viavaryinginstead. - NEVER use `#define` macros for dynamic runtime toggles — These create new shader permutations, causing massive compilation stutters when first encountered in-game. Use uniforms instead.
- NEVER forget to normalize vectors — Using
reflect(dir, normal)on unnormalized vectors causes severe rendering artifacts and incorrect lighting math. - NEVER modify UV without bounds checking or `fract()` — Shifting UVs beyond 0.0-1.0 without
repeatwrapping or clamping will sample edge pixels or return black, breaking texture consistency.
---
shader_type canvas_item;
void fragment() {
// Get texture color
vec4 tex_color = texture(TEXTURE, UV);
// Tint red
COLOR = tex_color * vec4(1.0, 0.5, 0.5, 1.0);
}Apply to Sprite: 1. Select Sprite2D node 2. Material → New ShaderMaterial 3. Shader → New Shader 4. Paste code
Common 2D Effects
Dissolve Effect
shader_type canvas_item;
uniform float dissolve_amount : hint_range(0.0, 1.0) = 0.0;
uniform sampler2D noise_texture;
void fragment() {
vec4 tex_color = texture(TEXTURE, UV);
float noise = texture(noise_texture, UV).r;
if (noise < dissolve_amount) {
discard; // Make pixel transparent
}
COLOR = tex_color;
}Wave Distortion
shader_type canvas_item;
uniform float wave_speed = 2.0;
uniform float wave_amount = 0.05;
void fragment() {
vec2 uv = UV;
uv.x += sin(uv.y * 10.0 + TIME * wave_speed) * wave_amount;
COLOR = texture(TEXTURE, uv);
}Outline
shader_type canvas_item;
uniform vec4 outline_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
uniform float outline_width = 2.0;
void fragment() {
vec4 col = texture(TEXTURE, UV);
vec2 pixel_size = TEXTURE_PIXEL_SIZE * outline_width;
float alpha = col.a;
alpha = max(alpha, texture(TEXTURE, UV + vec2(pixel_size.x, 0.0)).a);
alpha = max(alpha, texture(TEXTURE, UV + vec2(-pixel_size.x, 0.0)).a);
alpha = max(alpha, texture(TEXTURE, UV + vec2(0.0, pixel_size.y)).a);
alpha = max(alpha, texture(TEXTURE, UV + vec2(0.0, -pixel_size.y)).a);
COLOR = mix(outline_color, col, col.a);
COLOR.a = alpha;
}3D Shaders
Basic 3D Shader
shader_type spatial;
void fragment() {
ALBEDO = vec3(1.0, 0.0, 0.0); // Red material
}Toon Shading (Cel-Shading)
shader_type spatial;
uniform vec3 base_color : source_color = vec3(1.0);
uniform int color_steps = 3;
void light() {
float NdotL = dot(NORMAL, LIGHT);
float stepped = floor(NdotL * float(color_steps)) / float(color_steps);
DIFFUSE_LIGHT = base_color * stepped;
}Screen-Space Effects
Vignette
shader_type canvas_item;
uniform float vignette_strength = 0.5;
void fragment() {
vec4 color = texture(TEXTURE, UV);
// Distance from center
vec2 center = vec2(0.5, 0.5);
float dist = distance(UV, center);
float vignette = 1.0 - dist * vignette_strength;
COLOR = color * vignette;
}Uniforms (Parameters)
// Float slider
uniform float intensity : hint_range(0.0, 1.0) = 0.5;
// Color picker
uniform vec4 tint_color : source_color = vec4(1.0);
// Texture
uniform sampler2D noise_texture;
// Access in code:
material.set_shader_parameter("intensity", 0.8)Built-in Variables
2D (canvas_item):
UV- Texture coordinates (0-1)COLOR- Output colorTEXTURE- Current textureTIME- Time since startSCREEN_UV- Screen coordinates
3D (spatial):
ALBEDO- Base colorNORMAL- Surface normalROUGHNESS- Surface roughnessMETALLIC- Metallic value
Best Practices
1. Use Uniforms for Tweaking
// ✅ Good - adjustable
uniform float speed = 1.0;
void fragment() {
COLOR.r = sin(TIME * speed);
}
// ❌ Bad - hardcoded
void fragment() {
COLOR.r = sin(TIME * 2.5);
}2. Optimize Performance
// Avoid expensive operations in fragment shader
// Pre-calculate values when possible
// Use textures for complex patterns3. Comment Shaders
// Water wave effect
// Creates horizontal distortion based on sine wave
uniform float wave_amplitude = 0.02;---
---
Expert Pattern: Deferred-Fog-Volume
Create localized volumetric effects (caves, toxic clouds) using custom fog shaders that react to real-time lighting.
// Custom Localized Fog Shader
shader_type fog;
uniform float base_density : hint_range(0.0, 10.0) = 1.0;
uniform vec3 edge_color : source_color = vec3(0.1, 0.5, 0.8);
void fog() {
// 1. SDF built-in contains distance to FogVolume surface
float distance_factor = clamp(-SDF, 0.0, 1.0);
// 2. Smooth density falloff at volume edges
float edge_fade = pow(distance_factor, 2.0);
// 3. Output to volumetric froxel buffer
DENSITY = base_density * edge_fade;
ALBEDO = edge_color;
}---
Expert Pattern: Compute-Shader-Particles
Simulate massive, high-performance particle systems (boids, fluids) using the RenderingDevice API for raw GPGPU processing.
class_name ComputeParticleSim extends Node
var _rd: RenderingDevice
var _pipeline: RID
var _buffer: RID
func _ready() -> void:
# 1. Initialize RenderingDevice and load GLSL
_rd = RenderingServer.create_local_rendering_device()
var shader_file := load("res://particle_sim.glsl") as RDShaderFile
var shader_rid := _rd.shader_create_from_spirv(shader_file.get_spirv())
# 2. Setup Storage Buffer for particle data
var data := PackedFloat32Array()
data.resize(6400) # 6400 particles
_buffer = _rd.storage_buffer_create(data.size() * 4, data.to_byte_array())
# 3. Create Compute Pipeline and Uniform Set
var uniform := RDUniform.new()
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER
uniform.binding = 0
uniform.add_id(_buffer)
var uniform_set := _rd.uniform_set_create([uniform], shader_rid, 0)
_pipeline = _rd.compute_pipeline_create(shader_rid)
# 4. Dispatch (simplified for logic overview)
var compute_list := _rd.compute_list_begin()
_rd.compute_list_bind_compute_pipeline(compute_list, _pipeline)
_rd.compute_list_bind_uniform_set(compute_list, uniform_set, 0)
_rd.compute_list_dispatch(compute_list, 100, 1, 1) # 100 workgroups * 64
_rd.compute_list_end()---
Expert Pattern: Shader-Debug-Visualizer
Diagnostic tool to inspect Depth, Normals, and UVs using a full-screen post-processing quad.
shader_type spatial;
render_mode unshaded, fog_disabled;
uniform sampler2D depth_tex : hint_depth_texture;
uniform sampler2D norm_tex : hint_normal_roughness_texture;
uniform int mode : hint_range(0, 2) = 0; // 0: Depth, 1: Normals, 2: UVs
void vertex() {
POSITION = vec4(VERTEX.xy, 1.0, 1.0); // Full-screen quad
}
void fragment() {
if (mode == 0) {
float raw_depth = texture(depth_tex, SCREEN_UV).x;
// Convert to linear view-space depth
vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, raw_depth);
vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
view.xyz /= view.w;
ALBEDO = vec3(clamp(-view.z / 100.0, 0.0, 1.0));
} else if (mode == 1) {
vec3 norm = texture(norm_tex, SCREEN_UV).xyz * 2.0 - 1.0;
ALBEDO = (norm * 0.5) + 0.5;
} else {
ALBEDO = vec3(SCREEN_UV, 0.0);
}
}---
Expert Pattern: Visual-Shader-Extensibility
Extend the Visual Shader editor by creating custom VisualShaderNodeCustom classes in GDScript to expose complex math or global functions as reusable nodes.
@tool
class_name VisualShaderNodeCustomMath extends VisualShaderNodeCustom
func _get_name() -> String: return "CustomPhysicsMath"
func _get_category() -> String: return "Custom"
func _get_return_icon_type() -> PortType: return PORT_TYPE_SCALAR
func _get_input_port_count() -> int: return 2
func _get_input_port_name(port: int) -> String: return "in_" + str(port)
func _get_input_port_type(_port: int) -> PortType: return PORT_TYPE_SCALAR
func _get_output_port_count() -> int: return 1
func _get_output_port_name(_port: int) -> String: return "out"
func _get_output_port_type(_port: int) -> PortType: return PORT_TYPE_SCALAR
func _get_code(input_vars: Array[String], output_vars: Array[String], _mode: Shader.Mode, _type: VisualShader.Type) -> String:
return "%s = %s * (1.0 - %s);" % [output_vars[0], input_vars[0], input_vars[1]]---
Expert Pattern: Shader-Precompilation-Warmup
Prevent mid-game "shader stutter" by forcing the engine to compile and cache pipelines during a loading screen.
func warmup_shaders(scenes: Array[PackedScene]):
for scene in scenes:
var inst = scene.instantiate()
add_child(inst)
# Place in front of camera
inst.position = Vector3(0, 0, -5)
# Force a single-frame render to populate the pipeline cache
await RenderingServer.frame_post_draw
# Cleanup
for child in get_children():
child.queue_free()Reference
Related
- Master Skill: godot-master
# depth_world_reconstruction.gdshader
# Reconstructing world-space from depth for localized fog/water [24]
shader_type spatial;
render_mode unshaded;
uniform sampler2D depth_tex : hint_depth_texture;
void fragment() {
float depth = textureLod(depth_tex, SCREEN_UV, 0.0).r;
// NDC (Normalized Device Coordinates) handle reversed-Z in Godot 4.3 [8]
vec4 ndc = vec4(SCREEN_UV * 2.0 - 1.0, depth, 1.0);
// Convert NDC back to world coordinates
vec4 world = INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * ndc;
vec3 world_pos = world.xyz / world.w;
// Visualize Y-height (useful for checking water depth)
ALBEDO = vec3(clamp(world_pos.y * 0.1, 0.0, 1.0));
}
# dissolve_scissor_expert.gdshader
# Expert dissolve effect using Alpha Scissor for shadow-casting and performance
shader_type spatial;
uniform sampler2D noise_tex : source_color;
uniform float dissolve_value : hint_range(0.0, 1.0) = 0.0;
uniform vec4 edge_color : source_color = vec4(1.0, 0.5, 0.0, 1.0);
uniform float edge_thickness = 0.05;
void fragment() {
float noise = texture(noise_tex, UV).r;
// ALPHA_SCISSOR_THRESHOLD allows the depth prepass to work,
// which is faster than alpha blending [7]
ALPHA = noise - dissolve_value;
ALPHA_SCISSOR_THRESHOLD = 0.01;
// Expert edge glow: use step() for branchless selection [5, 21]
float edge_mask = step(ALPHA, edge_thickness) * step(0.001, ALPHA);
ALBEDO = mix(ALBEDO, edge_color.rgb, edge_mask);
EMISSION = edge_color.rgb * edge_mask * 2.0;
}
# foliage_wind_sway_expert.gdshader
# High-performance GPU-driven wind sway with world-space uniformity [19]
shader_type spatial;
render_mode depth_prepass_alpha, world_vertex_coords;
uniform float wind_speed = 1.0;
uniform float wind_strength = 0.1;
void vertex() {
// Use VERTEX.y or Vertex Color (RED) to mask the base of the plant
// COLOR.r should be 0.0 at the ground and 1.0 at the tips.
float strength = COLOR.r * wind_strength;
float time = TIME * wind_speed;
// Multi-frequency sine for organic movement
VERTEX.x += sin(time + VERTEX.x * 0.5) * strength;
VERTEX.z += cos(time * 0.8 + VERTEX.z * 0.4) * strength;
}
# global_grass_flatten.gdshader
# Using GlobalShaderParameters to synchronize world interaction [23]
shader_type spatial;
// Global uniform injected project-wide via RenderingServer
global uniform vec3 player_pos;
void vertex() {
float dist = distance(VERTEX, player_pos);
// If player is close, squash the vertex towards the ground
// mix() + step() is used for branchless optimization [5]
float flatten_mask = 1.0 - step(1.5, dist);
VERTEX.y *= mix(1.0, 0.1, flatten_mask);
}
# instance_texture_array.gdshader
# Selecting unique textures in a batch using TextureArrays and Instance Uniforms [28]
shader_type spatial;
// Regular uniform array (shared by all batched instances)
uniform sampler2DArray textures_collection : source_color;
// Instance-specific index (unique per node, but maintains batching)
instance uniform int texture_variant_index = 0;
void fragment() {
// Use the instance index to pick a layer from the array
ALBEDO = texture(textures_collection, vec3(UV, float(texture_variant_index))).rgb;
}
# instance_uniform_hitflash.gdshader
# High-performance hit flash using instance uniforms for batching [10]
shader_type spatial;
// Instance uniforms allow thousands of nodes to have unique flash states
// while sharing a single draw call (batching).
instance uniform float hit_flash_intensity : hint_range(0.0, 1.0) = 0.0;
uniform vec3 tint_color : source_color = vec3(1.0, 1.0, 1.0);
void fragment() {
// Blend base color with hit flash color based on the instance parameter
ALBEDO = mix(ALBEDO, tint_color, hit_flash_intensity);
// Optional: add a tiny bit of emission for the flash
EMISSION = tint_color * hit_flash_intensity * 0.5;
}
# noise_terrain_displacement.gdshader
# Procedural terrain displacement using NoiseTexture2D [17]
shader_type spatial;
uniform sampler2D height_map;
uniform float height_scale = 2.0;
varying float v_height;
void vertex() {
// Sample noise based on world position (XZ plane)
vec2 world_uv = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xz * 0.1;
v_height = texture(height_map, world_uv).r;
// Physically displace the vertex
VERTEX.y += v_height * height_scale;
}
void fragment() {
// Use the height for procedural coloring (e.g. snow on peaks)
float peak_mask = step(0.8, v_height);
ALBEDO = mix(vec3(0.2, 0.5, 0.2), vec3(0.9, 0.9, 1.0), peak_mask);
}
# screenspace_full_quad.gdshader
# Correct Godot 4.3 Reversed-Z Full-Screen Quad setup [8]
shader_type spatial;
render_mode unshaded, skip_vertex_transform;
void vertex() {
// Reverse-Z fix: ensure the quad is at the correct depth [9]
// Using 1.0 for Z ensures it's at the far plane in reversed-Z
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
}
void fragment() {
// Perform post-processing logic here...
ALBEDO = vec3(SCREEN_UV, 0.5);
}
# screenspace_hex_pixelate.gdshader
# Advanced post-processing hex pixelation [13]
shader_type canvas_item;
uniform vec2 size = vec2(32.0, 28.0);
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
void fragment() {
vec2 norm_size = size * SCREEN_PIXEL_SIZE;
bool less_than_half = mod(SCREEN_UV.y / 2.0, norm_size.y) / norm_size.y < 0.5;
vec2 uv = SCREEN_UV + vec2(norm_size.x * 0.5 * float(less_than_half), 0.0);
vec2 center_uv = floor(uv / norm_size) * norm_size;
vec2 norm_uv = mod(uv, norm_size) / norm_size;
center_uv += mix(vec2(0.0, 0.0),
mix(mix(vec2(norm_size.x, -norm_size.y), vec2(0.0, -norm_size.y), float(norm_uv.x < 0.5)),
mix(vec2(0.0, -norm_size.y), vec2(-norm_size.x, -norm_size.y), float(norm_uv.x < 0.5)),
float(less_than_half)),
float(norm_uv.y < 0.3333333) * float(norm_uv.y / 0.3333333 < (abs(norm_uv.x - 0.5) * 2.0)));
COLOR = textureLod(screen_texture, center_uv, 0.0);
}
# skills/shaders-basics/scripts/shader_parameter_animator.gd
extends Node
## Shader Parameter Animator (Expert Pattern)
## Animates shader uniforms via code (Singular Manager).
## Prevents creating unique Tweens for every single visual effect instance.
class_name ShaderAnimator
static func animate_float(material: ShaderMaterial, param: String, from: float, to: float, duration: float) -> void:
if not material: return
var tree = Engine.get_main_loop() as SceneTree
if not tree: return
var tween = tree.create_tween()
tween.tween_method(
func(val): material.set_shader_parameter(param, val),
from, to, duration
)
static func animate_vec3(material: ShaderMaterial, param: String, from: Vector3, to: Vector3, duration: float) -> void:
if not material: return
var tree = Engine.get_main_loop() as SceneTree
var tween = tree.create_tween()
tween.tween_method(
func(val): material.set_shader_parameter(param, val),
from, to, duration
)
static func pulse_param(material: ShaderMaterial, param: String, min_val: float, max_val: float, speed: float) -> void:
# Requires an active node to process
pass # Implementation requires active processing
## EXPERT USAGE:
## Call ShaderAnimator.animate_float(mat, "dissolve", 0.0, 1.0, 2.0)
## Handles the tween creation automatically.
# triplanar_world_mapping.gdshader
# UV-less texturing for organic procedural cliffs [26]
shader_type spatial;
uniform sampler2D wall_texture : source_color;
void fragment() {
// Calculate blending weights based on surface normal
vec3 blending = abs(NORMAL);
blending /= (blending.x + blending.y + blending.z);
// Project texture from 3 axes using world-space positions
// (INV_VIEW_MATRIX * vec4(VERTEX, 1.0)) gets world space [26]
vec3 world_v = (INV_VIEW_MATRIX * vec4(VERTEX, 1.0)).xyz;
vec3 x_project = texture(wall_texture, world_v.yz).rgb;
vec3 y_project = texture(wall_texture, world_v.xz).rgb;
vec3 z_project = texture(wall_texture, world_v.xy).rgb;
ALBEDO = x_project * blending.x + y_project * blending.y + z_project * blending.z;
}
// skills/shaders-basics/scripts/vfx_port_shader.gdshader
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_disabled;
// Expert Shader Template
// Includes common VFX patterns: Panning, Noise, Fresnel, Proximity Fade.
uniform vec4 albedo : source_color = vec4(1.0);
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap;
uniform float emission_energy : hint_range(0.0, 16.0) = 1.0;
group_uniforms Panning;
uniform vec2 pan_speed = vec2(0.1, 0.0);
uniform vec2 uv_scale = vec2(1.0, 1.0);
group_uniforms Noise_Dissolve;
uniform sampler2D noise_texture : hint_default_white;
uniform float dissolve_amount : hint_range(0.0, 1.0) = 0.0;
uniform float edge_width : hint_range(0.0, 0.2) = 0.05;
uniform vec4 edge_color : source_color = vec4(1.0, 0.5, 0.0, 1.0);
group_uniforms Soft_Collision;
uniform float proximity_fade_distance = 0.5;
void fragment() {
// 1. Panning UVs
vec2 panned_uv = UV * uv_scale + TIME * pan_speed;
vec4 tex_color = texture(texture_albedo, panned_uv);
// 2. Base Color
ALBEDO = albedo.rgb * tex_color.rgb;
// 3. Noise Dissolve (Advanced)
float noise = texture(noise_texture, UV).r;
float alpha = 1.0;
if (dissolve_amount > 0.0) {
float cut = dissolve_amount;
if (noise < cut) {
discard;
}
// Edge Glow
if (noise < cut + edge_width) {
EMISSION += edge_color.rgb * 5.0; // Boost emission
ALBEDO = edge_color.rgb;
}
}
// 4. Proximity Fade (Soft Particles)
// Requires depth texture access, implied by render_mode usually
// float depth_tex = texture(DEPTH_TEXTURE, SCREEN_UV).r;
// ... complicated raw math omitted for template simplicity, use built-in:
// PROXIMITY_FADE is not a keyword, strictly manually implemented.
// StandardMaterial3D has it built-in. Here is manual:
ALPHA = albedo.a * tex_color.a * alpha;
EMISSION += ALBEDO * emission_energy;
}
// EXPERT USAGE:
// Copy-paste for Fire, Magic, Water effects.
// Use Proximity Fade logic for intersecting geometry softness.
Related skills
FAQ
What shader scripts ship with godot-shaders-basics?
godot-shaders-basics ships 12 expert .gdshader templates including dissolve, hit flash, hex pixelate, terrain displacement, foliage wind, triplanar mapping, and depth reconstruction, plus shader_parameter_animator.gd for runtime uniform animation.
What Godot shader types does godot-shaders-basics cover?
godot-shaders-basics covers canvas_item 2D shaders, spatial 3D materials, screen-space post-processing, fog volumes, compute-driven particles, and Godot 4.3 Reversed-Z full-screen quad patterns with uniforms and built-in variables.