Files
Emberwild/shaders/rock.gdshader
Paul Bailey 12f7fd677d M0.5: detailed scenery, mountain/sea-cliff boundary, Godot 4.7
Scenery (all procedural, seeded, no imported assets):
- Terrain shader: grass/dry grass/dirt/sand/rock strata/snow + detail normals
- 5 tree types, faceted mossy rocks, cliff outcrops, sea stacks, bushes,
  logs and stumps, batched as MultiMesh per 48 m cell
- Wind-animated grass and flowers streamed in tiles around the player
- Lake (depth-shaded water with shore foam), ocean to the horizon,
  cloud sky shader, volumetric fog, glow, softer shadows
- Swimming: float at the surface, swim-jump to climb out

World bounds:
- Steep mountain rim with an invisible wall partway up; one side opens to
  a sheer sea cliff with the wall 1 m inside the edge; whole chunk is an
  island so the mesh edge is never visible
- Respawn safety net if the player leaves the walkable area or the map
- Fix: the cliff edge now tracks the wall in the headlands (it used to
  drop away inside the wall, leaving a pit with lake water hanging over it)

Tests: tests/test_boundary.gd (24-direction escape attempt) and
tests/test_terrain_edges.gd (no ground below waterline near the wall).

Upgrades the project to Godot 4.7 (project.godot rewritten by the 4.7
importer, .uid files added) and documents it in the setup guide.
2026-11-03 23:49:39 +00:00

41 lines
1.3 KiB
Plaintext

shader_type spatial;
render_mode cull_back, diffuse_burley;
// Faceted low-poly rocks: triplanar grain, per-rock tint, moss on upward faces
// (on some rocks more than others), snow on top at altitude.
#include "res://shaders/common.gdshaderinc"
uniform vec3 moss_col : source_color = vec3(0.27, 0.38, 0.15);
uniform vec3 snow_col : source_color = vec3(0.93, 0.95, 0.98);
uniform float snow_height = 40.0;
varying vec3 w_pos;
varying vec3 w_nrm;
varying vec3 inst_pos;
void vertex() {
w_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
w_nrm = normalize((MODEL_MATRIX * vec4(NORMAL, 0.0)).xyz);
inst_pos = MODEL_MATRIX[3].xyz;
}
void fragment() {
float a = tri_nz(w_pos, w_nrm, 0.3);
float b = tri_nz(w_pos, w_nrm, 1.4);
vec3 base = to_linear(COLOR.rgb) * (0.7 + 0.6 * a) * (0.88 + 0.24 * b);
base *= mix(vec3(1.04, 1.0, 0.94), vec3(0.94, 0.97, 1.03), nz(inst_pos.xz * 0.07));
float mossy = smoothstep(0.3, 0.7, nz(inst_pos.xz * 0.021 + 0.5));
float moss = smoothstep(0.45, 0.8, w_nrm.y + (a - 0.5) * 0.7) * mossy;
vec3 col = mix(base, moss_col * (0.75 + 0.5 * b), moss);
float snow = smoothstep(snow_height - 3.0, snow_height + 3.0, w_pos.y + (a - 0.5) * 10.0);
snow *= smoothstep(0.35, 0.7, w_nrm.y);
col = mix(col, snow_col, snow);
ALBEDO = col;
ROUGHNESS = mix(mix(0.8, 0.95, moss), 0.6, snow);
SPECULAR = 0.35;
}