2D sdf lighting shader without shadows or light occlusion + (optional) pixelated lighting and hdr 2d

it is a 2d light without shadows or light occlusion. W/ hdr 2d .

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

for pixeletion effect set its pixel_size to x (x == one side of the square).

green/red/blue mult it is a mult for the respective color chanell

to use glow add enviroment turn on glow and set the background to canvas.

note:

when the “night” is true for lights overall color should be a lot darker and for white color should be black and energy should be 1.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;
uniform bool light=true;

uniform bool pixelated_light = false;
uniform float pixel_size=128;

uniform float red_mult = 1.0;
uniform float green_mult = 1.0;
uniform float blue_mult = 1.0;



void fragment(){
	if (light==true){
		vec2 sdf_pos = screen_uv_to_sdf(SCREEN_UV);
		float sdf_tex=texture_sdf(sdf_pos);
		float inside=0.0;
		//
		vec2 pixel_uv = floor(UV *pixel_size) / pixel_size;
		float dist;
		if (pixelated_light==true)
			 dist=distance(middle*2.0/size,(pixel_uv*2.0/size));
		if (pixelated_light==false)
			 dist=distance(middle*2.0/size,(UV*2.0/size));
		vec4 acc_col_wout_sh=vec4(0.0);
		//
		vec4 screen_col=texture(SCREEN_TEXTURE,SCREEN_UV);
		//defining the inside
		if (sdf_tex<=-0.1)
			inside=sdf_tex;
		vec3 col = (vec3(color.r*red_mult*energy,color.g*green_mult*energy,color.b*blue_mult*energy)+(screen_col.rgb));
		float sdf_light=((inside-inside*light_lenght));
		float fade_away=max((color.a-dist),0.0);
		if  (fade_away<=0.000){
			col = mix(screen_col.rgb,color.rgb,.0);}
		acc_col_wout_sh += (vec4(col,((fade_away)+(sdf_light))));
		//
		//
		if (dark==false){
			COLOR *= vec4(acc_col_wout_sh.rgb,max(acc_col_wout_sh.a,0.0));
			}
		if (dark==true)
			COLOR = vec4(0.0,0.0,0.0,1.0);
		}
}

Live Preview
Tags
2d, Bloom, hdr 2d, light, pixel, SDF
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from electrick

Related shaders

guest

0 Comments
Oldest
Newest Most Voted