[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KREE370Y80QK838PCRBA0S":3,"skill-same:01M6KREE370Y80QK838PCRBA0S":93},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":35,"linkOnly":36,"markdownContent":37,"markdownBody":38,"frontMatter":39,"refName":40,"commitSha":41,"skillDirectory":42,"forksCount":43,"repositoryHtmlUrl":44,"repositoryHomepageUrl":6,"ownerHtmlUrl":45,"ownerBlogUrl":46,"ownerDescription":47,"updatedAt":48,"install":49,"resources":62},"01M6KREE370Y80QK838PCRBA0S","shader-basics",null,"Use when implementing shaders — Godot shader language, visual shaders, common visual recipes, and post-processing effects","jame581\u002FGodotPrompter","jame581","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F21112138?v=4","01M6KR3KEQ9Z30WVJRR2E2ZVXE","Jan Mesarč","01M6KR3KJVRMPDSMASQPBCBVK3",964,"MIT","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],"basics","shader","shader basics","processing","implementing","use","effects","visual","common","post","shaders","post-processing","recipes","language","godot","when","2026-11-10 10:12:30",false,"---\nname: shader-basics\ndescription: Use when implementing shaders — Godot shader language, visual shaders, common visual recipes, and post-processing effects\n---\n\n# Shaders in Godot 4.3+\n\nAll examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **animation-system** for shader-driven effects like hit flash, **godot-optimization** for shader performance considerations, **camera-system** for post-processing camera effects, **2d-essentials** for 2D lighting, pixel-art shaders, and CanvasTexture normal maps, **3d-essentials** for spatial shaders and environment materials, **particles-vfx** for custom particle shaders, **tween-animation** for animating shader parameters at runtime.\n\n---\n\n## 1. Core Concepts\n\n### Shader Types\n\n| Shader Type | Applied To | Use For |\n|------------------|--------------------------|--------------------------------------------------|\n| `canvas_item` | 2D nodes (Sprite2D, Control, etc.) | 2D effects — outlines, dissolve, color swap |\n| `spatial` | 3D meshes (MeshInstance3D) | 3D materials — water, terrain, toon shading |\n| `particles` | GPUParticles2D\u002F3D | Custom particle behavior |\n| `sky` | WorldEnvironment | Procedural sky rendering |\n| `fog` | FogVolume | Volumetric fog effects |\n\n### Shader vs ShaderMaterial\n\n```\nShader (.gdshader)        → The code (GLSL-like language)\nShaderMaterial            → Instance of a shader with specific uniform values\nCanvasItemMaterial \u002F StandardMaterial3D → Built-in materials (no code needed)\n```\n\nMultiple nodes can share the same Shader but have different ShaderMaterial instances with different uniform values (e.g., same dissolve shader but different dissolve progress per enemy).\n\n### Creating a Shader\n\n1. Select a node (e.g., Sprite2D)\n2. In Inspector → Material → New ShaderMaterial\n3. On the ShaderMaterial → Shader → New Shader\n4. Edit the `.gdshader` file in the built-in editor\n\nOr create a `.gdshader` file directly in the FileSystem dock.\n\n---\n\n## 2. Godot Shader Language Basics\n\nGodot uses a GLSL ES 3.0-like language with Godot-specific additions.\n\n### Minimal Canvas Item Shader\n\n```glsl\nshader_type canvas_item;\n\nvoid fragment() {\n    \u002F\u002F COLOR is the output pixel color\n    \u002F\u002F TEXTURE is the sprite's texture\n    \u002F\u002F UV is the texture coordinate (0,0 top-left to 1,1 bottom-right)\n    vec4 tex = texture(TEXTURE, UV);\n    COLOR = tex;\n}\n```\n\n### Minimal Spatial Shader\n\n```glsl\nshader_type spatial;\n\nvoid fragment() {\n    \u002F\u002F ALBEDO is the base color (vec3)\n    ALBEDO = vec3(0.8, 0.2, 0.2);\n}\n```\n\n### Built-in Variables (canvas_item)\n\n| Variable | Type | Description |\n|------------|--------|---------------------------------------|\n| `UV` | `vec2` | Texture coordinates |\n| `COLOR` | `vec4` | Output color (set this in `fragment()`) |\n| `TEXTURE` | `sampler2D` | The node's texture |\n| `VERTEX` | `vec2` | Vertex position (in `vertex()`) |\n| `TIME` | `float`| Elapsed time in seconds |\n| `SCREEN_UV`| `vec2` | Screen-space UV (for screen effects) |\n\n> `SCREEN_TEXTURE` was removed in Godot 4.0. To read the screen, declare a uniform: `uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;`\n\n### Built-in Variables (spatial)\n\n| Variable | Type | Description |\n|-------------|--------|---------------------------------------|\n| `ALBEDO` | `vec3` | Base surface color |\n| `METALLIC` | `float`| Metallic value (0.0–1.0) |\n| `ROUGHNESS` | `float`| Roughness value (0.0–1.0) |\n| `NORMAL` | `vec3` | Surface normal (for normal mapping) |\n| `EMISSION` | `vec3` | Emissive color |\n| `ALPHA` | `float`| Transparency (writing it moves the material to the transparent pass) |\n| `VERTEX` | `vec3` | Vertex position (in `vertex()`) |\n\n### Uniforms (Shader Parameters)\n\nUniforms expose shader values to the Inspector and code.\n\n```glsl\nshader_type canvas_item;\n\nuniform float speed : hint_range(0.0, 10.0, 0.1) = 1.0;\nuniform vec4 tint_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);\nuniform sampler2D noise_texture : filter_linear_mipmap;\n\nvoid fragment() {\n    vec4 tex = texture(TEXTURE, UV);\n    COLOR = tex * tint_color;\n}\n```\n\n### Common Uniform Hints\n\n| Hint | Type | Description |\n|-----------------------------|--------------|-------------------------------------|\n| `hint_range(min, max, step)` | `float\u002Fint` | Slider in Inspector |\n| `source_color` | `vec4` | Color picker in Inspector |\n| `filter_linear_mipmap` | `sampler2D` | Texture filtering mode |\n| `repeat_enable` | `sampler2D` | Allow texture tiling |\n| `hint_normal` | `sampler2D` | Treat as normal map |\n\n### Setting Uniforms from Code\n\n#### GDScript\n\n```gdscript\nvar mat: ShaderMaterial = $Sprite2D.material\nmat.set_shader_parameter(\"speed\", 2.0)\nmat.set_shader_parameter(\"tint_color\", Color.RED)\n```\n\n#### C#\n\n```csharp\nvar mat = GetNode\u003CSprite2D>(\"Sprite2D\").Material as ShaderMaterial;\nmat.SetShaderParameter(\"speed\", 2.0f);\nmat.SetShaderParameter(\"tint_color\", Colors.Red);\n```\n\n---\n\n## 3. Common 2D Shader Recipes\n\nThe canvas_item recipes most projects need: **dissolve** (noise + edge glow), **outline** (sample neighbors, expand alpha), **flash-white** (uniform-driven hit effect), **color swap** (palette shift), **scrolling UV** (water\u002Flava\u002Fclouds), **wave distortion**.\n\n> See [references\u002F2d-shader-recipes.md](references\u002F2d-shader-recipes.md) for complete shader code for all six recipes.\n\n---\n\n## 4. Common 3D Shader Recipes\n\nSpatial-shader recipes: **toon\u002Fcel shading** (banded NdotL), **rim lighting \u002F Fresnel** (1 - NdotV), **simple water surface** (UV scroll + normal-map blend + Fresnel).\n\n> See [references\u002F3d-shader-recipes.md](references\u002F3d-shader-recipes.md) for the full shader source for each recipe.\n\n---\n\n## 5. Visual Shaders\n\nVisual shaders are a node-based graph editor (New ShaderMaterial → New VisualShader). Use them for quick prototypes, artist-tweakable values, and simple effects; use code for complex math, branching, or loops. Both compile to the same GPU code, so performance is identical.\n\n> See [references\u002Fvisual-shaders.md](references\u002Fvisual-shaders.md) for the choice table, steps, key nodes, and 4.7 node changes. In Godot 4.7 the `LinearToSRGB` node no longer clamps to `[0, 1]` on Forward+\u002FMobile; add a `Clamp` node if a graph relied on it.\n\n---\n\n## 6. Post-Processing Effects\n\nThe standard pattern: full-rect `ColorRect` with a canvas_item shader on top of the gameplay canvas. For 3D, use a `WorldEnvironment` Adjustment, Glow, or custom shader. For chained effects, render the world to a `SubViewport` then sample its texture in a final shader pass.\n\n> See [references\u002Fpost-processing.md](references\u002Fpost-processing.md) for the ColorRect overlay pattern, vignette + CRT\u002Fscanline shader source, the SubViewport pipeline, and WorldEnvironment 3D post-processing notes.\n\n---\n\n## 7. Compositor Effects (Godot 4.3+)\n\n`CompositorEffect` runs custom render passes at five points in the 3D render pipeline, from before the opaque pass to after the transparent pass — all before the built-in post effects and tonemapping. Use when ColorRect overlays aren't enough — multi-pass effects, depth-aware effects, custom AO\u002FSSR variants. Heavier setup than a screen-space shader; reach for it only when needed.\n\n> See [references\u002Fcompositor-effects.md](references\u002Fcompositor-effects.md) for setup, a custom CompositorEffect GDScript example, and built-in Compositor use cases.\n\n---\n\n## 8. Render Modes\n\nRender modes go on the first line after `shader_type` and control how the shader interacts with the rendering pipeline.\n\n### Canvas Item Render Modes\n\n```glsl\nshader_type canvas_item;\nrender_mode unshaded;           \u002F\u002F Ignore all lighting\nrender_mode light_only;         \u002F\u002F Only visible where lit\nrender_mode blend_add;          \u002F\u002F Additive blending (glow, fire)\nrender_mode blend_mix;          \u002F\u002F Standard alpha blending (default)\nrender_mode blend_premul_alpha; \u002F\u002F Pre-multiplied alpha\n```\n\n### Spatial Render Modes\n\n```glsl\nshader_type spatial;\nrender_mode unshaded;              \u002F\u002F No lighting calculations\nrender_mode cull_disabled;         \u002F\u002F Render both sides of faces\nrender_mode depth_draw_always;     \u002F\u002F Always write to depth buffer\nrender_mode specular_toon;         \u002F\u002F Toon specular model\nrender_mode diffuse_toon;          \u002F\u002F Toon diffuse model\nrender_mode blend_add;             \u002F\u002F Additive blending\n```\n\n---\n\n## 9. Stencil Buffer Effects (Godot 4.5+)\n\nGodot 4.5 exposes stencil write\u002Fread in spatial shaders via the `stencil_mode` statement (`stencil_mode write, 1;` \u002F `stencil_mode read, compare_equal, 1;`) and on `StandardMaterial3D` (Stencil: Outline \u002F X-Ray \u002F Custom), across all rendering backends. canvas_item shaders have no stencil modes. Enables portals, X-ray vision, outline masks, and holes-in-geometry effects that previously required compositor-level work.\n\n> See [references\u002Fstencil-buffer.md](references\u002Fstencil-buffer.md) for the `stencil_mode` reference and the X-ray vision portal worked example.\n\n---\n\n## 10. SMAA Antialiasing (Godot 4.5+)\n\nSub-pixel Morphological Antialiasing (SMAA 1x) is a built-in post-processing AA mode added in Godot 4.5. It produces clearer results than FXAA at a slightly higher performance cost, and is much cheaper than MSAA.\n\n### Enabling SMAA\n\n1. Open **Project Settings**\n2. Navigate to **Rendering → Anti Aliasing → Quality**\n3. Set **Screen Space AA** to **SMAA**\n\nSMAA can be combined with MSAA (for geometry edge aliasing) or used standalone. It does not require any shader code changes.\n\n| AA Mode | Sharpness | GPU cost | Ghosting |\n|---------|-----------|----------|----------|\n| Disabled | N\u002FA | None | None |\n| FXAA | Low (blurry) | Very low | Low |\n| **SMAA** | High | Low (slightly above FXAA) | Very low |\n| TAA | Medium (slight blur) | Medium | Possible |\n| MSAA 4x | High | High | None |\n\n> **When to use SMAA:** Prefer SMAA over FXAA for most desktop projects — it delivers noticeably sharper text and thin edges for a slightly higher cost. Combine SMAA + MSAA 2x for best quality at moderate cost.\n\nThe project setting is read at startup only. To switch at runtime set `get_viewport().screen_space_aa = Viewport.SCREEN_SPACE_AA_SMAA` (C#: `GetViewport().ScreenSpaceAA = Viewport.ScreenSpaceAAEnum.Smaa`). Forward+ and Mobile only — not Compatibility.\n\n---\n\n## 11. Shader Baker — Export-time Pre-compilation (Godot 4.5+)\n\nThe Shader Baker converts project shaders to the target driver's format at export time, which shortens first-launch load — most on macOS\u002FiOS (Metal) and Windows (D3D12), where that conversion is slow. It does not remove pipeline-compilation stutter the first time a material renders, works only on the Forward+ and Mobile renderers, and bakes only for drivers the exporting machine's OS supports. Enable it per export preset for release builds; leave it off for development.\n\n> See [references\u002Fshader-baker.md](references\u002Fshader-baker.md) for enabling steps and the with\u002Fwithout comparison.\n\n---\n\n## 12. Common Pitfalls\n\n| Symptom | Cause | Fix |\n|-------------------------------------|----------------------------------------------------|------------------------------------------------------------------|\n| Shader has no visible effect | Material not assigned or shader not saved | Check node's Material property in Inspector |\n| Transparent parts render as black | Alpha not handled in shader | Set `COLOR.a = tex.a;` and use appropriate blend mode |\n| Uniform doesn't appear in Inspector | Typo in uniform name or wrong type | Re-save the shader; check for compilation errors |\n| Texture appears stretched\u002Ftiled | Missing `repeat_enable` or wrong UV scale | Add `repeat_enable` hint to sampler2D uniform |\n| Shader works in editor but not in game | Screen texture uniform needs backbuffer | Use `hint_screen_texture` on a `sampler2D` uniform (Godot 4.x) |\n| Performance drops with many shaders | Each unique shader = draw call break | Share ShaderMaterial instances; use uniforms for variation |\n| Screen-space UV is wrong | `SCREEN_UV` not available in some contexts | Ensure the node is rendered in the correct viewport |\n| Visual shader node missing | Node was renamed or removed in newer Godot version | Check Godot docs for the current node name |\n\n> ⚠️ **Changed in Godot 4.7:** `textureQueryLod()` is available only in the fragment shader, and Godot 4.7 enforces this with a compile error — shaders calling it from `vertex()` stop compiling after upgrading. Move the call into `fragment()`. See [GH-118962](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F118962).\n\n---\n\n## 13. Implementation Checklist\n\n- [ ] Shader type matches the node type (`canvas_item` for 2D, `spatial` for 3D)\n- [ ] Uniforms use appropriate hints (`hint_range`, `source_color`, `filter_linear_mipmap`)\n- [ ] Shared visual effects use the same Shader resource with separate ShaderMaterial instances\n- [ ] Post-processing shaders are on a CanvasLayer (2D) or WorldEnvironment (3D), not on game objects\n- [ ] `TEXTURE` is sampled in canvas_item shaders (otherwise sprite content is lost)\n- [ ] Alpha-transparent shaders set `COLOR.a` correctly and use `blend_mix` render mode\n- [ ] Animated shader parameters (dissolve, flash) are driven by Tweens or AnimationPlayer, not `_process`\n- [ ] Screen-reading shaders use `hint_screen_texture` on a `sampler2D` uniform (Godot 4.x approach)\n- [ ] Complex shaders are profiled with the Godot profiler to check GPU frame time\n- [ ] Stencil effects use two-pass materials (write pass first, read pass second) with correct render priority (Godot 4.5+)\n- [ ] SMAA is preferred over FXAA for desktop builds (sharper edges, slightly higher cost) — set in Project Settings → Rendering → Anti Aliasing (Godot 4.5+)\n- [ ] Shader Baker is enabled in release presets for D3D12 and Metal targets to shorten first-launch load (Forward+\u002FMobile only; Godot 4.5+)\n","# Shaders in Godot 4.3+\n\nAll examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **animation-system** for shader-driven effects like hit flash, **godot-optimization** for shader performance considerations, **camera-system** for post-processing camera effects, **2d-essentials** for 2D lighting, pixel-art shaders, and CanvasTexture normal maps, **3d-essentials** for spatial shaders and environment materials, **particles-vfx** for custom particle shaders, **tween-animation** for animating shader parameters at runtime.\n\n---\n\n## 1. Core Concepts\n\n### Shader Types\n\n| Shader Type | Applied To | Use For |\n|------------------|--------------------------|--------------------------------------------------|\n| `canvas_item` | 2D nodes (Sprite2D, Control, etc.) | 2D effects — outlines, dissolve, color swap |\n| `spatial` | 3D meshes (MeshInstance3D) | 3D materials — water, terrain, toon shading |\n| `particles` | GPUParticles2D\u002F3D | Custom particle behavior |\n| `sky` | WorldEnvironment | Procedural sky rendering |\n| `fog` | FogVolume | Volumetric fog effects |\n\n### Shader vs ShaderMaterial\n\n```\nShader (.gdshader)        → The code (GLSL-like language)\nShaderMaterial            → Instance of a shader with specific uniform values\nCanvasItemMaterial \u002F StandardMaterial3D → Built-in materials (no code needed)\n```\n\nMultiple nodes can share the same Shader but have different ShaderMaterial instances with different uniform values (e.g., same dissolve shader but different dissolve progress per enemy).\n\n### Creating a Shader\n\n1. Select a node (e.g., Sprite2D)\n2. In Inspector → Material → New ShaderMaterial\n3. On the ShaderMaterial → Shader → New Shader\n4. Edit the `.gdshader` file in the built-in editor\n\nOr create a `.gdshader` file directly in the FileSystem dock.\n\n---\n\n## 2. Godot Shader Language Basics\n\nGodot uses a GLSL ES 3.0-like language with Godot-specific additions.\n\n### Minimal Canvas Item Shader\n\n```glsl\nshader_type canvas_item;\n\nvoid fragment() {\n    \u002F\u002F COLOR is the output pixel color\n    \u002F\u002F TEXTURE is the sprite's texture\n    \u002F\u002F UV is the texture coordinate (0,0 top-left to 1,1 bottom-right)\n    vec4 tex = texture(TEXTURE, UV);\n    COLOR = tex;\n}\n```\n\n### Minimal Spatial Shader\n\n```glsl\nshader_type spatial;\n\nvoid fragment() {\n    \u002F\u002F ALBEDO is the base color (vec3)\n    ALBEDO = vec3(0.8, 0.2, 0.2);\n}\n```\n\n### Built-in Variables (canvas_item)\n\n| Variable | Type | Description |\n|------------|--------|---------------------------------------|\n| `UV` | `vec2` | Texture coordinates |\n| `COLOR` | `vec4` | Output color (set this in `fragment()`) |\n| `TEXTURE` | `sampler2D` | The node's texture |\n| `VERTEX` | `vec2` | Vertex position (in `vertex()`) |\n| `TIME` | `float`| Elapsed time in seconds |\n| `SCREEN_UV`| `vec2` | Screen-space UV (for screen effects) |\n\n> `SCREEN_TEXTURE` was removed in Godot 4.0. To read the screen, declare a uniform: `uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;`\n\n### Built-in Variables (spatial)\n\n| Variable | Type | Description |\n|-------------|--------|---------------------------------------|\n| `ALBEDO` | `vec3` | Base surface color |\n| `METALLIC` | `float`| Metallic value (0.0–1.0) |\n| `ROUGHNESS` | `float`| Roughness value (0.0–1.0) |\n| `NORMAL` | `vec3` | Surface normal (for normal mapping) |\n| `EMISSION` | `vec3` | Emissive color |\n| `ALPHA` | `float`| Transparency (writing it moves the material to the transparent pass) |\n| `VERTEX` | `vec3` | Vertex position (in `vertex()`) |\n\n### Uniforms (Shader Parameters)\n\nUniforms expose shader values to the Inspector and code.\n\n```glsl\nshader_type canvas_item;\n\nuniform float speed : hint_range(0.0, 10.0, 0.1) = 1.0;\nuniform vec4 tint_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);\nuniform sampler2D noise_texture : filter_linear_mipmap;\n\nvoid fragment() {\n    vec4 tex = texture(TEXTURE, UV);\n    COLOR = tex * tint_color;\n}\n```\n\n### Common Uniform Hints\n\n| Hint | Type | Description |\n|-----------------------------|--------------|-------------------------------------|\n| `hint_range(min, max, step)` | `float\u002Fint` | Slider in Inspector |\n| `source_color` | `vec4` | Color picker in Inspector |\n| `filter_linear_mipmap` | `sampler2D` | Texture filtering mode |\n| `repeat_enable` | `sampler2D` | Allow texture tiling |\n| `hint_normal` | `sampler2D` | Treat as normal map |\n\n### Setting Uniforms from Code\n\n#### GDScript\n\n```gdscript\nvar mat: ShaderMaterial = $Sprite2D.material\nmat.set_shader_parameter(\"speed\", 2.0)\nmat.set_shader_parameter(\"tint_color\", Color.RED)\n```\n\n#### C#\n\n```csharp\nvar mat = GetNode\u003CSprite2D>(\"Sprite2D\").Material as ShaderMaterial;\nmat.SetShaderParameter(\"speed\", 2.0f);\nmat.SetShaderParameter(\"tint_color\", Colors.Red);\n```\n\n---\n\n## 3. Common 2D Shader Recipes\n\nThe canvas_item recipes most projects need: **dissolve** (noise + edge glow), **outline** (sample neighbors, expand alpha), **flash-white** (uniform-driven hit effect), **color swap** (palette shift), **scrolling UV** (water\u002Flava\u002Fclouds), **wave distortion**.\n\n> See [references\u002F2d-shader-recipes.md](references\u002F2d-shader-recipes.md) for complete shader code for all six recipes.\n\n---\n\n## 4. Common 3D Shader Recipes\n\nSpatial-shader recipes: **toon\u002Fcel shading** (banded NdotL), **rim lighting \u002F Fresnel** (1 - NdotV), **simple water surface** (UV scroll + normal-map blend + Fresnel).\n\n> See [references\u002F3d-shader-recipes.md](references\u002F3d-shader-recipes.md) for the full shader source for each recipe.\n\n---\n\n## 5. Visual Shaders\n\nVisual shaders are a node-based graph editor (New ShaderMaterial → New VisualShader). Use them for quick prototypes, artist-tweakable values, and simple effects; use code for complex math, branching, or loops. Both compile to the same GPU code, so performance is identical.\n\n> See [references\u002Fvisual-shaders.md](references\u002Fvisual-shaders.md) for the choice table, steps, key nodes, and 4.7 node changes. In Godot 4.7 the `LinearToSRGB` node no longer clamps to `[0, 1]` on Forward+\u002FMobile; add a `Clamp` node if a graph relied on it.\n\n---\n\n## 6. Post-Processing Effects\n\nThe standard pattern: full-rect `ColorRect` with a canvas_item shader on top of the gameplay canvas. For 3D, use a `WorldEnvironment` Adjustment, Glow, or custom shader. For chained effects, render the world to a `SubViewport` then sample its texture in a final shader pass.\n\n> See [references\u002Fpost-processing.md](references\u002Fpost-processing.md) for the ColorRect overlay pattern, vignette + CRT\u002Fscanline shader source, the SubViewport pipeline, and WorldEnvironment 3D post-processing notes.\n\n---\n\n## 7. Compositor Effects (Godot 4.3+)\n\n`CompositorEffect` runs custom render passes at five points in the 3D render pipeline, from before the opaque pass to after the transparent pass — all before the built-in post effects and tonemapping. Use when ColorRect overlays aren't enough — multi-pass effects, depth-aware effects, custom AO\u002FSSR variants. Heavier setup than a screen-space shader; reach for it only when needed.\n\n> See [references\u002Fcompositor-effects.md](references\u002Fcompositor-effects.md) for setup, a custom CompositorEffect GDScript example, and built-in Compositor use cases.\n\n---\n\n## 8. Render Modes\n\nRender modes go on the first line after `shader_type` and control how the shader interacts with the rendering pipeline.\n\n### Canvas Item Render Modes\n\n```glsl\nshader_type canvas_item;\nrender_mode unshaded;           \u002F\u002F Ignore all lighting\nrender_mode light_only;         \u002F\u002F Only visible where lit\nrender_mode blend_add;          \u002F\u002F Additive blending (glow, fire)\nrender_mode blend_mix;          \u002F\u002F Standard alpha blending (default)\nrender_mode blend_premul_alpha; \u002F\u002F Pre-multiplied alpha\n```\n\n### Spatial Render Modes\n\n```glsl\nshader_type spatial;\nrender_mode unshaded;              \u002F\u002F No lighting calculations\nrender_mode cull_disabled;         \u002F\u002F Render both sides of faces\nrender_mode depth_draw_always;     \u002F\u002F Always write to depth buffer\nrender_mode specular_toon;         \u002F\u002F Toon specular model\nrender_mode diffuse_toon;          \u002F\u002F Toon diffuse model\nrender_mode blend_add;             \u002F\u002F Additive blending\n```\n\n---\n\n## 9. Stencil Buffer Effects (Godot 4.5+)\n\nGodot 4.5 exposes stencil write\u002Fread in spatial shaders via the `stencil_mode` statement (`stencil_mode write, 1;` \u002F `stencil_mode read, compare_equal, 1;`) and on `StandardMaterial3D` (Stencil: Outline \u002F X-Ray \u002F Custom), across all rendering backends. canvas_item shaders have no stencil modes. Enables portals, X-ray vision, outline masks, and holes-in-geometry effects that previously required compositor-level work.\n\n> See [references\u002Fstencil-buffer.md](references\u002Fstencil-buffer.md) for the `stencil_mode` reference and the X-ray vision portal worked example.\n\n---\n\n## 10. SMAA Antialiasing (Godot 4.5+)\n\nSub-pixel Morphological Antialiasing (SMAA 1x) is a built-in post-processing AA mode added in Godot 4.5. It produces clearer results than FXAA at a slightly higher performance cost, and is much cheaper than MSAA.\n\n### Enabling SMAA\n\n1. Open **Project Settings**\n2. Navigate to **Rendering → Anti Aliasing → Quality**\n3. Set **Screen Space AA** to **SMAA**\n\nSMAA can be combined with MSAA (for geometry edge aliasing) or used standalone. It does not require any shader code changes.\n\n| AA Mode | Sharpness | GPU cost | Ghosting |\n|---------|-----------|----------|----------|\n| Disabled | N\u002FA | None | None |\n| FXAA | Low (blurry) | Very low | Low |\n| **SMAA** | High | Low (slightly above FXAA) | Very low |\n| TAA | Medium (slight blur) | Medium | Possible |\n| MSAA 4x | High | High | None |\n\n> **When to use SMAA:** Prefer SMAA over FXAA for most desktop projects — it delivers noticeably sharper text and thin edges for a slightly higher cost. Combine SMAA + MSAA 2x for best quality at moderate cost.\n\nThe project setting is read at startup only. To switch at runtime set `get_viewport().screen_space_aa = Viewport.SCREEN_SPACE_AA_SMAA` (C#: `GetViewport().ScreenSpaceAA = Viewport.ScreenSpaceAAEnum.Smaa`). Forward+ and Mobile only — not Compatibility.\n\n---\n\n## 11. Shader Baker — Export-time Pre-compilation (Godot 4.5+)\n\nThe Shader Baker converts project shaders to the target driver's format at export time, which shortens first-launch load — most on macOS\u002FiOS (Metal) and Windows (D3D12), where that conversion is slow. It does not remove pipeline-compilation stutter the first time a material renders, works only on the Forward+ and Mobile renderers, and bakes only for drivers the exporting machine's OS supports. Enable it per export preset for release builds; leave it off for development.\n\n> See [references\u002Fshader-baker.md](references\u002Fshader-baker.md) for enabling steps and the with\u002Fwithout comparison.\n\n---\n\n## 12. Common Pitfalls\n\n| Symptom | Cause | Fix |\n|-------------------------------------|----------------------------------------------------|------------------------------------------------------------------|\n| Shader has no visible effect | Material not assigned or shader not saved | Check node's Material property in Inspector |\n| Transparent parts render as black | Alpha not handled in shader | Set `COLOR.a = tex.a;` and use appropriate blend mode |\n| Uniform doesn't appear in Inspector | Typo in uniform name or wrong type | Re-save the shader; check for compilation errors |\n| Texture appears stretched\u002Ftiled | Missing `repeat_enable` or wrong UV scale | Add `repeat_enable` hint to sampler2D uniform |\n| Shader works in editor but not in game | Screen texture uniform needs backbuffer | Use `hint_screen_texture` on a `sampler2D` uniform (Godot 4.x) |\n| Performance drops with many shaders | Each unique shader = draw call break | Share ShaderMaterial instances; use uniforms for variation |\n| Screen-space UV is wrong | `SCREEN_UV` not available in some contexts | Ensure the node is rendered in the correct viewport |\n| Visual shader node missing | Node was renamed or removed in newer Godot version | Check Godot docs for the current node name |\n\n> ⚠️ **Changed in Godot 4.7:** `textureQueryLod()` is available only in the fragment shader, and Godot 4.7 enforces this with a compile error — shaders calling it from `vertex()` stop compiling after upgrading. Move the call into `fragment()`. See [GH-118962](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F118962).\n\n---\n\n## 13. Implementation Checklist\n\n- [ ] Shader type matches the node type (`canvas_item` for 2D, `spatial` for 3D)\n- [ ] Uniforms use appropriate hints (`hint_range`, `source_color`, `filter_linear_mipmap`)\n- [ ] Shared visual effects use the same Shader resource with separate ShaderMaterial instances\n- [ ] Post-processing shaders are on a CanvasLayer (2D) or WorldEnvironment (3D), not on game objects\n- [ ] `TEXTURE` is sampled in canvas_item shaders (otherwise sprite content is lost)\n- [ ] Alpha-transparent shaders set `COLOR.a` correctly and use `blend_mix` render mode\n- [ ] Animated shader parameters (dissolve, flash) are driven by Tweens or AnimationPlayer, not `_process`\n- [ ] Screen-reading shaders use `hint_screen_texture` on a `sampler2D` uniform (Godot 4.x approach)\n- [ ] Complex shaders are profiled with the Godot profiler to check GPU frame time\n- [ ] Stencil effects use two-pass materials (write pass first, read pass second) with correct render priority (Godot 4.5+)\n- [ ] SMAA is preferred over FXAA for desktop builds (sharper edges, slightly higher cost) — set in Project Settings → Rendering → Anti Aliasing (Godot 4.5+)\n- [ ] Shader Baker is enabled in release presets for D3D12 and Metal targets to shorten first-launch load (Forward+\u002FMobile only; Godot 4.5+)\n",{"name":5,"description":7},"master","60c28fdc40706a24576731e9fb3508b9c95258ad","skills\u002Fshader-basics",63,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter","https:\u002F\u002Fgithub.com\u002Fjame581","https:\u002F\u002Fjanmesarc.online\u002F","Software engineer. My biggest passion is game development.","2026-11-14 20:45:49",{"source":8,"skillName":5,"commands":50,"prompt":60,"zipAvailable":61},[51,54,57],{"tool":52,"command":53},"npx","npx skills add jame581\u002FGodotPrompter --skill shader-basics",{"tool":55,"command":56},"bunx","bunx skills add jame581\u002FGodotPrompter --skill shader-basics",{"tool":58,"command":59},"pnpm","pnpm dlx skills add jame581\u002FGodotPrompter --skill shader-basics","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002FSKILL.md",true,[63,69,73,77,81,85,89],{"path":64,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":67,"sourceHtmlUrl":68},"references\u002F2d-shader-recipes.md","REFERENCE","参考文档",3707,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002Freferences\u002F2d-shader-recipes.md",{"path":70,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":71,"sourceHtmlUrl":72},"references\u002F3d-shader-recipes.md",1703,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002Freferences\u002F3d-shader-recipes.md",{"path":74,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fcompositor-effects.md",4394,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002Freferences\u002Fcompositor-effects.md",{"path":78,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":79,"sourceHtmlUrl":80},"references\u002Fpost-processing.md",2735,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002Freferences\u002Fpost-processing.md",{"path":82,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":83,"sourceHtmlUrl":84},"references\u002Fshader-baker.md",1996,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002Freferences\u002Fshader-baker.md",{"path":86,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":87,"sourceHtmlUrl":88},"references\u002Fstencil-buffer.md",3496,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002Freferences\u002Fstencil-buffer.md",{"path":90,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":91,"sourceHtmlUrl":92},"references\u002Fvisual-shaders.md",3094,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fshader-basics\u002Freferences\u002Fvisual-shaders.md",[94,113,134,164,188,203],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":35},"01M6KRFE5BR2PSD08ZKDAS66R7","xr-development","Use when building VR\u002FAR\u002FXR applications — OpenXR setup, XROrigin3D, hand tracking, controllers, passthrough, and Meta Quest deployment in Godot 4.3+","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fxr-development\u002FSKILL.md",[],[101,102,34,103,33,104,105,106,107,108,109,24,110,111,112],"xr development","development","deployment","vr","setup","tracking","godot 4","ar","hand","Meta","applications","quest",{"skillNo":114,"name":115,"nameZh":6,"description":116,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":35},"01M6KRF8GZTG1TAS506MFBSGFC","web-services","Use when a Godot game calls a web server — HTTPRequest, downloads, REST\u002FJSON APIs, auth headers, WebSocketPeer clients, TLS, retries, and keeping secrets out of the build. Not for game networking\u002FRPCs (multiplayer-basics) or browser export (web-export)","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-services\u002FSKILL.md",[],[120,121,122,123,124,125,126,127,24,34,33,128,129,130,131,132,133],"web services","web","services","tls","retries","calling","auth","downloads","clients","headers","secrets","json","build","REST",{"skillNo":135,"name":136,"nameZh":6,"description":137,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":138,"categories":139,"keywords":145,"publishedAt":35},"01M6KRF38Q4WSKAYFS56PG87T0","web-export","Use when shipping a Godot game to the browser — Web export preset options, threads vs no-threads and COOP\u002FCOEP headers, hosting on itch.io or your own server, PWA, JavaScriptBridge, user:\u002F\u002F persistence, audio and input limits, and load size","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-export\u002FSKILL.md",[140],{"categoryNo":141,"categoryName":142,"taxonomyType":143,"taxonomyTypeDesc":144},"01JBSEEDCAT000000000000016","图像与多媒体","SCENARIO","使用场景",[121,146,147,148,149,150,151,152,129,153,154,34,155,156,157,158,159,160,24,161,162,163],"export","web export","threads","limits","shipping","size","options","hosting","input","Coop","preset","browser","game","io","load","pwa","Audio","server",{"skillNo":165,"name":166,"nameZh":6,"description":167,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":168,"categories":169,"keywords":178,"publishedAt":35},"01M6KREYFETEBH62ZTN6EZH2X3","using-godot-prompter","Bootstrap skill — establishes how to find and use GodotPrompter skills, with platform-specific tool mapping","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fusing-godot-prompter\u002FSKILL.md",[170,173],{"categoryNo":171,"categoryName":172,"taxonomyType":143,"taxonomyTypeDesc":144},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":174,"categoryName":175,"taxonomyType":176,"taxonomyTypeDesc":177},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[33,179,180,181,182,24,183,184,185,186,187],"using godot prompter","find","with","bootstrap","tool","platform","mapping","how","how to",{"skillNo":189,"name":190,"nameZh":6,"description":191,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":192,"categories":193,"keywords":194,"publishedAt":35},"01M6KRER5G7EQWKGAFN8QJKQ69","tween-animation","Use when implementing tweens — property animation, method tweening, chaining, parallel sequences, easing, and common UI\u002Fgameplay motion recipes","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Ftween-animation\u002FSKILL.md",[],[195,196,24,197,198,199,200,201,31,27,23,34,202],"tween animation","Animation","motion","parallel","gameplay","chaining","ui","sequences",{"skillNo":204,"name":205,"nameZh":6,"description":206,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":207,"categories":208,"keywords":209,"publishedAt":35},"01M6KREKGCQMVDV8WX7HWX8BZG","state-machine","Use when building a state machine or refactoring logic into one — enum, node, and resource-based FSM patterns with trade-offs. Not for adding states to an existing one","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fstate-machine\u002FSKILL.md",[],[210,211,212,33,34,213,214,215,216,217,181,24,23,218],"state","state machine","machine","patterns","node","fsm","state machines","trade","trade-offs"]