carry: the runtime and render3d work Maroon Lake builds against
Input.text, App.monitor_count / window_to_monitor / window_fixed, gl_sleep_us, and the grass and collide changes, uncommitted on main and depended on by the game; carried here so the language work starts from what the game actually uses. main's working tree is untouched.
This commit is contained in:
parent
86492064aa
commit
e6f565a6c4
17 changed files with 622 additions and 34 deletions
|
|
@ -8,7 +8,7 @@
|
|||
// count is skipped.
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
const int BLADES = 16; // blades an invocation may emit
|
||||
const int ROWS = 4; // grass_blade_mesh(4): two vertices a row, three quads
|
||||
const int ROWS = 5; // grass_blade_mesh(5): two vertices a row, four quads
|
||||
layout(triangles, max_vertices = 128, max_primitives = 96) out;
|
||||
|
||||
uniform mat4 u_view;
|
||||
|
|
@ -129,11 +129,13 @@ void main() {
|
|||
if (tilt) n = normalize(n * ck + cross(k, n) * sk + k * dot(k, n) * (1.0 - ck));
|
||||
n = normalize(mix(n, gn, smoothstep(2.0, 12.0, dist)));
|
||||
float hull = (dist > 2.0 || far || (u_dbg & 2) != 0) ? -1.0 : 1.0;
|
||||
// the blade: grass_blade_mesh(4)'s vertices, placed as grass.vert places them
|
||||
// the blade: grass_blade_mesh(5)'s vertices, placed as grass.vert places them
|
||||
for (int r = 0; r < ROWS; r++) {
|
||||
float t = float(r) / float(ROWS - 1);
|
||||
float taper = max(1.0 - t * t * sqrt(t), 0.12);
|
||||
float bend = t * t * 0.28;
|
||||
// A COPY of grass_blade_mesh's profile in grass.ludic - narrow at the sheath,
|
||||
// widest a fifth of the way up, a fine point, and arched. Change both together.
|
||||
float taper = max((0.50 + 0.33 * min(t / 0.22, 1.0)) * (1.0 - t * t * t), 0.05);
|
||||
float bend = t * t * 0.52;
|
||||
for (int sd = 0; sd < 2; sd++) {
|
||||
vec3 a_pos = vec3((float(sd) - 0.5) * taper, t, bend);
|
||||
vec2 a_uv = vec2(float(sd), t);
|
||||
|
|
|
|||
|
|
@ -100,8 +100,16 @@ void main() {
|
|||
// of the count shrinks to nothing so a blade never pops.
|
||||
float spacing = u_s0 * (1.0 + dist / u_d0);
|
||||
float count = CELL * CELL / (spacing * spacing) * (1.0 - smoothstep(u_radius * 0.7, u_radius, dist));
|
||||
if (fj >= count) { cull(); return; }
|
||||
float life = 1.0 - smoothstep(0.8, 1.0, fj / max(count, 1.0));
|
||||
// WHICH blades thin out has to be random, not the last indices. `fj >= count` keeps
|
||||
// blades 0..N-1, and as N falls by one with distance, the SAME index dies in every
|
||||
// cell at the same radius - one blade in a fixed place per cell, over a whole ring.
|
||||
// Seen from above that is a set of arcs centred on the camera, and at eye level it is
|
||||
// the banding that reads as a ploughed field. Giving each blade its own fixed number
|
||||
// and comparing that against the density makes the thinning scatter instead.
|
||||
float keep = count / float(max(per_cell, 1));
|
||||
float r = bladeHash(ci, j, 5);
|
||||
if (r > keep) { cull(); return; }
|
||||
float life = 1.0 - smoothstep(keep * 0.75, keep, r);
|
||||
// the ground under it
|
||||
vec2 huv = (xz - u_ts_origin) / (2.0 * u_ts_half) + 0.5;
|
||||
if (huv.x < 0.0 || huv.x > 1.0 || huv.y < 0.0 || huv.y > 1.0) { cull(); return; }
|
||||
|
|
@ -136,7 +144,11 @@ void main() {
|
|||
if ((u_dbg & 1) != 0) h += 0.3;
|
||||
// the blade: sized so that coverage stays level as the spacing grows
|
||||
float seed = hv.x * 0.7 + hv.y * 0.3;
|
||||
float ang = hv.y * 6.2831853;
|
||||
// A BLADE'S YAW MUST NOT BE ITS POSITION. This was `hv.y * 2pi`, and hv.y is the same
|
||||
// number that places the blade along the cell's z - so every blade at the same depth
|
||||
// in a cell faced the same way, in rows, sixteen metres wide. That is the single thing
|
||||
// that made the meadow look ploughed. Its own hash costs nothing.
|
||||
float ang = bladeHash(ci, j, 6) * 6.2831853;
|
||||
float s = sin(ang), c_ = cos(ang);
|
||||
float grow = spacing / u_s0; // 1 at the camera, growing with distance
|
||||
// Height is biased SHORT rather than spread evenly. A meadow is not one length of grass: it
|
||||
|
|
@ -146,7 +158,12 @@ void main() {
|
|||
// that had been cut, which is the one thing an alpine meadow is not.
|
||||
float hh = h3 * h3;
|
||||
float tall = mix(0.09, 0.60, hh) * mix(0.8, 1.2, hash1(cid * 0.1)) * (1.0 + 0.35 * smoothstep(1.0, 12.0, grow)) * life;
|
||||
float bw = 0.028 * mix(1.0, 0.45 * grow, smoothstep(1.0, 4.0, grow));
|
||||
// 2.8 cm was FIVE TIMES a blade of meadow grass, which is 3-6 mm. At 2 m from the
|
||||
// camera that is a broad dark scimitar lying along the ground rather than a blade
|
||||
// standing in a sward, and no amount of profile or colour work fixes a blade that is
|
||||
// the wrong size. Measured, not guessed: it is the one number behind every "too wide
|
||||
// and too flat" note in this stage.
|
||||
float bw = 0.010 * mix(1.0, 0.45 * grow, smoothstep(1.0, 4.0, grow));
|
||||
if (far) { bw = max(bw, spacing * 0.35); tall = min(tall, spacing * 0.3); }
|
||||
vec3 p = vec3(a_pos.x * bw, a_pos.y * tall, a_pos.z * tall * (0.6 + 0.8 * h4));
|
||||
vec3 n = vec3(0.0, 0.3, 1.0);
|
||||
|
|
|
|||
|
|
@ -45,16 +45,27 @@ void main() {
|
|||
vec3 toCam = normalize(u_cam_pos - v_wpos); toCam.y = 0.0; toCam = normalize(toCam);
|
||||
vec3 right = vec3(-toCam.z, 0.0, toCam.x);
|
||||
vec3 hull = normalize(right * q.x * 0.8 + vec3(0.0, 1.0, 0.0) * (q.y * 0.6 + 0.35) + toCam * 0.7);
|
||||
n = normalize(mix(hull, n, mix(0.65, 0.35, far)));
|
||||
// Keep the BAKED normal. This was mix(0.65, 0.35, far), so past a few hundred metres
|
||||
// only a third of the foliage's own normal survived and two thirds was a smooth
|
||||
// rounded shell - which shades evenly and turns a canopy into a flat coloured blob.
|
||||
// Impostors draw nearly all the forest a player ever sees (turn them off and the
|
||||
// valley is bare), so that shell was most of the tree line.
|
||||
n = normalize(mix(hull, n, mix(0.88, 0.70, far)));
|
||||
float dist = length(v_wpos - u_cam_pos);
|
||||
float viewDepth = -(u_view * vec4(v_wpos, 1.0)).z;
|
||||
vec3 alb = a.rgb * u_tint * (0.85 + 0.3 * fract(v_seed * 7.13)) * regionTint(v_wpos, 0.4);
|
||||
// a distant stand reads as a dark mass, not as bright separate sprites
|
||||
alb = mix(alb, alb * vec3(0.72, 0.78, 0.72), far);
|
||||
// A distant stand reads as a dark mass, not as bright separate sprites - but this was
|
||||
// also pulling the colour out of it. Darken without desaturating: the same factor on
|
||||
// all three channels, and a touch of saturation put back, because the thing that makes
|
||||
// a far tree line read as forest rather than as a wash is that it is still GREEN.
|
||||
alb = mix(alb, alb * 0.72, far);
|
||||
float lum = dot(alb, vec3(0.2126, 0.7152, 0.0722));
|
||||
alb = mix(vec3(lum), alb, 1.45); // conifer foliage is SATURATED, not grey-green
|
||||
alb *= 0.78; // and it is dark: a spruce canopy is not a lawn
|
||||
// the card itself is the caster: look up the shadow a little toward the sun so it does not self-shadow
|
||||
float shadow = sunShadow(v_wpos + u_sun_dir * u_radius * 0.7, vec3(0, 1, 0), viewDepth);
|
||||
// crowns are dense: darken toward the centre of the card as a cheap interior occlusion
|
||||
float interior = 1.0 - 0.45 * smoothstep(0.9, 0.3, abs(q.x)) * smoothstep(1.0, 0.2, v_uv.y);
|
||||
float interior = 1.0 - 0.22 * smoothstep(0.9, 0.3, abs(q.x)) * smoothstep(1.0, 0.2, v_uv.y);
|
||||
// ground contact: the lowest part of anything sitting on the ground is occluded by it
|
||||
// (a boulder's underside, a trunk's base); without it a far boulder is a sticker on the grass
|
||||
interior *= mix(0.55, 1.0, smoothstep(0.0, 0.3, v_uv.y));
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ uniform float u_emissive; // self-lit (a flame): albedo added back after sha
|
|||
#ifdef BLADE
|
||||
uniform vec3 u_blade_base;
|
||||
uniform vec3 u_blade_tip;
|
||||
uniform sampler2D u_blade_tex; // straightened photographic blades, side by side
|
||||
uniform float u_blade_cols; // how many are in it
|
||||
uniform float u_blade_tex_on;
|
||||
#endif
|
||||
#ifdef CARD
|
||||
uniform float u_cull; // the layer's cull distance (m); 0 = none
|
||||
|
|
@ -80,6 +83,33 @@ void main() {
|
|||
alb = mix(u_blade_base, u_blade_tip, t * t) * regionTint(v_wpos, 0.35);
|
||||
float dry = smoothstep(0.7, 0.8, fract(v_seed * 3.17));
|
||||
alb = mix(alb, vec3(0.40, 0.36, 0.13) * (0.45 + 0.55 * t), dry * 0.75);
|
||||
// A REAL BLADE, if the game gave us one. Each blade picks a column of the atlas from
|
||||
// its own seed and runs v from sheath to tip, so a meadow is eight different plants
|
||||
// rather than one plant ten thousand times. The photograph carries the midrib, the
|
||||
// olive-to-straw run and the dry browning; the gradient above stays as the tint that
|
||||
// the season and the lushness drive, so nothing that used to control the colour stops
|
||||
// working - the picture multiplies it rather than replacing it.
|
||||
if (u_blade_tex_on > 0.5) {
|
||||
float col = floor(fract(v_seed * 7.31) * u_blade_cols);
|
||||
vec2 buv = vec2((col + clamp(v_uv.x, 0.0, 1.0)) / u_blade_cols, 1.0 - t);
|
||||
vec3 photo = texture(u_blade_tex, buv).rgb;
|
||||
// Normalised by the atlas's OWN MEAN LUMINANCE - a measured constant, 0.3736 over the
|
||||
// opaque pixels - and not by each pixel's mean. Dividing by the per-pixel mean was the
|
||||
// bug: it cancels exactly the thing the photograph was fetched for. What survives is
|
||||
// the hue ratio, so every blade comes back out at the same brightness and the midrib,
|
||||
// the dry browning and the sheath-to-tip run all vanish. It looked like a faint tint
|
||||
// over the old procedural blade, which is precisely what it was.
|
||||
// Blended, not applied whole. At full strength a photo pixel brighter than the
|
||||
// atlas's mean is multiplied by up to 1.9, and the bright blades came out white -
|
||||
// straws in a green sward. Three quarters of the photograph keeps the midrib, the
|
||||
// browning and the sheath-to-tip run and leaves the extremes alone.
|
||||
// CLAMPED. The atlas's mean luminance is 0.3736, so a blade pixel brighter than the
|
||||
// mean is multiplied by up to 2.7 and comes out white - and a white blade is the one
|
||||
// thing grass never is. Holding the factor to 1.15 keeps the midrib and the browning,
|
||||
// which are the parts of the photograph worth having, and refuses the bleach.
|
||||
vec3 g = photo * (1.0 / 0.3736);
|
||||
alb *= mix(vec3(1.0), min(g, vec3(1.15)), 0.85);
|
||||
}
|
||||
float patchy = fbm(v_wpos.xz * 0.045, 3) * 0.5 + 0.5;
|
||||
alb *= mix(vec3(0.7, 0.8, 0.55), vec3(1.1, 1.05, 0.85), patchy);
|
||||
// a far tuft is a patch of the meadow, darker than a lit blade tip and never straw
|
||||
|
|
@ -87,7 +117,15 @@ void main() {
|
|||
// a rounded cross-section reads softer than a flat card
|
||||
vec3 side = normalize(cross(N, vec3(0.0, 1.0, 0.0)) + vec3(1e-4));
|
||||
n = (v_hull < 0.0) ? N : normalize(N + side * (v_uv.x * 2.0 - 1.0) * 0.6);
|
||||
arm = vec3(mix(0.2, 1.0, t * t), 0.85, 0.0);
|
||||
// A blade's own ambient occlusion. This was mix(0.2, 1.0, t*t): 80% occluded at the
|
||||
// sheath and still 60% at half height, because t*t holds the curve down. Measured in a
|
||||
// walking-distance shot the blades came out at 24-31 of 255 against a ground of 143 -
|
||||
// near-black on light earth - and at that contrast the eye reads every blade as a hard
|
||||
// EDGE rather than as a mass of vegetation, whatever shape it is. No albedo can answer
|
||||
// an occlusion term; grass albedo is capped near 0.5 and this was dividing it by five.
|
||||
// A blade is a thin thing standing in open air: shaded at the root by its neighbours,
|
||||
// not buried.
|
||||
arm = vec3(mix(0.55, 1.0, t), 0.85, 0.0);
|
||||
#elif defined(CARD)
|
||||
// thin grass is lit from either side: face the card toward the sun before shading
|
||||
if (dot(N, u_sun_dir) < 0.0) N = -N;
|
||||
|
|
@ -156,8 +194,20 @@ void main() {
|
|||
// The quake made visible. A turning aspen leaf shows its pale, almost white underside, so
|
||||
// the crown does not merely move - it GLITTERS, leaf by leaf, and that is what reads at a
|
||||
// distance and in a still frame. Toward the viewer is the pale side; away is the face.
|
||||
if (v_quake > 0.0) alb = mix(alb, alb * 0.55 + vec3(0.42, 0.45, 0.33), min(v_quake * 2.6, 0.75));
|
||||
else if (v_quake < 0.0) alb *= 1.0 + v_quake * 0.28; // the dark half stays gentle: a crown should shimmer, not flicker
|
||||
// The quake, as a LIGHTENING rather than a repaint. This used to mix up to 75% toward
|
||||
// a fixed near-white (0.42,0.45,0.33), which was written for a hand-painted leaf atlas
|
||||
// that had no pale underside of its own. On a photographed leaf it does not read as a
|
||||
// turning leaf at all - it reads as parts of the tree going WHITE, because that is
|
||||
// exactly what it does: it replaces three quarters of the leaf's colour with a constant.
|
||||
// Nothing in a wood turns white in the sun. A real turning leaf shows a paler, greyer
|
||||
// version of ITSELF, so lift and desaturate the leaf's own colour instead.
|
||||
if (v_quake > 0.0) {
|
||||
float q = min(v_quake * 2.6, 0.75);
|
||||
float l = dot(alb, vec3(0.2126, 0.7152, 0.0722));
|
||||
alb = mix(alb, mix(alb, vec3(l), 0.45) * 1.30, q);
|
||||
} else if (v_quake < 0.0) {
|
||||
alb *= 1.0 + v_quake * 0.28; // the dark half stays gentle: a crown should shimmer, not flicker
|
||||
}
|
||||
#if defined(FOLIAGE) && !defined(BLADE)
|
||||
// Per-plant HUE, not only per-plant brightness. The line above varies value by +-15% and
|
||||
// nothing else, so a stand of one species was one colour at fifteen different exposures -
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue