Last active
October 11, 2020 11:02
-
-
Save hiulit/eacd3affd88884048120f63fd65b9154 to your computer and use it in GitHub Desktop.
Godot 3 light interact with shader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type canvas_item; | |
uniform vec4 dawn_color : hint_color = vec4(0.86, 0.70, 0.70, 1.0); | |
uniform vec4 day_color : hint_color = vec4(1.0, 1.0, 1.0, 1.0); | |
uniform vec4 dusk_color : hint_color = vec4(0.59, 0.66, 0.78, 1.0); | |
uniform vec4 night_color : hint_color = vec4(0.07, 0.09, 0.38, 1.0); | |
uniform float brightness : hint_range(0.0, 10.0, 0.01) = 1.0; | |
uniform float contrast : hint_range(0.0, 10.0, 0.01) = 1.0; | |
uniform float saturation : hint_range(0.0, 10.0, 0.01) = 1.0; | |
uniform float pop_strength : hint_range(0.0, 10.0, 0.01) = 1.0; | |
uniform float pop_threslhold : hint_range(0.0, 10.0, 0.01) = 1.0; | |
uniform bool overlay = false; | |
void fragment() { | |
vec3 cycle_color = night_color.rgb; | |
vec3 base_col = texture(SCREEN_TEXTURE, SCREEN_UV).rgb; | |
vec3 out_col = base_col; | |
vec4 final_color; | |
float grey = dot(base_col, vec3(0.299, 0.587, 0.114)); | |
if (overlay) { | |
if (grey > 0.5) { | |
out_col = 1.0 - (1.0 - 2.0 * (base_col - 0.5)) * (1.0 * cycle_color.rgb); | |
} else { | |
out_col = 2.0 * base_col * cycle_color.rgb; | |
} | |
} | |
out_col = mix(vec3(grey), out_col, saturation); | |
out_col = (out_col - 0.5) * contrast + 0.5; | |
out_col = out_col + pop_strength * max(grey - pop_threslhold, 0.0); | |
out_col = out_col * brightness; | |
if (AT_LIGHT_PASS) { | |
vec3 lights_col= texture(TEXTURE, UV).rgb; | |
grey = dot(lights_col, vec3(0.333)); | |
out_col = mix(out_col, base_col * normalize(lights_col + 0.05) * 3.0, grey); | |
out_col += 0.1 * lights_col; // optional | |
final_color = vec4(out_col, 1.0); | |
} else { | |
final_color = vec4(out_col * cycle_color.rgb, 1.0); | |
} | |
COLOR = final_color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment