batrix/shaders/cel_shader/includes/base_cel_shader.gdshaderinc
2025-02-27 02:08:29 +10:00

70 lines
1.8 KiB
Plaintext

// global uniform sampler2D diffuse_curve: repeat_disable;
// global uniform float specular_smoothness;
// global uniform float fresnel_smoothness;
uniform float specular_smoothness = 0.05;
uniform float fresnel_smoothness = 0.05;
float diffuse_sample(vec3 light, vec3 normal) {
// float remapped = (dot(light, normal) - (-1.0))/(1.0 - (-1.0));
// return texture(diffuse_curve, vec2(remapped, 1.0)).r;
return (dot(light, normal) - (-1.0))/(1.0 - (-1.0));
}
float is_lit(vec3 light, vec3 normal, float attenuation) {
return attenuation * diffuse_sample(light, normal);
}
vec3 diffuse_light(
vec3 albedo,
vec3 light_color,
vec3 light,
vec3 normal,
float attenuation
) {
// return albedo * light_color * is_lit(light, normal, attenuation);
return light_color * is_lit(light, normal, attenuation);
}
vec3 specular_light(
vec3 light_color,
vec3 specular_color,
float specular_strength,
vec3 normal,
vec3 view,
vec3 light,
float attenuation
) {
vec3 half = normalize(view + light);
float gloss = pow(2.0, 8.0 * (1.0 - specular_strength));
float intensity = pow(dot(normal, half), gloss * gloss);
return light_color
* specular_color
* is_lit(light, normal, attenuation)
* smoothstep(
0.05,
0.05 + specular_smoothness,
intensity
);
}
vec3 fresnel_light(
vec3 light_color,
vec3 fresnel_color,
float fresnel_strength,
vec3 normal,
vec3 view,
vec3 light,
float attenuation
) {
float fresnel_dot = 1.0 - dot(normal, view);
float fresnel_threshold = pow((1.0 - fresnel_strength), dot(light, normal));
return light_color
* fresnel_color
* is_lit(light, normal, attenuation)
* smoothstep(
fresnel_threshold - fresnel_smoothness / 2.0,
fresnel_threshold + fresnel_smoothness / 2.0,
fresnel_dot
);
}