Light shader

Godot’s Light2D has an annoying limit of 16, and while the official documentation recommends using Sprite2D with additive blending mode, it ends up not looking very good in a dark environment.

Here is a simple shader which was provided by HaruYou27!

No 16 limit, no performance issue, you can place as many lights as you want in a dark environment!

The final effect is as follows:

Shader code
shader_type canvas_item;
render_mode blend_add, unshaded;
// 2D light shader by HaruYou27.

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, repeat_disable, filter_nearest;

uniform float intensity = 10.0;

void fragment() {
    // Sample the underlying screen color
    vec3 under_color = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;

    // Make it brighter
    vec3 final_color = under_color * COLOR.rgb * intensity;

    // Don't forget the alpha value
    COLOR = vec4(final_color, COLOR.a);
}
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Custom 2D Light

fireball fire ball with light

Modulate Before Light

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tz0322
Tz0322
8 days ago

Cool, it works for me