Modulate Before Light
Before Light Modulate – Alters the color of the object before the light pass, preserving luminosity. The standard Modulate setting will change the color of the object and the light after the light has been applied.
Thanks
cybereality on Reddit – Provided the super helpful solution for Before Light Modulate.
Shader code
shader_type canvas_item;
uniform vec4 before_light_modulate : hint_color = vec4(1.0,1.0,1.0,1.0);
void fragment() {
vec4 texture_color = texture(TEXTURE, UV);
if (AT_LIGHT_PASS) {
COLOR = texture_color;
} else {
COLOR = texture_color * before_light_modulate;
}
}
Here is a working Godot 4 version:
shader_type canvas_item;
varying vec4 modulate;
void vertex()
{
modulate = COLOR;
}
void fragment()
{
vec4 color = texture(TEXTURE, UV);
COLOR = color * modulate;
}
void light()
{
vec4 color = texture(TEXTURE, UV);
LIGHT = vec4(color.rgb * LIGHT_COLOR.rgb * LIGHT_ENERGY, LIGHT_COLOR.a);
}