docs/STYLE.md sets Tidewall's look: a drowned coast printed by hand. It has the palette, shape language, character proportions, shading, UI motifs, audio palette and a do-not-do list. - Palette (src/client/style/palette.gd) is the one table of client colours. Every colour that was scattered over the views now names its entry, with values unchanged. test_palette fails on a colour literal anywhere else in src/client or src/app, and on a palette colour the guide doesn't list. - Look sets up the sky, the salt-faded grading (saturation 0.86, contrast 1.05), the sun and the print pass, for the match view and the capture scenes. - folk_print.gdshader is one full-screen quad multiplied over the frame. It draws ink lines at depth jumps and creases (fading with distance, scaled with screen height), diagonal hatching cut into real shadow, and faint paper grain. Ground under the sea gets none. - make style-captures renders a hamlet and a dock with and without the pass. Closes #41 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
5.1 KiB
Plaintext
115 lines
5.1 KiB
Plaintext
// Tidewall's woodcut print pass (docs/STYLE.md, "Shading"). One full-screen quad, drawn
|
|
// last and multiplied over the frame, adds what a hand-cut print has and a render
|
|
// doesn't:
|
|
// - ink lines where depth jumps (silhouettes) or bends (creases), thick near the
|
|
// camera and fading with distance so far hills stay quiet;
|
|
// - diagonal hatching cut into shadow, its lines thickening as the shadow deepens;
|
|
// - a faint grain of unbleached paper.
|
|
// It only darkens (blend_mul), so lit colours stay the palette's own. Colour grading
|
|
// (salt-faded saturation, contrast) is done by the Environment in Look. Ground under
|
|
// the sea gets no ink or hatching, because the water is drawn over it. No textures:
|
|
// every pattern is generated here.
|
|
shader_type spatial;
|
|
render_mode unshaded, blend_mul, depth_test_disabled, depth_draw_never, cull_disabled, fog_disabled, shadows_disabled;
|
|
|
|
uniform sampler2D depth_texture : hint_depth_texture, filter_nearest;
|
|
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;
|
|
uniform vec3 ink_colour : source_color = vec3(0.16, 0.13, 0.11);
|
|
// 0 turns the pass off without removing it.
|
|
uniform float strength : hint_range(0.0, 1.0) = 1.0;
|
|
// Line weight, in pixels at 720 lines of screen; scales with the screen's height.
|
|
uniform float line_pixels = 1.0;
|
|
// Relative depth jump that counts as a silhouette, and depth bend that counts as a crease.
|
|
uniform float silhouette_threshold = 0.035;
|
|
uniform float crease_threshold = 0.010;
|
|
// Lines are full strength out to ink_near metres and fade to ink_far_strength by ink_far.
|
|
uniform float ink_near = 35.0;
|
|
uniform float ink_far = 260.0;
|
|
uniform float ink_far_strength = 0.2;
|
|
// Hatching: spacing in pixels at 720 lines, and the scene luminance (linear, before
|
|
// tone mapping) below which it begins: only real shadow, never lit ground.
|
|
uniform float hatch_spacing = 5.0;
|
|
uniform float hatch_start = 0.055;
|
|
uniform float hatch_depth = 0.28;
|
|
uniform float grain = 0.035;
|
|
// The sea's height: ground below it gets no ink.
|
|
uniform float sea_level = -1000.0;
|
|
uniform float camera_far = 2500.0;
|
|
|
|
float hash(vec2 p) {
|
|
p = fract(p * vec2(123.34, 456.21));
|
|
p += dot(p, p + 45.32);
|
|
return fract(p.x * p.y);
|
|
}
|
|
|
|
void vertex() {
|
|
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
|
|
}
|
|
|
|
vec3 view_position(vec2 uv, mat4 inv_projection) {
|
|
float depth = textureLod(depth_texture, uv, 0.0).r;
|
|
#if CURRENT_RENDERER == RENDERER_COMPATIBILITY
|
|
vec4 ndc = vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
|
#else
|
|
vec4 ndc = vec4(uv * 2.0 - 1.0, depth, 1.0);
|
|
#endif
|
|
vec4 view = inv_projection * ndc;
|
|
return view.xyz / view.w;
|
|
}
|
|
|
|
void fragment() {
|
|
vec2 uv = SCREEN_UV;
|
|
float scale = VIEWPORT_SIZE.y / 720.0;
|
|
vec2 step_uv = line_pixels * scale / VIEWPORT_SIZE;
|
|
|
|
vec3 centre = view_position(uv, INV_PROJECTION_MATRIX);
|
|
float d = -centre.z;
|
|
float d_l = -view_position(uv - vec2(step_uv.x, 0.0), INV_PROJECTION_MATRIX).z;
|
|
float d_r = -view_position(uv + vec2(step_uv.x, 0.0), INV_PROJECTION_MATRIX).z;
|
|
float d_u = -view_position(uv - vec2(0.0, step_uv.y), INV_PROJECTION_MATRIX).z;
|
|
float d_d = -view_position(uv + vec2(0.0, step_uv.y), INV_PROJECTION_MATRIX).z;
|
|
|
|
bool sky = d > camera_far * 0.9;
|
|
vec3 world = (INV_VIEW_MATRIX * vec4(centre, 1.0)).xyz;
|
|
bool under_sea = world.y < sea_level - 0.15;
|
|
|
|
// Silhouettes: the nearer side of a depth jump gets the line, so outlines hug objects.
|
|
float near_d = min(d, min(min(d_l, d_r), min(d_u, d_d)));
|
|
float jump = max(max(abs(d_l - d), abs(d_r - d)), max(abs(d_u - d), abs(d_d - d))) / max(near_d, 0.001);
|
|
float silhouette = smoothstep(silhouette_threshold, silhouette_threshold * 2.0, jump);
|
|
// Creases: depth bending (second difference) on one surface.
|
|
float bend = (abs(d_l + d_r - 2.0 * d) + abs(d_u + d_d - 2.0 * d)) / max(d, 0.001);
|
|
float crease = smoothstep(crease_threshold, crease_threshold * 2.5, bend) * 0.7;
|
|
float distance_fade = mix(1.0, ink_far_strength, smoothstep(ink_near, ink_far, near_d));
|
|
float ink = max(silhouette, crease) * distance_fade;
|
|
if (sky && near_d > camera_far * 0.9) {
|
|
ink = 0.0;
|
|
}
|
|
// Samples past the screen's edge clamp to it and read as a depth jump: no frame.
|
|
vec2 pixel = FRAGCOORD.xy;
|
|
if (pixel.x < 2.0 * scale || pixel.y < 2.0 * scale || pixel.x > VIEWPORT_SIZE.x - 2.0 * scale || pixel.y > VIEWPORT_SIZE.y - 2.0 * scale) {
|
|
ink = 0.0;
|
|
}
|
|
|
|
// Hatching in shadow: diagonal lines in screen space whose width grows with darkness.
|
|
float hatch = 0.0;
|
|
if (!sky && !under_sea) {
|
|
vec3 scene = textureLod(screen_texture, uv, 0.0).rgb;
|
|
float luminance = dot(scene, vec3(0.2126, 0.7152, 0.0722));
|
|
float shade = smoothstep(hatch_start, hatch_start * 0.25, luminance);
|
|
float spacing = hatch_spacing * scale;
|
|
float stripe = fract((FRAGCOORD.x + FRAGCOORD.y) / spacing);
|
|
float width = shade * 0.55;
|
|
float aa = 1.2 / spacing;
|
|
hatch = shade > 0.0 ? (1.0 - smoothstep(width - aa, width + aa, abs(stripe - 0.5) * 2.0)) * hatch_depth * distance_fade : 0.0;
|
|
} else if (under_sea) {
|
|
ink = 0.0;
|
|
}
|
|
|
|
float paper = 1.0 - grain * hash(floor(FRAGCOORD.xy / max(scale, 1.0)));
|
|
vec3 multiplier = mix(vec3(1.0), ink_colour, clamp(ink, 0.0, 1.0));
|
|
multiplier *= 1.0 - hatch;
|
|
multiplier *= paper;
|
|
ALBEDO = mix(vec3(1.0), multiplier, strength);
|
|
}
|