2D sdf lighting shader without shadows or light occlusion
it is a 2d light without shadows or light occlusion.
it uses sdf to add onto sdf occluders its own light.
it also can and should be used with itself for darkness by turning on the “night”.
Only areas w/ SDF occluder will be occluded(will block light)
It should be used w/ ColorRect
the scene tree should be made like:
–rest of the game
-the darkening node
–all of the lights
also
if you turn on the night then set color alpha to 0
Shader code
shader_type canvas_item;
render_mode unshaded;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform vec2 middle=vec2(0.5,0.5);
uniform float energy=.7;
uniform vec4 color: source_color;
uniform float size=1.0;
uniform float light_lenght=0.9;
//uniform vec4 shadow_darkness: source_color;
// basically turns screen dark
uniform bool dark=false;
void fragment(){
vec2 sdf_pos = screen_uv_to_sdf(SCREEN_UV);
float sdf_tex=texture_sdf(sdf_pos);
float inside=0.0;
//
float dist = distance(middle*2.0/size,(UV*2.0/size));
vec4 light = vec4(0,0,0,1);
vec4 acc_col_wout_sh=vec4(0.0);
//
vec4 screen_col=texture(SCREEN_TEXTURE,SCREEN_UV);
//
//defining the inside
if (sdf_tex<=-0.01)
inside=sdf_tex;
vec3 col = color.rgb+screen_col.rgb;
float sdf_light=(inside-inside*light_lenght);
float fade_away=color.a-(dist);
acc_col_wout_sh += (vec4(col,((fade_away)+(sdf_light))))*energy;
//
if (dark==false)
COLOR = vec4(acc_col_wout_sh.rgb,acc_col_wout_sh.a);
if (dark==true)
COLOR = vec4(0.0,0.0,0.0,1.0);
}


