gamejam-march-28/shell_fur.gdshader
2025-03-29 23:25:13 -06:00

68 lines
2.1 KiB
Text

shader_type spatial;
// Can't figure out how to make back faces look good
// Flipping normals doesn't change their shading
render_mode cull_back, depth_prepass_alpha;
//#include "res://addons/vertexanimations/va_default.gdshaderinc"
#include "res://color.gdshaderinc"
#include "res://noise.gdshaderinc"
varying float fur_length;
varying float is_shell;
varying float shell_id_factor;
varying vec3 ungroomed_3d_uv;
varying vec3 groomed_normals;
uniform float scale = 700.0;
uniform float clump_scale = 90.1;
uniform float grooming_factor = 0.008;
uniform sampler2D hair_curve_shape : repeat_disable;
uniform sampler2D hair_stem_shape : repeat_disable;
uniform sampler2D hair_clump_radius : repeat_disable;
uniform sampler2D hair_clump_height : repeat_disable;
uniform sampler2D hair_base_color : source_color;
uniform sampler2D hair_depth_factor : repeat_disable;
uniform sampler2D normals : hint_normal;
void vertex() {
fur_length = CUSTOM0.w;
shell_id_factor = CUSTOM2.r;
ungroomed_3d_uv = CUSTOM0.xzy;
ungroomed_3d_uv.z *= -1.0;
groomed_normals = CUSTOM1.xzy;
groomed_normals.z *= -1.0;
is_shell = CUSTOM2.y;
//VERTEX = vertex_animation_default(VERTEX_ID, VERTEX);
}
void fragment() {
if (is_shell <= 0.0001) {
discard;
}
float curve_shape = texture(hair_curve_shape, vec2(1.0-shell_id_factor)).r;
float groom_weight = (((1.0-fur_length)*grooming_factor) + grooming_factor) * curve_shape;
vec3 groomed_3d_uv = ungroomed_3d_uv + (groomed_normals * groom_weight);
float clump_radius = 1.0-texture(hair_clump_radius, vec2(shell_worley(groomed_3d_uv, clump_scale))).r;
float clump_height = texture(hair_clump_height, vec2(clump_radius)).r;
float clump_shell_id = shell_id_factor / clump_height;
float stem_shape = texture(hair_stem_shape, vec2(clump_shell_id)).r;
float c = shell_worley(groomed_3d_uv, scale);
if (c > stem_shape) {
discard;
}
vec3 sample_hair_base_color = COLOR.rgb;
vec3 base = rgb2hsv(sample_hair_base_color);
float v = base.z * texture(hair_depth_factor, vec2(shell_id_factor)).r;
ALBEDO = hsv2rgb(vec3(base.x, base.y, v));
ROUGHNESS = 1.0;
SPECULAR = 0.0;
NORMAL_MAP = texture(normals, UV).xyz;
}