Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document CURRENT_RENDERER built-in shader define #10231

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tutorials/shaders/shader_reference/shader_preprocessor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,35 @@ the preprocessor step.
// This causes a shader compilation error, as the `#if USE_LIGHT` and `#endif`
// are included as-is in the final shader code.
#endif

Built-in defines
----------------

Current renderer
^^^^^^^^^^^^^^^^

Since Godot 4.4, you can check which renderer is currently used with the built-in
defines ``CURRENT_RENDERER``, ``RENDERER_COMPATIBILITY``, ``RENDERER_MOBILE``,
and ``RENDERER_FORWARD_PLUS``:

- ``CURRENT_RENDERER`` is set to either ``0``, ``1``, or ``2`` depending on the
current renderer.
- ``RENDERER_COMPATIBILITY`` is always ``0``.
- ``RENDERER_MOBILE`` is always ``1``.
- ``RENDERER_FORWARD_PLUS`` is always ``2``.

As an example, this shader sets ``ALBEDO`` to a different color in each renderer:

.. code-block:: glsl

shader_type spatial;

void fragment() {
#if CURRENT_RENDERER == RENDERER_COMPATIBILITY
ALBEDO = vec3(0.0, 0.0, 1.0);
#elif CURRENT_RENDERER == RENDERER_MOBILE
ALBEDO = vec3(1.0, 0.0, 0.0);
#else // CURRENT_RENDERER == RENDERER_FORWARD_PLUS
ALBEDO = vec3(0.0, 1.0, 0.0);
#endif
}