module
CrShader::Templates
Overview
============================================================================= CrShader::Templates - Built-in Authoring Templates Across All Shader Modes
Powers Godot 4.8's "Create Shader" dialog (Ctrl+N in the Shader Editor),
the CRShader toolbar menu, CrShaderTabEditor template picker, and crshader new.
Extended Modules
Defined in:
crshader/templates.crConstant Summary
-
ALL_MODES =
[Mode::Spatial, Mode::CanvasItem, Mode::Particles, Mode::Sky, Mode::Fog, Mode::Compute, Mode::ShaderInclude] -
CATALOG =
[Entry.new(id: "spatial_default", name: "Default (Standard PBR)", mode: Mode::Spatial, summary: "Standard 3D physically-based surface shader with albedo, roughness, and metallic uniforms.", source: " shader_type :spatial\n render_mode :cull_back, :diffuse_burley, :specular_schlick_ggx\n\n uniform albedo_color : Color = Color.new(0.22, 0.62, 0.96, 1.0), hint: :source_color\n uniform albedo_tex : Sampler2D, hint: :source_color, filter: :linear_mipmap\n uniform roughness_val : Float32 = 0.35, range: 0.0..1.0\n uniform metallic_val : Float32 = 0.05, range: 0.0..1.0\n\n vertex do\n # Called for every vertex the material is visible on.\n end\n\n fragment do\n tex = texture(albedo_tex, UV)\n ALBEDO = albedo_color.rgb * tex.rgb\n ROUGHNESS = roughness_val\n METALLIC = metallic_val\n end"), Entry.new(id: "spatial_empty", name: "Empty", mode: Mode::Spatial, summary: "Minimal empty 3D Spatial CRShader skeleton.", source: " shader_type :spatial\n\n fragment do\n ALBEDO = vec3(1.0, 1.0, 1.0)\n end"), Entry.new(id: "spatial_toon", name: "Toon / Cel Shaded Surface", mode: Mode::Spatial, summary: "Stylized cel-shaded 3D material with perceptual Oklab color ramp and rim Fresnel glow.", source: " surface_material :toon do\n property base_tint : Color = Color.hex(\"#38bdf8\"), hint: :source_color\n property roughness_val : Float32 = 0.4, range: 0.0..1.0\n\n gradient :cel_ramp, {\n 0.0 => Color.hex(\"#0f172a\"),\n 0.5 => Color.hex(\"#2563eb\"),\n 1.0 => Color.hex(\"#bae6fd\"),\n }, space: :oklab, interp: :smooth\n\n use_trait \"std/traits/rim_fresnel\"\n\n shade_t = clamp(1.0 - UV.y, 0.0, 1.0)\n ALBEDO = cel_ramp(shade_t).rgb * base_tint.rgb\n ROUGHNESS = roughness_val\n end"), Entry.new(id: "spatial_dissolve_hitflash", name: "Dissolve & Hit Flash VFX", mode: Mode::Spatial, summary: "Combat-ready 3D surface combining procedural noise dissolve and damage hit-flash traits.", source: " surface_material :pbr do\n property albedo_color : Color = Color.hex(\"#e2e8f0\"), hint: :source_color\n property roughness_val : Float32 = 0.45, range: 0.0..1.0\n\n use_trait \"std/traits/dissolve\"\n use_trait \"std/traits/hit_flash\"\n\n ALBEDO = albedo_color.rgb\n ROUGHNESS = roughness_val\n end"), Entry.new(id: "spatial_foliage_wind", name: "Foliage & Wind Sway", mode: Mode::Spatial, summary: "Two-sided alpha-prepass foliage material with procedural vertex wind sway and backlight.", source: " surface_material :foliage do\n sampler leaf_tex, filter: :linear_mipmap\n property leaf_tint : Color = Color.hex(\"#4ade80\"), hint: :source_color\n property alpha_scissor : Float32 = 0.5, range: 0.0..1.0\n property backlight_tint : Color = Color.hex(\"#bef264\"), hint: :source_color\n\n use_trait \"std/traits/wind_sway\"\n\n tex = texture(leaf_tex, UV)\n ALBEDO = tex.rgb * leaf_tint.rgb\n ALPHA = tex.a\n ALPHA_SCISSOR_THRESHOLD = alpha_scissor\n ROUGHNESS = 0.65\n BACKLIGHT = backlight_tint.rgb * 0.35\n end"), Entry.new(id: "spatial_water_waves", name: "Water / Animated Waves", mode: Mode::Spatial, summary: "Translucent animated 3D water surface with vertex waves and Fresnel horizon tint.", source: " surface_material :glass do\n require \"std/math\"\n\n property shallow_color : Color = Color.hex(\"#22d3ee\"), hint: :source_color\n property deep_color : Color = Color.hex(\"#0c4a6e\"), hint: :source_color\n property wave_height : Float32 = 0.12, range: 0.0..1.0\n property wave_speed : Float32 = 1.8, range: 0.0..8.0\n property wave_scale : Float32 = 2.5, range: 0.1..12.0\n property opacity : Float32 = 0.82, range: 0.1..1.0\n\n vertex do\n phase_x = VERTEX.x * wave_scale + TIME * wave_speed\n phase_z = VERTEX.z * (wave_scale * 0.85) + TIME * (wave_speed * 0.75)\n VERTEX.y += (sin(phase_x) + cos(phase_z)) * 0.5 * wave_height\n end\n\n fragment do\n fres = fresnel(3.0, NORMAL, VIEW)\n ripple = sin(UV.x * 24.0 + TIME * wave_speed) * cos(UV.y * 24.0 - TIME * wave_speed) * 0.5 + 0.5\n ALBEDO = mix(deep_color.rgb, shallow_color.rgb, clamp(fres + ripple * 0.15, 0.0, 1.0))\n ROUGHNESS = 0.08\n METALLIC = 0.1\n ALPHA = opacity\n end\n end"), Entry.new(id: "spatial_hologram_shield", name: "Hologram / Forcefield Shield", mode: Mode::Spatial, summary: "Additive glowing energy shield with Fresnel rim, scrolling scanlines, and emission pulse.", source: " shader_type :spatial\n render_mode :blend_add, :depth_draw_never, :cull_disabled, :unshaded\n\n require \"std/math\"\n\n uniform shield_color : Color = Color.hex(\"#38bdf8\"), hint: :source_color\n uniform rim_sharpness : Float32 = 2.8, range: 0.5..8.0\n uniform scanline_density : Float32 = 48.0, range: 4.0..200.0\n uniform scanline_speed : Float32 = 2.5, range: 0.0..12.0\n\n use_trait \"std/traits/emission_pulse\"\n\n fragment do\n rim = fresnel(rim_sharpness, NORMAL, VIEW)\n scan = sin(UV.y * scanline_density - TIME * scanline_speed * 6.28318) * 0.5 + 0.5\n mask = clamp(rim * 0.85 + scan * 0.2, 0.0, 1.0)\n ALBEDO = shield_color.rgb * (1.0 + rim * 1.5)\n ALPHA = mask\n end"), Entry.new(id: "spatial_triplanar", name: "Triplanar World-Aligned Surface", mode: Mode::Spatial, summary: "UV-free world-space triplanar texture projection ideal for terrain, cliffs, and greyboxing.", source: " surface_material :pbr do\n property base_color : Color = Color.hex(\"#cbd5e1\"), hint: :source_color\n property roughness_val : Float32 = 0.75, range: 0.0..1.0\n\n use_trait \"std/traits/triplanar_surface\"\n\n ALBEDO = base_color.rgb\n ROUGHNESS = roughness_val\n end"), Entry.new(id: "canvas_default", name: "Default (2D Sprite)", mode: Mode::CanvasItem, summary: "Standard 2D CanvasItem shader sampling TEXTURE with customizable color tint.", source: " shader_type :canvas_item\n\n uniform tint_color : Color = Color.new(1.0, 1.0, 1.0, 1.0), hint: :source_color\n\n vertex do\n # Called for every vertex the CanvasItem is visible on.\n end\n\n fragment do\n COLOR = texture(TEXTURE, UV) * COLOR * tint_color\n end"), Entry.new(id: "canvas_empty", name: "Empty", mode: Mode::CanvasItem, summary: "Minimal empty 2D CanvasItem CRShader skeleton.", source: " shader_type :canvas_item\n\n fragment do\n COLOR = texture(TEXTURE, UV) * COLOR\n end"), Entry.new(id: "canvas_sprite_outline_flash", name: "Sprite Hit Flash & Pixel Outline", mode: Mode::CanvasItem, summary: "2D sprite archetype with 4-neighbor pixel outline stroke and animated damage flash.", source: " sprite_effect do |uv, color, px|\n property outline_color : Color = Color.hex(\"#0f172a\"), hint: :source_color\n property outline_width : Float32 = 1.0, range: 0.0..8.0\n property flash_color : Color = Color.hex(\"#ffffff\"), hint: :source_color\n property flash_amount : Float32 = 0.0, range: 0.0..1.0\n\n step_uv = px * outline_width\n a_up = texture(TEXTURE, uv + vec2(0.0, -step_uv.y)).a\n a_down = texture(TEXTURE, uv + vec2(0.0, step_uv.y)).a\n a_left = texture(TEXTURE, uv + vec2(-step_uv.x, 0.0)).a\n a_right = texture(TEXTURE, uv + vec2(step_uv.x, 0.0)).a\n neighbor_a = clamp(a_up + a_down + a_left + a_right, 0.0, 1.0)\n\n outlined_rgb = mix(outline_color.rgb, color.rgb, color.a)\n outlined_a = max(color.a, neighbor_a * outline_color.a)\n flashed_rgb = mix(outlined_rgb, flash_color.rgb, clamp(flash_amount, 0.0, 1.0))\n\n vec4(flashed_rgb, outlined_a)\n end"), Entry.new(id: "canvas_sprite_dissolve", name: "Sprite Dissolve & Burn Edge", mode: Mode::CanvasItem, summary: "2D sprite procedural noise dissolve with glowing ember border.", source: " sprite_effect do |uv, color|\n require \"std/noise\"\n\n property dissolve_amount : Float32 = 0.0, range: 0.0..1.0\n property noise_scale : Float32 = 14.0, range: 1.0..64.0\n property burn_width : Float32 = 0.08, range: 0.005..0.3\n property burn_color : Color = Color.hex(\"#fb923c\"), hint: :source_color\n\n n = value_noise(uv * noise_scale)\n alpha_mask = step(dissolve_amount, n)\n burn_edge = smoothstep(dissolve_amount + burn_width, dissolve_amount, n) * step(0.001, dissolve_amount)\n lit_rgb = mix(color.rgb, burn_color.rgb * 2.0, burn_edge)\n\n vec4(lit_rgb, color.a * alpha_mask)\n end"), Entry.new(id: "canvas_wave_distortion", name: "2D UV Wave / Distortion", mode: Mode::CanvasItem, summary: "Animated sine wave UV distortion for underwater sprites, banners, and heat shimmer.", source: " sprite_effect do |uv, color|\n property wave_frequency : Float32 = 16.0, range: 1.0..64.0\n property wave_amplitude : Float32 = 0.02, range: 0.0..0.15\n property wave_speed : Float32 = 3.0, range: 0.0..15.0\n\n offset_x = sin(uv.y * wave_frequency + TIME * wave_speed) * wave_amplitude\n offset_y = cos(uv.x * wave_frequency + TIME * (wave_speed * 0.8)) * (wave_amplitude * 0.5)\n warped_uv = clamp(uv + vec2(offset_x, offset_y), vec2(0.0, 0.0), vec2(1.0, 1.0))\n\n texture(TEXTURE, warped_uv) * COLOR\n end"), Entry.new(id: "canvas_ui_sdf_card", name: "UI Rounded SDF Card & Glow", mode: Mode::CanvasItem, summary: "Aspect-corrected 2D UI panel with anti-aliased rounded corners, border stroke, and glow.", source: " ui_effect do |uv, centered_uv, color|\n require \"std/sdf2d\"\n\n property card_half_size : Vec2 = Vec2.new(0.42, 0.32)\n property corner_radius : Float32 = 0.06, range: 0.0..0.25\n property border_width : Float32 = 0.01, range: 0.001..0.05\n property fill_color : Color = Color.hex(\"#0f172a\"), hint: :source_color\n property border_color : Color = Color.hex(\"#38bdf8\"), hint: :source_color\n property glow_strength : Float32 = 0.5, range: 0.0..2.0\n\n d = sdf2d_rounded_box(centered_uv, card_half_size, corner_radius)\n fill = sdf_fill(d)\n border = sdf_stroke(d, border_width)\n glow = sdf_glow(d, 0.07, 2.2) * glow_strength\n\n rgb = fill_color.rgb * fill + border_color.rgb * (border + glow * 0.45)\n alpha = clamp(fill * fill_color.a + border + glow * 0.5, 0.0, 1.0) * color.a\n vec4(rgb, alpha)\n end"), Entry.new(id: "canvas_screen_postprocess", name: "Screen Post-Process (Vignette & Chromatic)", mode: Mode::CanvasItem, summary: "Fullscreen ColorRect post-processing stack fusing chromatic aberration, color grade, and vignette.", source: " screen_effect do |uv, color|\n use_trait \"std/traits/chromatic_aberration\"\n use_trait \"std/traits/color_grade\"\n use_trait \"std/traits/vignette\"\n end"), Entry.new(id: "canvas_crt_dither", name: "Retro CRT & Bayer Dither", mode: Mode::CanvasItem, summary: "Fullscreen retro CRT curvature, scanlines, and ordered 4x4 Bayer dithering.", source: " screen_effect do |uv, color|\n require \"std/post_processing\"\n require \"std/dither\"\n\n property curvature : Float32 = 0.12, range: 0.0..0.5\n property color_levels : Float32 = 16.0, range: 2.0..64.0\n property scanline_strength : Float32 = 0.18, range: 0.0..0.6\n\n warped = barrel_distortion(uv, curvature)\n sampled = texture(screen_texture, clamp(warped, vec2(0.0, 0.0), vec2(1.0, 1.0)))\n\n px_coord = ivec2(FRAGCOORD.xy)\n bayer = bayer4x4(px_coord) - 0.5\n quant_r = dither_quantize(sampled.r, color_levels, bayer)\n quant_g = dither_quantize(sampled.g, color_levels, bayer)\n quant_b = dither_quantize(sampled.b, color_levels, bayer)\n\n scan = 1.0 - (sin(FRAGCOORD.y * 3.14159) * 0.5 + 0.5) * scanline_strength\n vec4(vec3(quant_r, quant_g, quant_b) * scan, 1.0)\n end"), Entry.new(id: "particles_default", name: "Default (Velocity & Gravity)", mode: Mode::Particles, summary: "GPU particle shader with randomized radial launch velocity, gravity, and tint.", source: " shader_type :particles\n\n uniform initial_speed : Float32 = 4.0, range: 0.0..30.0\n uniform spread : Float32 = 1.0, range: 0.0..5.0\n uniform gravity_accel : Vec3 = Vec3.new(0.0, -4.5, 0.0)\n uniform start_color : Color = Color.hex(\"#38bdf8\"), hint: :source_color\n\n def start\n rx = (fract(sin(float(INDEX) * 12.9898 + float(SEED)) * 43758.5453) - 0.5) * spread\n rz = (fract(cos(float(INDEX) * 78.233 + float(SEED)) * 43758.5453) - 0.5) * spread\n VELOCITY = vec3(rx, initial_speed, rz)\n COLOR = start_color\n end\n\n def process\n VELOCITY += gravity_accel * DELTA\n end"), Entry.new(id: "particles_empty", name: "Empty", mode: Mode::Particles, summary: "Minimal GPU particle process shader skeleton.", source: " shader_type :particles\n\n def start\n end\n\n def process\n end"), Entry.new(id: "particles_fire_embers", name: "Stylized Fire & Smoke Embers", mode: Mode::Particles, summary: "Buoyant rising embers with turbulent swirl and ignition-to-smoke color transition.", source: " shader_type :particles\n\n uniform launch_speed : Float32 = 3.5, range: 0.5..20.0\n uniform spread_factor : Float32 = 1.2, range: 0.0..5.0\n uniform buoyancy : Float32 = 3.0, range: 0.0..15.0\n uniform turbulence : Float32 = 2.0, range: 0.0..10.0\n uniform flame_hot : Color = Color.hex(\"#fde047\"), hint: :source_color\n uniform flame_mid : Color = Color.hex(\"#f97316\"), hint: :source_color\n\n def start\n rx = (sin(float(INDEX) * 12.9898 + float(SEED)) - 0.5) * spread_factor\n rz = (cos(float(INDEX) * 78.233 + float(SEED)) - 0.5) * spread_factor\n VELOCITY = vec3(rx, launch_speed, rz)\n COLOR = flame_hot\n end\n\n def process\n swirl_x = sin(TIME * 4.0 + float(INDEX)) * turbulence\n swirl_z = cos(TIME * 4.0 + float(INDEX)) * turbulence\n VELOCITY += vec3(swirl_x, buoyancy, swirl_z) * DELTA\n COLOR = mix(flame_hot, flame_mid, clamp(DELTA * 8.0, 0.0, 1.0))\n end"), Entry.new(id: "particles_vortex_swarm", name: "Vortex & Orbital Swarm", mode: Mode::Particles, summary: "Uses std/particles vortex and point-attractor forces for portals and energy swarms.", source: " shader_type :particles\n\n require \"std/particles\"\n\n uniform attractor_pos : Vec3 = Vec3.new(0.0, 1.0, 0.0)\n uniform orbit_radius : Float32 = 6.0, range: 0.5..30.0\n uniform vortex_strength : Float32 = 8.0, range: 0.0..30.0\n uniform pull_strength : Float32 = 4.0, range: 0.0..20.0\n uniform drag_amount : Float32 = 0.8, range: 0.0..5.0\n\n def start\n angle = float(INDEX) * 0.618034 * 6.28318\n VELOCITY = vec3(cos(angle) * 2.0, 0.5, sin(angle) * 2.0)\n end\n\n def process\n pos = TRANSFORM[3].xyz\n swirl = vortex_force_3d(pos, attractor_pos, vortex_strength, orbit_radius)\n pull = attract_point(pos, attractor_pos, pull_strength, orbit_radius)\n VELOCITY = apply_linear_drag(VELOCITY + (swirl + pull) * DELTA, drag_amount, DELTA)\n end"), Entry.new(id: "sky_default", name: "Default (Procedural Horizon & Sun)", mode: Mode::Sky, summary: "Procedural sky dome blending zenith, horizon, ground, and directional sun disc.", source: " shader_type :sky\n\n uniform sky_top_color : Color = Color.hex(\"#0f172a\"), hint: :source_color\n uniform sky_horizon_color : Color = Color.hex(\"#38bdf8\"), hint: :source_color\n uniform ground_color : Color = Color.hex(\"#1e293b\"), hint: :source_color\n uniform sun_size : Float32 = 0.03, range: 0.002..0.2\n\n sky do\n up_t = clamp(EYEDIR.y, 0.0, 1.0)\n down_t = clamp(-EYEDIR.y, 0.0, 1.0)\n dome = mix(sky_horizon_color.rgb, sky_top_color.rgb, up_t ** 0.6)\n dome = mix(dome, ground_color.rgb, smoothstep(0.0, 0.15, down_t))\n\n if LIGHT0_ENABLED\n sun_angle = acos(clamp(dot(EYEDIR, LIGHT0_DIRECTION), -1.0, 1.0))\n sun_disc = smoothstep(sun_size, sun_size * 0.5, sun_angle)\n dome += LIGHT0_COLOR * (sun_disc * LIGHT0_ENERGY)\n end\n\n COLOR = dome\n end"), Entry.new(id: "sky_empty", name: "Empty", mode: Mode::Sky, summary: "Minimal 3D Environment Sky shader skeleton.", source: " shader_type :sky\n\n sky do\n COLOR = vec3(0.15, 0.28, 0.52)\n end"), Entry.new(id: "sky_sunset_stars", name: "Stylized Sunset & Starfield", mode: Mode::Sky, summary: "Perceptual Oklab twilight sky ramp with procedural twinkling zenith stars.", source: " shader_type :sky\n\n require \"std/noise\"\n\n uniform star_density : Float32 = 180.0, range: 20.0..500.0\n uniform star_brightness : Float32 = 1.4, range: 0.0..4.0\n\n gradient :twilight_sky, {\n 0.0 => Color.hex(\"#fb923c\"),\n 0.35 => Color.hex(\"#7c3aed\"),\n 1.0 => Color.hex(\"#020617\"),\n }, space: :oklab, interp: :smooth\n\n sky do\n t = clamp(EYEDIR.y * 0.85 + 0.15, 0.0, 1.0)\n base_sky = twilight_sky(t).rgb\n\n star_cell = floor(SKY_COORDS * star_density)\n star_seed = hash11(star_cell.x + star_cell.y * 113.0)\n twinkle = sin(TIME * 3.0 + star_seed * 31.4) * 0.35 + 0.65\n star_mask = step(0.992, star_seed) * smoothstep(0.1, 0.55, EYEDIR.y)\n\n COLOR = base_sky + vec3(star_mask * twinkle * star_brightness)\n end"), Entry.new(id: "fog_default", name: "Default (Height-Attenuated Fog)", mode: Mode::Fog, summary: "Volumetric height fog with smooth exponential altitude falloff.", source: " shader_type :fog\n\n uniform base_density : Float32 = 0.08, range: 0.0..1.0\n uniform fog_tint : Color = Color.hex(\"#cbd5e1\"), hint: :source_color\n uniform height_level : Float32 = 0.0\n uniform height_falloff : Float32 = 0.35, range: 0.01..4.0\n\n fog do\n rel_h = max(WORLD_POSITION.y - height_level, 0.0)\n DENSITY = base_density * exp(-rel_h * height_falloff)\n FOG_COLOR = fog_tint\n end"), Entry.new(id: "fog_empty", name: "Empty", mode: Mode::Fog, summary: "Minimal 3D Volumetric Fog shader skeleton.", source: " shader_type :fog\n\n fog do\n DENSITY = 0.04\n FOG_COLOR = vec4(0.8, 0.85, 0.92, 1.0)\n end"), Entry.new(id: "fog_rolling_mist", name: "Animated Rolling Ground Mist", mode: Mode::Fog, summary: "Scrolling procedural noise mist clinging to low terrain elevations.", source: " shader_type :fog\n\n require \"std/noise\"\n\n uniform mist_density : Float32 = 0.15, range: 0.0..1.0\n uniform mist_color : Color = Color.hex(\"#94a3b8\"), hint: :source_color\n uniform wind_velocity : Vec2 = Vec2.new(0.4, 0.2)\n uniform noise_scale : Float32 = 0.18, range: 0.02..2.0\n uniform ceiling_height : Float32 = 4.0, range: 0.5..30.0\n\n fog do\n sample_uv = WORLD_POSITION.xz * noise_scale + wind_velocity * TIME\n n = value_noise(sample_uv)\n height_mask = clamp(1.0 - WORLD_POSITION.y / max(ceiling_height, 0.01), 0.0, 1.0)\n DENSITY = mist_density * n * height_mask\n FOG_COLOR = mist_color\n end"), Entry.new(id: "compute_default", name: "Default (GLSL Storage Buffer)", mode: Mode::Compute, summary: "Vulkan GLSL compute shader with std430 storage buffer and push constants.", source: " shader_type :compute\n local_size 64, 1, 1\n\n buffer DataBuffer, set: 0, binding: 0, std: :std430 do\n field values : Array(Float32)\n end\n\n push_constant Params do\n field count : UInt32\n field scale : Float32\n end\n\n def main\n idx = gl_GlobalInvocationID.x\n if idx >= params.count\n return\n end\n\n data_buffer.values[idx] = data_buffer.values[idx] * params.scale\n end"), Entry.new(id: "compute_empty", name: "Empty", mode: Mode::Compute, summary: "Minimal Vulkan GLSL compute shader skeleton.", source: " shader_type :compute\n local_size 8, 8, 1\n\n def main\n end"), Entry.new(id: "compute_compositor_post", name: "Compositor Post-Process Effect", mode: Mode::Compute, summary: "Forward+ CompositorEffect compute pass reading and writing viewport color.", source: " compositor_effect :post_transparent do\n access :color\n\n property tint_color : Color = Color.hex(\"#e0f2fe\"), hint: :source_color\n property saturation : Float32 = 1.15, range: 0.0..2.5\n\n process_pixel do |pos, curr_color|\n luma = dot(curr_color.rgb, vec3(0.2126, 0.7152, 0.0722))\n graded = mix(vec3(luma, luma, luma), curr_color.rgb, saturation) * tint_color.rgb\n curr_color = vec4(graded, curr_color.a)\n end\n end"), Entry.new(id: "compute_compositor_depth_outline", name: "Compositor Depth Silhouette Outline", mode: Mode::Compute, summary: "Hardware Forward+ Compositor compute pass sampling Reverse-Z depth for crisp 3D outlines.", source: " compositor_effect :post_transparent do\n access :color, :depth\n\n property outline_color : Color = Color.new(0.05, 0.05, 0.08, 1.0), hint: :source_color\n property outline_thickness : Int32 = 1, hint: hint_range(1, 4)\n property depth_threshold : Float32 = 0.005, hint: hint_range(0.0001, 0.05, 0.0005)\n\n process_pixel do |pos, curr_color|\n max_coord = size - ivec2(1, 1)\n center_d = texelFetch(depth_texture, pos, 0).r\n d_up = texelFetch(depth_texture, clamp(pos + ivec2(0, -outline_thickness), ivec2(0, 0), max_coord), 0).r\n d_down = texelFetch(depth_texture, clamp(pos + ivec2(0, outline_thickness), ivec2(0, 0), max_coord), 0).r\n d_left = texelFetch(depth_texture, clamp(pos + ivec2(-outline_thickness, 0), ivec2(0, 0), max_coord), 0).r\n d_right = texelFetch(depth_texture, clamp(pos + ivec2(outline_thickness, 0), ivec2(0, 0), max_coord), 0).r\n\n diff = abs(center_d - d_up) + abs(center_d - d_down) + abs(center_d - d_left) + abs(center_d - d_right)\n if diff > depth_threshold\n curr_color = vec4(outline_color.rgb, 1.0)\n end\n end\n end"), Entry.new(id: "compute_image_filter", name: "2D Image Compute Filter", mode: Mode::Compute, summary: "2D Image2D read/write compute kernel for procedural textures or convolution blurs.", source: " shader_type :compute\n local_size 8, 8, 1\n\n image2d input_image, format: :rgba32f, set: 0, binding: 0\n image2d output_image, format: :rgba32f, set: 0, binding: 1\n\n uniform exposure : Float32 = 1.0\n\n def main\n coord = ivec2(gl_GlobalInvocationID.xy)\n dims = imageSize(input_image)\n if coord.x >= dims.x || coord.y >= dims.y\n return\n end\n\n src = imageLoad(input_image, coord)\n imageStore(output_image, coord, vec4(src.rgb * exposure, src.a))\n end"), Entry.new(id: "compute_particle_sim", name: "GPU Particle Simulation (Compute)", mode: Mode::Compute, summary: "High-throughput compute particle simulation DSL with Euler integration and linear drag.", source: " particle_simulation 64 do\n step_particles do |idx, pos, vel, life|\n life = life - sim_params.delta_time\n vel = apply_linear_drag(vel + sim_params.gravity * sim_params.delta_time, sim_params.drag, sim_params.delta_time)\n pos = integrate_euler(pos, vel, sim_params.delta_time)\n end\n end"), Entry.new(id: "include_default", name: "Default (Shared Math & Lighting Helpers)", mode: Mode::ShaderInclude, summary: "Reusable .gdshaderinc library compiled automatically with header guards on save.", source: " emit_target \"{{STEM}}.gdshaderinc\", target: :gdshaderinc\n\n shader :gdshaderinc\n\n def remap_range(val : Float32, in_min : Float32, in_max : Float32, out_min : Float32, out_max : Float32) : Float32\n t = clamp((val - in_min) / max(in_max - in_min, 0.00001), 0.0, 1.0)\n mix(out_min, out_max, t)\n end\n\n def rim_factor(normal : Vec3, view_dir : Vec3, power : Float32) : Float32\n clamp(1.0 - dot(normal, view_dir), 0.0, 1.0) ** power\n end"), Entry.new(id: "include_empty", name: "Empty", mode: Mode::ShaderInclude, summary: "Minimal .gdshaderinc include library skeleton.", source: " emit_target \"{{STEM}}.gdshaderinc\", target: :gdshaderinc\n\n shader :gdshaderinc\n\n def helper_identity(x : Float32) : Float32\n x\n end"), Entry.new(id: "include_oop_struct", name: "OOP Shader Class & Methods", mode: Mode::ShaderInclude, summary: "Demonstrates Crystal class/struct lowering into reusable .gdshaderinc types and helpers.", source: " emit_target \"{{STEM}}.gdshaderinc\", target: :gdshaderinc\n\n shader :gdshaderinc\n\n class SurfaceSample\n albedo : Vec3\n roughness : Float32\n\n def initialize(@albedo : Vec3 = vec3(1.0, 1.0, 1.0), @roughness : Float32 = 0.5)\n end\n\n def tinted(tint : Vec3, factor : Float32 = 1.0) : Vec3\n mix(albedo, albedo * tint, clamp(factor, 0.0, 1.0))\n end\n end\n\n def make_tinted_sample(base : Vec3, tint : Vec3) : Vec3\n s = SurfaceSample.new(base, 0.4)\n s.tinted(tint, 0.75)\n end")]
Instance Method Summary
- #all : Array(Entry)
- #default_for_mode(mode : Mode) : Entry
- #find(id_or_name : String) : Entry | Nil
- #for_mode(mode : Mode) : Array(Entry)
- #modes : Array(Mode)