Wind Waker Style Eyes Over Hair Shader
This shader will draw one material over another, specifically replicating the way Link’s eyes and eyebrows are rendered in The Legend of Zelda: Wind Waker. As I mentioned in the video, I just put everything together. All the credit goes to Midrule and CattreesDev.
Shader code
// Wind Waker Style Eyes Over Hair Shader - Megalukes
// All credit goes to Midrule from Godot Forums and CattreesDev from Reddit
shader_type spatial;
render_mode blend_mix, depth_draw_always, cull_disabled, unshaded;
uniform float depth_offset = 0.1;
uniform sampler2D albedo_texture : source_color;
uniform vec4 albedo_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec3 uv1_scale = vec3(1.0, 1.0, 1.0);
uniform vec3 uv1_offset = vec3(0.0, 0.0, 0.0);
void vertex() {
UV=UV*uv1_scale.xy+uv1_offset.xy;
}
void fragment() {
vec4 tex = texture(albedo_texture, UV);
ALBEDO = tex.rgb * albedo_color.rgb;
ALPHA = tex.a * albedo_color.a;
//view to world(global) fragment position set to world_position
vec3 world_position = vec4(INV_VIEW_MATRIX * vec4(VERTEX,1)).xyz;
//set direction from fragment to camera in world space
vec3 dir2cam = normalize(CAMERA_POSITION_WORLD - world_position);
//move fragment towards camera in world(global) space
world_position += dir2cam * depth_offset;
//transform world_position from world(global) to view space
//then transform world_position from view to clip(ndc) space
vec4 ndc_offset = PROJECTION_MATRIX * VIEW_MATRIX * vec4(world_position,1);
//normalize ndc_offset.z and set depth
DEPTH = ndc_offset.z/ndc_offset.w;
}