Files
grass-cutters/Assets/Shaders/Ground.shader
Bonchellon 3ee5956694 Ending: the Director's call, flyovers into orbit, Earth turning green, credits
When the planet is mown the ending plays by itself: G.R.A.S.S.A. calls, the
camera skims the stubble into the base, circles it and rises without a cut
into orbit over the bald planet (title, the crew's results). Then a jump
across space to a scorched, dried-out Earth: a rocket from Herbaria-7 passes
the lens and lands in Africa, and the green spreads from there over the whole
globe (seed pods, a glowing front, clouds and blue air coming back). The
credits roll over the green Earth (PlayWay credited as publisher), then THE
END and a card to keep mowing, leave a review or go to the menu. Space, Enter
or Esc skips to the green Earth and the card.

- EndingCinematic, EndingEarth (globe, air shell, rocket, seeds), SpaceSky
  (split out of the intro), EarthGlobe/EarthAir shaders and Earth maps in
  Resources/Ending
- the far meadow shows as stubble once the planet is mown
- "all of it" mown now means no sector with grass left (MowMap.Left); mown
  area summed in double
- the crew's total pay and play time are counted and saved for the results
- the "ending" cheat; -ending previews it in a test world; the -ending bot
  shoots every stage
- loc for the new lines in all 11 languages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 01:52:24 +03:00

143 lines
6.5 KiB
GLSL

// Soil of Herbaria-7, wrapped around the whole ball (Ground.cs). It reads as dense meadow from far away, steep hillsides
// turn to rock, and thin gold lines mark the borders of the sectors. What was cut is drawn over it (GrassFur.shader).
Shader "GrassCutter/Ground"
{
Properties
{
_Meadow ("Meadow floor", Color) = (0.12, 0.27, 0.07, 1)
_MeadowFar ("Meadow far", Color) = (0.3, 0.52, 0.16, 1)
_Rock ("Rock", Color) = (0.5, 0.46, 0.4, 1)
_Border ("Sector border", Color) = (0.95, 0.72, 0.25, 1)
}
SubShader
{
Tags { "RenderType" = "Opaque" "Queue" = "Geometry" "RenderPipeline" = "UniversalPipeline" }
Cull Off
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Planet.hlsl"
// the mesh is unit directions around the camera; the soil lifts them into place
float3 GroundDir(float3 positionOS) { return normalize(mul((float3x3)UNITY_MATRIX_M, positionOS)); }
ENDHLSL
Pass
{
Name "GroundForward"
Tags { "LightMode" = "UniversalForward" }
HLSLPROGRAM
#pragma target 4.5
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fog
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _Meadow, _MeadowFar, _Rock, _Border;
CBUFFER_END
float _GcSkyOn, _GcTime;
// 1 once the whole planet is mown (EndingCinematic): the far meadow is stubble and soil, as the cut sectors are drawn
float _GcBald;
float4 _GcCam;
float4x4 _GcSkyRot;
float4 _GcIcoN[20], _GcIcoR0[20], _GcIcoR1[20], _GcIcoR2[20];
struct Attributes { float3 positionOS : POSITION; };
struct Varyings { float4 positionCS : SV_POSITION; float3 positionWS : TEXCOORD0; float3 normalWS : TEXCOORD1; float3 dir : TEXCOORD2; float fog : TEXCOORD3; };
Varyings vert(Attributes v)
{
Varyings o;
float3 d = GroundDir(v.positionOS);
float3 t1, t2;
GcTangents(d, t1, t2);
float h = GcHeight(d);
const float e = 6.0;
float slope1 = GcHeight(normalize(d + t1 * e / _GcPlanet.w)) - h;
float slope2 = GcHeight(normalize(d + t2 * e / _GcPlanet.w)) - h;
o.dir = d;
o.normalWS = normalize(d - (t1 * slope1 + t2 * slope2) / e);
o.positionWS = _GcPlanet.xyz + d * (_GcPlanet.w + h);
o.positionCS = TransformWorldToHClip(o.positionWS);
o.fog = ComputeFogFactor(o.positionCS.z);
return o;
}
// metres to the nearest sector border (the same lattice as HexGrid.cs)
float HexEdge(float3 d)
{
int f = 0;
float best = -2;
for (int k = 0; k < 20; k++)
{
float dt = dot(_GcIcoN[k].xyz, d);
if (dt > best) { best = dt; f = k; }
}
float3 w = float3(dot(_GcIcoR0[f].xyz, d), dot(_GcIcoR1[f].xyz, d), dot(_GcIcoR2[f].xyz, d));
w *= 128.0 / (w.x + w.y + w.z);
float3 r = round(w), e = abs(r - w);
if (e.x > e.y && e.x > e.z) r.x = 128 - r.y - r.z;
else if (e.y > e.z) r.y = 128 - r.x - r.z;
else r.z = 128 - r.x - r.y;
float3 o = w - r;
return (1 - max(abs(o.x - o.y), max(abs(o.y - o.z), abs(o.z - o.x)))) * 13.0;
}
half4 frag(Varyings i) : SV_Target
{
float3 p = i.positionWS;
float n1 = SAMPLE_TEXTURE3D(_GcNoise3, sampler_GcNoise3, p * 0.25 / 64.0).r;
float n2 = SAMPLE_TEXTURE3D(_GcNoise3, sampler_GcNoise3, p * 1.3 / 64.0).g;
float n3 = SAMPLE_TEXTURE3D(_GcNoise3, sampler_GcNoise3, p * 6.0 / 64.0).b;
// meadow floor: dark and dense near (the blades stand on it), lighter canopy colour far away
float dist = length(p - _GcCam.xyz);
float3 col = lerp(_Meadow.rgb, _MeadowFar.rgb, smoothstep(40, 150, dist)) * lerp(0.8, 1.15, n1) * lerp(0.9, 1.08, n3);
float3 stubble = lerp(float3(0.46, 0.37, 0.12), float3(0.34, 0.25, 0.1), smoothstep(0.35, 0.65, n1) * 0.7) * lerp(0.86, 1.1, n3);
col = lerp(col, stubble, _GcBald);
// steep hillsides are rock
float3 nrm = normalize(i.normalWS);
float3 up = normalize(i.dir);
col = lerp(col, _Rock.rgb * lerp(0.8, 1.1, n2), smoothstep(0.86, 0.72, dot(nrm, up)));
// sector borders: a thin line that fades away instead of breaking up once it is under a pixel wide
float edge = HexEdge(up);
float pixel = max(fwidth(edge), 1e-3);
float line_ = (1 - smoothstep(0.1, 0.1 + pixel, edge)) * saturate(0.16 / pixel);
col = lerp(col, _Border.rgb, line_ * (1 - smoothstep(120, 320, dist)));
Light main = GetMainLight(TransformWorldToShadowCoord(p));
float ndl = saturate(dot(nrm, main.direction));
float3 ambient = SampleSH(_GcSkyOn > 0.5 ? mul((float3x3)_GcSkyRot, nrm) : nrm);
float3 lit = col * (main.color * ndl * lerp(0.3, 1, main.shadowAttenuation) * GcCloudSun(p, _GcTime) + ambient + GcLamp(p));
lit *= GcContact(p);
lit = MixFog(lit, i.fog);
return half4(lit, 1);
}
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags { "LightMode" = "DepthOnly" }
ZWrite On
ColorMask R
HLSLPROGRAM
#pragma target 4.5
#pragma vertex vert
#pragma fragment frag
struct A { float3 positionOS : POSITION; };
float4 vert(A v) : SV_POSITION { return TransformWorldToHClip(GcSoil(GroundDir(v.positionOS))); }
half frag() : SV_Target { return 0; }
ENDHLSL
}
}
}