Flights run on rails at even speed along the spline with eased ends and smooth zoom pushes, no hand-held shake. Grass fur, sector lines and shadows fade out as the camera climbs, and above 250 m the ground swaps to an even cube-sphere skin so the relief no longer pops while orbiting. Per-shot FOV, motion blur, slamming titles and a warp to Earth; the rocket now lands in Kansas and the green bursts straight out of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
146 lines
6.7 KiB
GLSL
146 lines
6.7 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;
|
|
// a film's lens leaving the ground (0 .. 1): the sector lines go and the cloud shade softens
|
|
float _GcFarOnly;
|
|
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)) * (1 - _GcFarOnly));
|
|
|
|
Light main = GetMainLight(TransformWorldToShadowCoord(p));
|
|
float ndl = saturate(dot(nrm, main.direction));
|
|
float3 ambient = SampleSH(_GcSkyOn > 0.5 ? mul((float3x3)_GcSkyRot, nrm) : nrm);
|
|
float clouds = lerp(GcCloudSun(p, _GcTime), 1, _GcFarOnly * 0.6);
|
|
float3 lit = col * (main.color * ndl * lerp(0.3, 1, main.shadowAttenuation) * clouds + 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
|
|
}
|
|
}
|
|
}
|