Skip to content

Commit 1735319

Browse files
authored
Add section about editor-specific shader code (#552)
1 parent ded37db commit 1735319

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/en/manuals/shader.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,27 @@ vec3 get_red_color_inverted()
340340
}
341341
```
342342

343+
## Editor-specific shader code
344+
345+
When shaders are rendered in the Defold Editor viewport, a preprocessor definition `EDITOR` is available. This allows you to write shader code that behaves differently when running in the editor versus when running in the actual game engine.
346+
347+
This is particularly useful for:
348+
- Adding debug visualizations that should only appear in the editor.
349+
- Implementing editor-specific features like wireframe modes or material previews.
350+
- Providing fallback rendering for materials that might not work properly in the editor viewport.
351+
352+
Use the `#ifdef EDITOR` preprocessor directive to conditionally compile code that should only run in the editor:
353+
354+
```glsl
355+
#ifdef EDITOR
356+
// This code will only execute when the shader is rendered in the Defold Editor
357+
color_out = vec4(1.0, 0.0, 1.0, 1.0); // Magenta color for editor preview
358+
#else
359+
// This code will execute when running in the game
360+
color_out = texture(texture_sampler, var_texcoord0) * tint_pm;
361+
#endif
362+
```
363+
343364
## The rendering process
344365

345366
Before ending up on the screen, the data that you create for your game goes through a series of steps:

0 commit comments

Comments
 (0)