Add some cool shaders
This commit is contained in:
@ -1,23 +1,25 @@
|
||||
shader_type spatial;
|
||||
render_mode cull_front, unshaded;
|
||||
@shader_type spatial;
|
||||
@render_mode unshaded;
|
||||
|
||||
uniform vec4 outline_color : source_color;
|
||||
uniform float outline_width = 1.0;
|
||||
|
||||
void vertex() {
|
||||
vec4 clip_position = PROJECTION_MATRIX * (MODELVIEW_MATRIX * vec4(VERTEX, 1.0));
|
||||
vec3 clip_normal = mat3(PROJECTION_MATRIX) * (mat3(MODELVIEW_MATRIX) * NORMAL);
|
||||
|
||||
vec2 offset = normalize(clip_normal.xy) / VIEWPORT_SIZE * clip_position.w * outline_width * 2.0;
|
||||
|
||||
clip_position.xy += offset;
|
||||
|
||||
POSITION = clip_position;
|
||||
}
|
||||
@uniform sampler2D albedo_texture;
|
||||
@uniform vec3 light_color = vec3(1.0, 1.0, 1.0);
|
||||
@uniform float outline_width = 0.05;
|
||||
@uniform vec3 outline_color = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = outline_color.rgb;
|
||||
if (outline_color.a < 1.0) {
|
||||
ALPHA = outline_color.a;
|
||||
}
|
||||
}
|
||||
// Fake directional light
|
||||
vec3 light_dir = normalize(vec3(0.5, 1.0, -0.5));
|
||||
vec3 norm = normalize(NORMAL);
|
||||
float intensity = dot(norm, light_dir);
|
||||
|
||||
// Cel shading - Quantized lighting steps
|
||||
float shade = step(0.1, intensity) * 0.3 +
|
||||
step(0.3, intensity) * 0.4 +
|
||||
step(0.6, intensity) * 0.3;
|
||||
|
||||
// Sample texture and apply shading
|
||||
vec4 tex_color = texture(albedo_texture, UV);
|
||||
vec3 final_color = tex_color.rgb * shade * light_color;
|
||||
|
||||
ALBEDO = final_color;
|
||||
}
|
||||
|
36
shaders/test.gdshader
Normal file
36
shaders/test.gdshader
Normal file
@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user