54 lines
1.6 KiB
Plaintext
54 lines
1.6 KiB
Plaintext
// https://github.com/eldskald/godot4-cel-shader
|
|
shader_type spatial;
|
|
|
|
#define USE_ALPHA_CUTOFF 1
|
|
|
|
render_mode cull_disabled;
|
|
|
|
#include "includes/base_cel_shader.gdshaderinc"
|
|
|
|
group_uniforms BaseProperties;
|
|
#if USE_ALPHA_CUTOFF
|
|
uniform float alpha_cutoff : hint_range(0.0, 1.0) = 0.5;
|
|
#endif
|
|
uniform vec4 color : source_color = vec4(0.7, 0.12, 0.86, 1.0);
|
|
uniform sampler2D base_texture : source_color;
|
|
uniform vec4 specular : source_color = vec4(0.3, 0.3, 0.3, 0.5);
|
|
uniform sampler2D specular_texture : hint_default_white;
|
|
uniform vec4 fresnel : source_color = vec4(0.2, 0.2, 0.2, 0.3);
|
|
uniform sampler2D fresnel_texture : hint_default_white;
|
|
group_uniforms;
|
|
|
|
varying vec3 SPECULAR_COLOR;
|
|
varying float SPECULAR_STRENGTH;
|
|
varying vec3 FRESNEL_COLOR;
|
|
varying float FRESNEL_STRENGTH;
|
|
|
|
group_uniforms Tiling;
|
|
uniform vec2 uv_scale = vec2(1, 1);
|
|
uniform vec2 uv_offset = vec2(0, 0);
|
|
group_uniforms;
|
|
|
|
void vertex() { UV = UV * uv_scale.xy + uv_offset.xy; }
|
|
|
|
void fragment() {
|
|
ALBEDO = color.rgb * texture(base_texture, UV).rgb;
|
|
#if USE_ALPHA_CUTOFF
|
|
ALPHA = color.a * texture(base_texture, UV).a;
|
|
ALPHA_SCISSOR_THRESHOLD = alpha_cutoff;
|
|
#endif
|
|
|
|
SPECULAR_COLOR = specular.rgb * texture(specular_texture, UV).rgb;
|
|
SPECULAR_STRENGTH = specular.a * texture(specular_texture, UV).a;
|
|
FRESNEL_COLOR = fresnel.rgb * texture(fresnel_texture, UV).rgb;
|
|
FRESNEL_STRENGTH = fresnel.a * texture(fresnel_texture, UV).a;
|
|
}
|
|
|
|
void light() {
|
|
DIFFUSE_LIGHT +=
|
|
diffuse_light(ALBEDO, LIGHT_COLOR, LIGHT, NORMAL, ATTENUATION);
|
|
|
|
SPECULAR_LIGHT += fresnel_light(LIGHT_COLOR, FRESNEL_COLOR, FRESNEL_STRENGTH,
|
|
NORMAL, VIEW, LIGHT, ATTENUATION);
|
|
}
|