Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shader_type canvas_item;
- uniform vec4 modulate_color : source_color = vec4(0.0);
- uniform vec4 black_point : source_color = vec4(0.0);
- uniform vec3 lights[100];
- uniform int number_of_lights = 0;
- uniform float band_1_radius = 54;
- uniform float band_2_radius = 38;
- uniform float band_1_strength = 0.3;
- uniform float band_2_strength = 0.6;
- uniform sampler2D screen_texture : hint_screen_texture, filter_nearest;
- uniform float light_radius = 64.0;
- struct Light_data{
- float dist;
- float radius;
- };
- Light_data distance_to_light(vec2 coords) {
- float dist = 1000.0;
- float rad = 0.0;
- Light_data data;
- float best_ratio = 1000.0;
- for (int i = 0; i < number_of_lights; i++) {
- float new_dist = distance(coords, lights[i].xy);
- float new_rad = lights[i].z;
- float ratio = new_dist / new_rad;
- if (ratio < best_ratio) {
- best_ratio = ratio;
- data.dist = new_dist;
- data.radius = new_rad;
- }
- }
- return data;
- }
- vec4 set_black_point(vec4 color) {
- float bp_avg = black_point.r + black_point.g + black_point.b;
- float color_avg = color.r + color.g + color.b;
- if (color_avg < bp_avg) {
- return black_point;
- } else {
- return color;
- }
- }
- vec4 modulate(vec4 color, Light_data data) {
- vec4 modulated = color * modulate_color;
- float band_radius = 0.8 * data.radius;
- if (data.dist > data.radius) {
- return modulated;
- }
- if (data.dist > band_radius) {
- return mix(modulated, color, band_1_strength);
- }
- return color;
- }
- void fragment() {
- COLOR = texture(screen_texture, SCREEN_UV);
- if (number_of_lights > 0){
- COLOR = modulate(COLOR, distance_to_light(FRAGCOORD.xy));
- COLOR = set_black_point(COLOR);
- }
- else{
- COLOR = COLOR *modulate_color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement