37 lines
1.1 KiB
Plaintext
37 lines
1.1 KiB
Plaintext
shader_type spatial;
|
|
render_mode unshaded;
|
|
|
|
uniform vec4 light_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
|
|
uniform sampler2D albedo_texture;
|
|
uniform float outline_width = 0.05; // Thickness of outline
|
|
uniform vec4 outline_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
|
|
|
|
void vertex() {
|
|
// Expanding vertices along normals for outlines (inverted hull technique)
|
|
if (OUTLINE_PASS) {
|
|
VERTEX += NORMAL * outline_width;
|
|
}
|
|
}
|
|
|
|
void fragment() {
|
|
vec3 light_dir = normalize(vec3(0.5, 1.0, -0.5)); // Fake directional light
|
|
vec3 norm = normalize(NORMAL);
|
|
float intensity = dot(norm, light_dir);
|
|
|
|
// Cel shading (quantized lighting levels)
|
|
float shade = smoothstep(0.1, 0.3, intensity) * 0.5 +
|
|
smoothstep(0.3, 0.6, intensity) * 0.3 +
|
|
smoothstep(0.6, 1.0, intensity) * 0.2;
|
|
|
|
// Sample texture and apply shading
|
|
vec4 tex_color = texture(albedo_texture, UV);
|
|
vec3 final_color = tex_color.rgb * shade * light_color.rgb;
|
|
|
|
// Outline pass
|
|
if (OUTLINE_PASS) {
|
|
final_color = outline_color.rgb;
|
|
}
|
|
|
|
ALBEDO = final_color;
|
|
}
|