Skip to Content

Godot Shader Notes

Learning Notes These are notes I’m making while learning about something. They are not comprehensive and may be limited in their usefulness.

TIME Is Offset From Engine Time

Annoyingly, TIME is not related to engine time (like Time.get_ticks_msec), but is a separate value private to the renderer.

This complicates some things. Say we wanted a shader that did something starting this frame, like a glow effect that fades out. We might do something like this:

uniform float startTime;
uniform vec3 emissionColor;

void fragment() {
    float timeSinceStart = TIME - startTime;
    float emissionFactor = clamp(1 - timeSinceStart, 0, 1);
	EMISSION = emissionColor * emissionFactor;
}

And then our game code would only need to set the shader parameter startTime to the engine time when the effect happens.

But because TIME and engine time aren’t related, and I can’t figure out a good way to calculate the offset, this approach doesn’t work. The only workaround I’ve got so far is to do the timeSinceStart calculation in CPU-land and pass that to the shader.

render_mode Controls the Pipeline

Although Godot doesn’t provide full control over the rendering pipeline (compared to, say, Unity), a lot of it can be managed through render_mode. unshaded means the result is just ALBEDO, for example.