66 lines
2.4 KiB
Plaintext
66 lines
2.4 KiB
Plaintext
shader_type spatial;
|
|
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx;
|
|
|
|
// Configuration
|
|
uniform vec4 margin_color : source_color = vec4(0.6, 0.6, 0.6, 1.0);
|
|
uniform vec4 inside_color : source_color = vec4(0.7, 0.2, 0.2, 1.0); // Light Red
|
|
uniform vec4 outside_color : source_color = vec4(0.3, 0.3, 0.35, 1.0); // Grey-ish
|
|
|
|
uniform float margin_width : hint_range(0.0, 0.5) = 0.05;
|
|
uniform float ridge_frequency = 10.0;
|
|
|
|
void fragment() {
|
|
// COLOR passed from mesh generation:
|
|
// R=1 (Inside), B=1 (Outside), Black (Sides)
|
|
float is_inside = COLOR.r;
|
|
float is_outside = COLOR.b;
|
|
float is_side = 1.0 - is_inside - is_outside;
|
|
|
|
// --- MARGIN CALCULATION ---
|
|
// UVs are assumed to be centered at 0.5, 0.5.
|
|
// Distance from center > (0.5 - margin) means we are at the edge.
|
|
vec2 centered_uv = abs(UV - 0.5);
|
|
float dist_from_center = max(centered_uv.x, centered_uv.y);
|
|
float in_margin = step(0.5 - margin_width, dist_from_center);
|
|
|
|
// --- TEXTURES ---
|
|
|
|
// 1. Inside (Friction Mat)
|
|
vec3 inside_albedo = inside_color.rgb;
|
|
float inside_roughness = 0.8;
|
|
float inside_metallic = 0.1;
|
|
|
|
// 2. Outside (Reinforced Hull)
|
|
// Simple procedural grid ridges
|
|
float ridges_x = step(0.9, fract(UV.x * ridge_frequency));
|
|
float ridges_y = step(0.9, fract(UV.y * ridge_frequency));
|
|
float ridges = max(ridges_x, ridges_y);
|
|
|
|
vec3 outside_albedo = mix(outside_color.rgb, outside_color.rgb * 0.8, ridges);
|
|
float outside_roughness = 0.6;
|
|
float outside_metallic = 0.5;
|
|
|
|
// 3. Margin / Sides (Exposed Metal)
|
|
vec3 metal_albedo = margin_color.rgb;
|
|
float metal_roughness = 0.3;
|
|
float metal_metallic = 1.0;
|
|
|
|
// --- MIXING ---
|
|
// If we are on a Side OR in the Margin of a face, use Metal.
|
|
float show_metal = max(is_side, in_margin);
|
|
|
|
vec3 face_albedo = mix(outside_albedo, inside_albedo, is_inside);
|
|
float face_roughness = mix(outside_roughness, inside_roughness, is_inside);
|
|
float face_metallic = mix(outside_metallic, inside_metallic, is_inside);
|
|
|
|
ALBEDO = mix(face_albedo, metal_albedo, show_metal);
|
|
METALLIC = mix(face_metallic, metal_metallic, show_metal);
|
|
ROUGHNESS = mix(face_roughness, metal_roughness, show_metal);
|
|
|
|
// Normal Map for Ridges (Optional fake bump)
|
|
if (is_outside > 0.5 && show_metal < 0.5) {
|
|
NORMAL_MAP_DEPTH = 1.0;
|
|
// Simple normal perturbation based on ridges
|
|
// ( omitted for brevity, flat normal usually fine for low poly style )
|
|
}
|
|
} |