Grass Cutters Together: the project as of moon-sweepers f3666f0

A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiemandKG
2026-11-06 18:44:40 +06:00
parent 0f0467cd0c
commit d1c3761e58
4190 changed files with 270757 additions and 1 deletions

View File

@ -0,0 +1,64 @@
// The saucer's tractor beam: a see-through cone, bright at its edges, with rings of light climbing it toward the ship.
// Additive, no depth: what's being lifted shows inside it.
Shader "GrassCutter/Beam"
{
Properties
{
_BaseColor ("Colour", Color) = (0.45, 1, 0.8, 0.3)
_Power ("Power", Float) = 1
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent+10" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }
Pass
{
Name "Beam"
Tags { "LightMode" = "UniversalForward" }
Blend SrcAlpha One
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _BaseColor;
float _Power;
CBUFFER_END
struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; float2 uv : TEXCOORD0; };
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 normalWS : TEXCOORD0;
float3 positionWS : TEXCOORD1;
float2 uv : TEXCOORD2;
};
Varyings vert(Attributes v)
{
Varyings o;
o.positionWS = TransformObjectToWorld(v.positionOS.xyz);
o.positionCS = TransformWorldToHClip(o.positionWS);
o.normalWS = TransformObjectToWorldNormal(v.normalOS);
o.uv = v.uv;
return o;
}
float4 frag(Varyings i) : SV_Target
{
float3 view = normalize(GetCameraPositionWS() - i.positionWS);
float facing = abs(dot(normalize(i.normalWS), view));
float rim = pow(1 - facing, 1.6);
// v runs 0 at the ground to 1 at the ship
float v = i.uv.y;
float climb = smoothstep(0.75, 1, frac(v * 7 - _Time.y * 1.1));
float streak = 0.5 + 0.5 * sin(i.uv.x * 6.2831 * 9 + _Time.y * 2.0);
float fadeEnds = smoothstep(0, 0.12, v) * smoothstep(1, 0.85, v);
float a = (_BaseColor.a * (0.35 + rim * 0.9) + climb * 0.35 + streak * 0.06) * fadeEnds * _Power;
return float4(_BaseColor.rgb * (1 + climb), saturate(a));
}
ENDHLSL
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b52cacb17b9e8604699be6c6e13c0a14
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,84 @@
// What a piece will look like before it's built: one see-through shell with a lit rim and a line of light climbing it.
// _Flat is for lines on the ground, which have no normals to make a rim from.
Shader "GrassCutter/Ghost"
{
Properties
{
_BaseColor ("Colour", Color) = (0.3, 1, 0.55, 0.45)
_Flat ("Flat", Float) = 0
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }
// depth first: only the outer shell gets colour, not the tangle of parts inside it
Pass
{
Name "GhostDepth"
Tags { "LightMode" = "SRPDefaultUnlit" }
ZWrite On
ColorMask 0
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _BaseColor;
float _Flat;
CBUFFER_END
float4 vert(float4 positionOS : POSITION) : SV_POSITION
{
if (_Flat > 0.5) return float4(0, 0, -1, 1);
return TransformObjectToHClip(positionOS.xyz);
}
float4 frag() : SV_Target { return 0; }
ENDHLSL
}
Pass
{
Name "Ghost"
Tags { "LightMode" = "UniversalForward" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _BaseColor;
float _Flat;
CBUFFER_END
struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; };
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 normalWS : TEXCOORD0;
float3 positionWS : TEXCOORD1;
float height : TEXCOORD2;
};
Varyings vert(Attributes v)
{
Varyings o;
o.positionWS = TransformObjectToWorld(v.positionOS.xyz);
o.positionCS = TransformWorldToHClip(o.positionWS);
o.normalWS = TransformObjectToWorldNormal(v.normalOS);
o.height = v.positionOS.y;
return o;
}
float4 frag(Varyings i) : SV_Target
{
if (_Flat > 0.5) return float4(_BaseColor.rgb * 1.3, saturate(_BaseColor.a + 0.45));
float3 view = normalize(GetCameraPositionWS() - i.positionWS);
float rim = pow(1 - saturate(dot(normalize(i.normalWS), view)), 2.2);
float climb = smoothstep(0.86, 1, frac(i.height * 1.2 - _Time.y * 0.6));
float alpha = saturate(_BaseColor.a * 0.6 + rim * 0.65 + climb * 0.22);
return float4(_BaseColor.rgb * (1 + rim * 1.1 + climb * 0.5), alpha);
}
ENDHLSL
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 56ed8d2659860fc4eb1815ebd7263cc3
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

242
Assets/Shaders/Grass.shader Normal file
View File

@ -0,0 +1,242 @@
// GPU meadow for Herbaria-7. Drawn by GrassField.cs with RenderMeshPrimitives: every instance derives its world cell,
// jitter, size and colour from SV_InstanceID, so there is no per-instance buffer. _Plant = 1 draws hemp (alpha-cut leaf
// cards, albedo from the leaf texture) instead of blade tufts.
Shader "GrassCutter/Grass"
{
Properties
{
_RootColor ("Root", Color) = (0.07, 0.2, 0.05, 1)
_TipColor ("Tip", Color) = (0.45, 0.78, 0.2, 1)
_DryColor ("Dry tip", Color) = (0.86, 0.8, 0.36, 1)
_CutColor ("Fresh cut", Color) = (0.62, 0.74, 0.25, 1)
_MainTex ("Leaf (rgb albedo, a cutout)", 2D) = "white" {}
_Plant ("Plant mode", Float) = 0
_PlantScale ("Plant height vs grass", Float) = 1.15
_Metres ("Plant height in metres, 0 goes by the grass", Float) = 0
_Tint ("Plant tint", Color) = (1, 1, 1, 1)
_Patchy ("Grow in patches", Float) = 0
_Wind ("Wind", Float) = 1
_Translucency ("Translucency", Float) = 0.5
}
SubShader
{
Tags { "RenderType" = "Opaque" "Queue" = "AlphaTest" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }
Pass
{
Name "GrassForward"
Tags { "LightMode" = "UniversalForward" }
Cull Off
ZWrite On
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/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Planet.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _RootColor, _TipColor, _DryColor, _CutColor, _Tint;
float4 _MainTex_ST;
float _Plant, _PlantScale, _Metres, _Patchy, _Wind, _Translucency;
CBUFFER_END
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
// per draw (MaterialPropertyBlock)
float4 _GcGrid; // first cell x, first cell z, cell, cells per row
float4 _GcFade; // fade start, fade end, inner skip radius, density
// globals
float4 _GcCam;
float4 _GcVortex[12]; // where, strength
float _GcVortexReach[12];
float _GcVortexCount;
float _GcGust; // the weather's wind on top of the breeze: 0 calm
float4 _GcPushers[8]; // x, y, z, radius
float _GcPusherCount;
float _GcTime, _GcHeight;
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 color : COLOR;
float2 uv : TEXCOORD0;
uint iid : SV_InstanceID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 positionWS : TEXCOORD0;
float3 normalWS : TEXCOORD1;
float4 albedo : TEXCOORD2; // rgb, a = along-blade (for translucency)
float2 uv : TEXCOORD3;
float fog : TEXCOORD4;
float sun : TEXCOORD5; // through the clouds
};
float4 Hash4(float2 p)
{
float4 p4 = frac(float4(p.xyxy) * float4(0.1031, 0.1030, 0.0973, 0.1099));
p4 += dot(p4, p4.wzxy + 33.33);
return frac((p4.xxyz + p4.yzzw) * p4.zywx);
}
Varyings Collapse()
{
Varyings o = (Varyings)0;
o.positionCS = float4(0, 0, -2, 1); // behind the near plane: clipped
return o;
}
Varyings vert(Attributes v)
{
uint n = (uint)_GcGrid.w;
float cell = _GcGrid.z;
uint ix = v.iid % n, iz = v.iid / n;
float2 cid = _GcGrid.xy + float2(ix, iz);
float4 h = Hash4(cid + _GcSalt.xy + (_Plant > 0.5 ? 71.3 : 0));
if (h.w > _GcFade.w) return Collapse();
float2 plane = (cid + h.xy) * cell;
float3 up;
float edge;
if (!GcInSector(plane, up, edge)) return Collapse();
float3 root = GcSoil(up);
if (_Patchy > 0.5 && GcNoise(root * 0.035).b < 0.52) return Collapse();
float dist = length(root - _GcCam.xyz);
if (dist > _GcFade.y || dist < _GcFade.z - 6) return Collapse();
float fade = 1 - smoothstep(_GcFade.x, _GcFade.y, dist);
if (_GcFade.z > 0) fade *= smoothstep(_GcFade.z - 6, _GcFade.z + 5, dist);
float2 mask = GcMask(plane);
if (mask.g > 0.5) return Collapse();
float cut = saturate(mask.r);
// big soft patches of taller / shorter, greener / drier grass
float patch = GcNoise(root * 0.045).r;
float H = _GcHeight * lerp(0.72, 1.28, h.z) * lerp(0.8, 1.15, patch);
float stubble = lerp(1, 0.09, cut);
if (_Plant > 0.5)
{
H = _Metres > 0 ? _Metres * lerp(0.86, 1.14, h.z) : (_GcHeight * _PlantScale + 0.35) * lerp(0.8, 1.2, h.z);
stubble = lerp(1, 0.06, smoothstep(0.15, 0.6, cut));
}
H *= stubble * fade;
if (H < 0.02) return Collapse();
// rotate + place the clump
float3 t1, t2;
GcTangents(up, t1, t2);
float yaw = h.z * 6.2831853 + h.x * 3.0;
float s, c;
sincos(yaw, s, c);
float3 p = v.positionOS;
float widthMul = _Plant > 0.5 ? H : lerp(0.9, 1.4, h.y) * (1 + (1 - fade) * 1.5);
float2 local = float2(p.x * c - p.z * s, p.x * s + p.z * c) * widthMul;
float along = _Plant > 0.5 ? saturate(p.y) : v.color.r;
// wind: rolling gusts
float t = _GcTime;
float gust = GcNoise(root * 0.06 + float3(-0.8, 0.1, -0.45) * t * 0.9).g * 0.8 + 0.2;
float sway = sin(t * 2.3 + dot(root, float3(0.7, 0.3, 0.4)) + h.y * 6.0) * 0.35;
float bendK = along * along * H * _Wind * (1.0 + _GcGust) * (_Plant > 0.5 ? 0.12 : 0.34);
float2 off = float2(gust * 0.9 + sway * 0.4, sway * 0.3) * bendK;
// mowing spots: tips get pulled toward the cutter and up (sucked in)
float lift = 0;
for (int i = 0; i < (int)_GcVortexCount; i++)
{
float3 toV = root - _GcVortex[i].xyz;
float2 d = float2(dot(toV, t1), dot(toV, t2));
float reach = _GcVortexReach[i];
float r2 = dot(d, d) / max(0.2, reach * reach * 2.5);
float f = _GcVortex[i].w * exp(-r2);
float2 swirl = float2(-d.y, d.x);
off += (-normalize(d + 1e-4) * 0.8 + normalize(swirl + 1e-4) * 0.5) * f * along * H * 0.7;
lift += f * along * 0.25;
off += sin(t * 31.0 + h.x * 20.0) * f * 0.05 * along;
}
// people and vehicles push the grass aside
for (int j = 0; j < (int)_GcPusherCount; j++)
{
float4 ps = _GcPushers[j];
float r = ps.w;
if (r <= 0) continue;
float3 toP = root - ps.xyz;
float2 d = float2(dot(toP, t1), dot(toP, t2));
float f = saturate(1 - length(d) / r) * step(-dot(toP, up) - 0.6, H);
off += normalize(d + 1e-4) * f * along * H * 0.9;
lift -= f * along * 0.35;
}
float offLen = length(off);
float2 flat_ = local + off;
float3 wpos = root + t1 * flat_.x + t2 * flat_.y + up * (p.y * H + lift * H - offLen * offLen / max(0.3, H) * 0.35 * along);
Varyings o;
o.positionWS = wpos;
o.positionCS = TransformWorldToHClip(wpos);
float3 nrm = v.normalOS;
nrm = t1 * (nrm.x * c - nrm.z * s) + up * nrm.y + t2 * (nrm.x * s + nrm.z * c);
o.normalWS = normalize(lerp(nrm, up, 0.35));
float3 col;
if (_Plant > 0.5)
{
// hemp: leaf texture provides colour; a touch of per-plant hue
col = lerp(float3(1, 1, 1), float3(0.92, 1.05, 0.85), h.y) * lerp(0.85, 1.1, h.z) * _Tint.rgb;
// wildflowers: every patch has its own petals
if (_Patchy > 0.5 && v.uv.x > 0.5 && v.uv.y > 0.5)
{
float pick = frac(GcNoise(root * 0.018).g * 9.0);
col = pick < 0.34 ? float3(1, 1, 0.96) : pick < 0.6 ? float3(1, 0.82, 0.16) : pick < 0.82 ? float3(0.66, 0.46, 0.98) : float3(1, 0.46, 0.66);
}
}
else
{
float3 tip = lerp(_TipColor.rgb, _DryColor.rgb, saturate(patch * 0.55 + h.y * 0.25 - 0.15));
tip = lerp(tip, _CutColor.rgb, cut);
col = lerp(_RootColor.rgb, tip, pow(along, 0.8)) * lerp(0.82, 1.12, h.w);
col *= lerp(0.55, 1, saturate(along * 1.6)); // root occlusion
}
o.albedo = float4(col, along);
o.uv = v.uv;
o.fog = ComputeFogFactor(o.positionCS.z);
o.sun = GcCloudSun(root, t);
return o;
}
half4 frag(Varyings i, bool front : SV_IsFrontFace) : SV_Target
{
float3 albedo = i.albedo.rgb;
if (_Plant > 0.5)
{
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
clip(tex.a - 0.5);
albedo *= tex.rgb;
}
float3 n = normalize(i.normalWS) * (front ? 1 : -1);
Light main = GetMainLight(TransformWorldToShadowCoord(i.positionWS));
float3 v = normalize(GetCameraPositionWS() - i.positionWS);
float ndl = saturate(dot(n, main.direction) * 0.6 + 0.4);
float back = pow(saturate(dot(v, -main.direction)), 3) * _Translucency * i.albedo.a;
float shadow = lerp(0.35, 1, main.shadowAttenuation) * i.sun;
float3 col = albedo * (main.color * (ndl + back) * shadow + SampleSH(float3(0, 1, 0)) * 0.9 + GcLamp(i.positionWS));
// a soft sheen on the tips
col += main.color * pow(saturate(dot(n, normalize(main.direction + v))), 24) * 0.08 * i.albedo.a * shadow;
col *= GcContact(i.positionWS);
col = MixFog(col, i.fog);
return half4(col, 1);
}
ENDHLSL
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8745f4ec3a7754247abbbf867421a7f6
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,222 @@
// Herbaria-7's meadow toward the horizon, where single strands would be under a pixel (shell texturing), and the solid
// floor under the near strands (one shell). GrassField.cs lays a grid over the flat frame of each sector in view,
// once per shell with RenderMeshPrimitives (SV_InstanceID = shell, 0 = the top one so the upper layers hit the depth
// buffer first). Every shell is lifted to its share of the pile height and bent by wind, mowers and players in the vertex
// stage; the fragment stage cuts the strands out of a tiling strand texture (r = strand height, tapered to a point; g =
// per-strand tint) and the mow mask, so mown trails are crisp and cost nothing extra. No blades, no per-instance data.
Shader "GrassCutter/GrassFur"
{
Properties
{
_RootColor ("Root", Color) = (0.06, 0.17, 0.04, 1)
_TipColor ("Tip", Color) = (0.38, 0.68, 0.17, 1)
_DryColor ("Dry tip", Color) = (0.82, 0.78, 0.33, 1)
_HempColor ("Hemp streaks", Color) = (0.25, 0.55, 0.22, 1)
_CutColor ("Fresh stubble", Color) = (0.8, 0.74, 0.4, 1)
_SoilColor ("Soil under stubble", Color) = (0.52, 0.42, 0.25, 1)
_Dirt ("Dirt", Color) = (0.42, 0.33, 0.22, 1)
_Gravel ("Gravel", Color) = (0.58, 0.55, 0.5, 1)
_Wind ("Wind", Float) = 1
}
SubShader
{
Tags { "RenderType" = "Opaque" "Queue" = "AlphaTest" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }
Pass
{
Name "FurForward"
Tags { "LightMode" = "UniversalForward" }
Cull Off
ZWrite On
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/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Planet.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _RootColor, _TipColor, _DryColor, _HempColor, _CutColor, _SoilColor, _Dirt, _Gravel;
float _Wind;
CBUFFER_END
TEXTURE2D(_GcFurTex); SAMPLER(sampler_GcFurTex);
// per draw (MaterialPropertyBlock)
float4 _GcGrid; // half a side of the sector's square, cell
float4 _GcShells; // shell count, inner radius, outer radius (only this ring is drawn), dithered seam width
float4 _GcFade; // the pile sinks into the ground between these distances (the horizon); z = 1: only what was cut
// globals
float4 _GcCam, _GcCamUp;
float4 _GcFurN, _GcFurU, _GcFurV; // the cube face the strand texture lies on
float4 _GcVortex[12]; // where, strength
float _GcVortexReach[12];
float _GcVortexCount;
float _GcGust; // the weather's wind on top of the breeze: 0 calm
float4 _GcPushers[8]; // x, y, z, radius
float _GcPusherCount;
float _GcTime, _GcHeight, _GcFurScale, _GcFurMax;
struct Attributes
{
float3 positionOS : POSITION;
uint iid : SV_InstanceID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 positionWS : TEXCOORD0;
float4 data : TEXCOORD1; // x = shell 0..1, y = pile height here, z = big patch noise, w = edge fade
float3 root : TEXCOORD2; // undisplaced world position (strand lookup)
float fog : TEXCOORD3;
float2 plane : TEXCOORD4; // the sector's flat frame (mow map)
float2 air : TEXCOORD5; // x = sun through the clouds, y = gust passing
};
Varyings vert(Attributes v)
{
float shells = _GcShells.x;
// instance 0 is the top shell; a single shell is the solid floor under the strands
float t = shells > 1 ? 1 - (float)v.iid / (shells - 1) : 0;
float2 plane = v.positionOS.xz * _GcGrid.x;
float3 up = normalize(_GcC.xyz * _GcPlanet.w + _GcE1.xyz * plane.x + _GcE2.xyz * plane.y);
float3 t1, t2;
GcTangents(up, t1, t2);
// a grid cuts corners over bumps: each corner stands on the highest ground within half a cell of it, and a
// little over, so no bump between corners comes up through the floor
float hs = _GcGrid.y * 0.5 / _GcPlanet.w;
float ground = max(GcHeight(up), max(max(GcHeight(normalize(up + t1 * hs)), GcHeight(normalize(up - t1 * hs))),
max(GcHeight(normalize(up + t2 * hs)), GcHeight(normalize(up - t2 * hs)))));
float3 root = _GcPlanet.xyz + up * (_GcPlanet.w + ground + 0.01 + _GcGrid.y * 0.012);
float dist = length(root - _GcCam.xyz);
float fade = 1 - smoothstep(_GcFade.x, _GcFade.y, dist);
float patch = GcNoise(root * 0.045).r;
// never taller than the crew's eyes: from inside, the shells would be seen edge-on
float H = min(_GcHeight * lerp(0.85, 1.15, patch), _GcFurMax) * fade;
// wind: rolling gusts that comb the whole pile
float tm = _GcTime;
float gust = GcNoise(root * 0.06 + float3(-0.8, 0.1, -0.45) * tm * 0.9).g * 0.8 + 0.2;
float sway = sin(tm * 2.3 + dot(root, float3(0.7, 0.3, 0.4))) * 0.3;
float bend = t * t * H * _Wind * (1.0 + _GcGust) * 0.35;
float2 off = float2(gust * 0.9 + sway * 0.4, sway * 0.3) * bend;
// the pile is combed in slowly turning swirls, so from above the strands read as brushed fur, not dots
float ca = GcNoise(root * 0.11).b * 9.0 + GcNoise(root * 0.5).a * 1.5;
off += float2(cos(ca), sin(ca)) * t * t * H * 0.32;
// mowing spots pull the pile toward the cutter and up (sucked in)
float lift = 0;
for (int i = 0; i < (int)_GcVortexCount; i++)
{
float3 toV = root - _GcVortex[i].xyz;
float2 d = float2(dot(toV, t1), dot(toV, t2));
float reach = _GcVortexReach[i];
float f = _GcVortex[i].w * exp(-dot(d, d) / max(0.2, reach * reach * 2.5));
float2 swirl = float2(-d.y, d.x);
off += (-normalize(d + 1e-4) * 0.8 + normalize(swirl + 1e-4) * 0.5) * f * t * H * 0.6;
lift += f * t * 0.2;
}
// people and vehicles part it
for (int j = 0; j < (int)_GcPusherCount; j++)
{
float4 ps = _GcPushers[j];
if (ps.w <= 0) continue;
float3 toP = root - ps.xyz;
float2 d = float2(dot(toP, t1), dot(toP, t2));
float f = saturate(1 - length(d) / ps.w) * step(-dot(toP, up) - 0.6, H);
off += normalize(d + 1e-4) * f * t * H * 0.9;
lift -= f * t * 0.6;
}
float offLen = length(off);
float rise = t * H * (1 + lift) - offLen * offLen / max(0.15, H) * 0.3 * t;
float3 wpos = root + t1 * off.x + t2 * off.y + up * rise;
Varyings o;
o.positionWS = wpos;
o.positionCS = TransformWorldToHClip(wpos);
o.data = float4(t, H, patch, fade);
o.root = root;
o.plane = plane;
o.fog = ComputeFogFactor(o.positionCS.z);
o.air = float2(GcCloudSun(root, tm), gust);
return o;
}
half4 frag(Varyings i, bool front : SV_IsFrontFace) : SV_Target
{
float t = i.data.x, H = i.data.y;
float dist = length(i.root - _GcCam.xyz);
// rings hand over through a dithered band (same noise on both sides, so every pixel picks exactly one)
float ign = frac(52.9829189 * frac(dot(i.positionCS.xy, float2(0.06711056, 0.00583715))));
float e = (ign - 0.5) * _GcShells.w;
if ((_GcShells.y > 0 && dist < _GcShells.y + e) || dist >= _GcShells.z + e) discard;
// a sector's square reaches past its borders: each pixel belongs to one sector
float3 d = normalize(i.root - _GcPlanet.xyz);
for (int b = 0; b < 6; b++) if (dot(d, _GcBorders[b].xyz) > 0) discard;
float2 mask = GcMask(i.plane);
bool solid = t < 0.001; // the bottom of the pile: the floor everything stands on
if (!solid && mask.g > 0.5) discard;
if (_GcFade.z > 0.5 && mask.r < 0.5 && mask.g < 0.5) discard;
// under pieces reads exactly like mown ground: no dirt patches
float cut = saturate(max(mask.r, mask.g));
float top = 1 - cut; // mown means mown: nothing is left standing
// the strands: tapered cones from the strand texture; far away the mips average them out, so the cut
// threshold drifts down with the mip level to keep the pile its full height
float2 fuv = float2(dot(d, _GcFurU.xyz), dot(d, _GcFurV.xyz)) / dot(d, _GcFurN.xyz) * _GcPlanet.w * _GcFurScale;
float4 s = SAMPLE_TEXTURE2D(_GcFurTex, sampler_GcFurTex, fuv);
float lod = saturate(CALCULATE_TEXTURE2D_LOD(_GcFurTex, sampler_GcFurTex, fuv) / 4.0);
// dither the layer threshold by up to one shell step: equal steps otherwise show up as rings
float need = (t + (ign - 0.5) / max(1, _GcShells.x - 1)) / max(0.02, top);
if (t > top + 0.001) discard;
if (t > 0.02 && s.r < need * lerp(1, 0.42, lod)) discard;
// colour: dark roots, bright tips, big dry patches, streaks of hemp, pale fresh stubble
// (two octaves of world noise keep the pile from reading as one flat colour once the mips average it)
float mid = GcNoise(i.root * 0.33).r, fine = GcNoise(i.root * 1.9).g;
float macro = GcNoise(i.root * 0.012).a * 0.45 + mid * 0.35 + fine * 0.2;
float3 tip = lerp(_TipColor.rgb, _DryColor.rgb, saturate(i.data.z * 0.7 + macro * 0.3 + s.g * 0.2 - 0.42));
tip = lerp(tip, _HempColor.rgb, step(0.86, s.g) * 0.8);
// straw stubble thinning out over the earth in loose patches
float bare = smoothstep(0.4, 0.6, mid * 0.75 + fine * 0.25);
tip = lerp(tip, lerp(_CutColor.rgb, _SoilColor.rgb, bare * 0.7) * lerp(0.86, 1.1, macro), cut);
// far shells stand in for the tips of the strands, so they take the same bright colour
float k = lerp(saturate(t / max(0.05, top)), 1, lod * step(1.5, _GcShells.x));
// the floor shows between the strands from up high: it's the shade under grass, not black
if (solid) k = max(k, lerp(0.5, 0.42, cut));
// mown stubble: short straw tips over pale ground, so every trail reads clearly
float3 root = lerp(_RootColor.rgb, _SoilColor.rgb, cut);
float3 albedo = lerp(root, tip, pow(k, 0.7)) * lerp(0.85, 1.12, s.g) * lerp(0.84, 1.1, macro);
albedo *= 1 + (i.air.y - 0.6) * 0.3 * k * (1 - cut); // a gust lays the grass over, and it flashes paler
albedo *= lerp(lerp(0.38, 1, cut), 1, k); // the pile shades its own roots
// a solid shell reads more saturated than lit strands with gaps: meet them at the ring seam
albedo = lerp(albedo, dot(albedo, float3(0.3, 0.59, 0.11)).xxx, 0.16 * lod * step(1.5, _GcShells.x));
Light main = GetMainLight(TransformWorldToShadowCoord(i.positionWS));
float3 n = _GcCamUp.xyz;
float3 v = normalize(GetCameraPositionWS() - i.positionWS);
float ndl = saturate(dot(n, main.direction) * 0.55 + 0.45);
float back = pow(saturate(dot(v, -main.direction)), 3) * 0.45 * k;
float shadow = lerp(0.35, 1, main.shadowAttenuation) * i.air.x;
float3 col = albedo * (main.color * (ndl + back) * shadow + SampleSH(float3(0, 1, 0)) * 0.9 + GcLamp(i.positionWS));
// velvet sheen at grazing angles (what makes a pile read as fur)
float rim = pow(1 - saturate(dot(v, n)), 4);
col += lerp(_TipColor.rgb, 1, 0.4) * rim * 0.22 * k * shadow;
col *= GcContact(i.positionWS);
col = MixFog(col, i.fog);
return half4(col, 1);
}
ENDHLSL
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9f8b7781768d0924e80f1b90325aab02
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,224 @@
// Herbaria-7's meadow up close: every strand of the pile is its own long round "sausage". GrassField.cs draws a small
// camera-facing ribbon with RenderMeshPrimitives, one draw per sector, one instance per cell of the sector's flat frame;
// the root, height, tint and bend all come from SV_InstanceID and the cell, so there is no per-instance buffer. The ribbon is shaded as a cylinder with a rounded
// tip, and nothing is cut out per pixel (no discard), so early-z keeps the overdraw cheap. Mown cells keep nothing.
// Position stream: x = side (-1..1), y = along the strand (0..1).
Shader "GrassCutter/GrassStrand"
{
Properties
{
_RootColor ("Root", Color) = (0.05, 0.16, 0.04, 1)
_TipColor ("Tip", Color) = (0.38, 0.68, 0.17, 1)
_DryColor ("Dry tip", Color) = (0.82, 0.78, 0.33, 1)
_HempColor ("Hemp strands", Color) = (0.2, 0.5, 0.2, 1)
_CutColor ("Fresh stub", Color) = (0.86, 0.82, 0.46, 1)
_Border ("Sector border", Color) = (0.98, 0.76, 0.26, 1)
_Wind ("Wind", Float) = 1
}
SubShader
{
Tags { "RenderType" = "Opaque" "Queue" = "Geometry+10" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }
Pass
{
Name "StrandForward"
Tags { "LightMode" = "UniversalForward" }
Cull Off
ZWrite On
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/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Planet.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _RootColor, _TipColor, _DryColor, _HempColor, _CutColor, _Border;
float _Wind;
CBUFFER_END
// per draw (MaterialPropertyBlock)
float4 _GcGrid; // first cell x, first cell z, cell, cells per row
float4 _GcStrand; // inner radius, outer radius, seam band, strand width
// globals
float4 _GcCam, _GcCamFwd, _GcCamUp;
float4 _GcVortex[12]; // where, strength
float _GcVortexReach[12];
float _GcVortexCount;
float _GcGust; // the weather's wind on top of the breeze: 0 calm
float4 _GcPushers[8]; // x, y, z, radius
float _GcPusherCount;
float _GcTime, _GcHeight, _GcFurMax;
struct Attributes
{
float3 positionOS : POSITION;
uint iid : SV_InstanceID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 positionWS : TEXCOORD0;
float3 rightWS : TEXCOORD1;
float3 viewWS : TEXCOORD2;
float4 albedo : TEXCOORD3; // rgb, a = along the strand
float side : TEXCOORD4;
float fog : TEXCOORD5;
float sun : TEXCOORD6; // through the clouds
};
float4 Hash4(float2 p)
{
float4 p4 = frac(float4(p.xyxy) * float4(0.1031, 0.1030, 0.0973, 0.1099));
p4 += dot(p4, p4.wzxy + 33.33);
return frac((p4.xxyz + p4.yzzw) * p4.zywx);
}
Varyings Collapse()
{
Varyings o = (Varyings)0;
o.positionCS = float4(0, 0, -2, 1); // behind the near plane: clipped
return o;
}
Varyings vert(Attributes v)
{
uint n = (uint)_GcGrid.w;
float cell = _GcGrid.z;
uint ix = v.iid % n, iz = v.iid / n;
float2 cid = _GcGrid.xy + float2(ix, iz);
float4 h = Hash4(cid + _GcSalt.xy);
float2 plane = (cid + h.xy) * cell;
float3 up;
float edge;
if (!GcInSector(plane, up, edge)) return Collapse();
float groundH = GcHeight(up);
float3 root = _GcPlanet.xyz + up * (_GcPlanet.w + groundH);
// only this ring, handing over strand by strand; strands behind the camera are skipped right here
float3 toRoot = root - _GcCam.xyz;
float dist = length(toRoot);
float e = (h.w - 0.5) * _GcStrand.z;
if ((_GcStrand.x > 0 && dist < _GcStrand.x + e) || dist >= _GcStrand.y + e) return Collapse();
if (dist > 4 && dot(toRoot, _GcCamFwd.xyz) < -2) return Collapse();
float2 mask = GcMask(plane);
if (mask.g > 0.5 || mask.r > 0.6) return Collapse();
float cut = saturate(mask.r);
float4 big = GcNoise(root * 0.045);
float patch = big.r;
float H = min(_GcHeight * lerp(0.85, 1.15, patch), _GcFurMax);
// grass beside a cut stands lower and doesn't lean over it: even a strip as narrow as the scissors' shows
float near = saturate(GcMaskNear(plane) * 2.0);
float len = H * lerp(0.74, 1.12, h.z) * lerp(1, 0.5, near);
float full = len;
len *= 1 - cut; // mown means gone, no stubble
if (len < 0.02) return Collapse();
float t = v.positionOS.y, s = v.positionOS.x;
float3 t1, t2;
GcTangents(up, t1, t2);
// wind: rolling gusts
float tm = _GcTime;
float gust = GcNoise(root * 0.06 + float3(-0.8, 0.1, -0.45) * tm * 0.9).g * 0.8 + 0.2;
float sway = sin(tm * 2.3 + dot(root, float3(0.7, 0.3, 0.4)) + h.y * 6.0) * 0.3;
float bend = t * t * len * _Wind * (1.0 + _GcGust) * 0.35;
float2 off = float2(gust * 0.9 + sway * 0.4, sway * 0.3) * bend;
// combed in slow swirls, every strand with a bit of its own lean
float ca = GcNoise(root * 0.11).b * 9.0 + (h.x - 0.5) * 2.2;
off += float2(cos(ca), sin(ca)) * t * t * len * lerp(0.25, 0.5, h.y) * (1 - near * 0.7);
// mowing spots pull the tips toward the cutter and up (sucked in)
float lift = 0;
for (int i = 0; i < (int)_GcVortexCount; i++)
{
float3 toV = root - _GcVortex[i].xyz;
float2 d = float2(dot(toV, t1), dot(toV, t2));
float reach = _GcVortexReach[i];
float f = _GcVortex[i].w * exp(-dot(d, d) / max(0.2, reach * reach * 2.5));
float2 swirl = float2(-d.y, d.x);
off += (-normalize(d + 1e-4) * 0.8 + normalize(swirl + 1e-4) * 0.5) * f * t * len * 0.6;
lift += f * t * 0.2;
}
// people and vehicles part them
for (int j = 0; j < (int)_GcPusherCount; j++)
{
float4 ps = _GcPushers[j];
if (ps.w <= 0) continue;
float3 toP = root - ps.xyz;
float2 d = float2(dot(toP, t1), dot(toP, t2));
float f = saturate(1 - length(d) / ps.w) * step(-dot(toP, up) - 0.6, len);
off += normalize(d + 1e-4) * f * t * len * 0.9;
lift -= f * t * 0.6;
}
float offLen = length(off);
float rise = t * len * (1 + lift) - offLen * offLen / max(0.15, len) * 0.3 * t;
float3 center = root + t1 * off.x + t2 * off.y + up * rise;
// the ribbon turns to the camera around the strand's own direction, and rounds off at the tip
float3 tangent = normalize((t1 * off.x + t2 * off.y) * 2.0 / max(t, 0.1) + up * len);
float3 view = normalize(GetCameraPositionWS() - center);
float3 right = cross(tangent, view);
right /= max(1e-4, length(right));
float tipK = saturate((t - 0.86) / 0.14);
float width = _GcStrand.w * lerp(0.8, 1.2, h.w) * sqrt(saturate(1 - tipK * tipK));
float3 wpos = center + right * s * width * 0.5;
Varyings o;
o.positionWS = wpos;
o.positionCS = TransformWorldToHClip(wpos);
o.rightWS = right;
o.viewWS = cross(right, tangent);
o.side = s;
// colour: dark roots, bright tips, big dry patches, strands of hemp, pale fresh stubs, gold along the borders
float mid = GcNoise(root * 0.33).r;
float macro = big.a * 0.55 + mid * 0.45;
float3 tip = lerp(_TipColor.rgb, _DryColor.rgb, saturate(patch * 0.7 + macro * 0.3 + h.w * 0.2 - 0.42));
tip = lerp(tip, _HempColor.rgb, step(0.87, h.y) * 0.85);
tip = lerp(tip, _CutColor.rgb * lerp(1, float3(0.8, 0.73, 0.72), smoothstep(0.4, 0.6, mid)), cut);
tip = lerp(tip, _Border.rgb, 1 - smoothstep(0.1, 0.24, edge));
float k = saturate(t * len / max(0.05, full) + cut * t); // height in the pile, not along this strand
float3 base = lerp(_RootColor.rgb, _CutColor.rgb * 0.7, cut);
float3 col = lerp(base, tip, pow(k, 0.75)) * lerp(0.84, 1.12, h.z) * lerp(0.86, 1.08, macro);
col *= lerp(lerp(0.45, 0.95, cut), 1, k); // the pile shades its own roots
col *= 1 + (gust - 0.6) * 0.3 * k * (1 - cut); // a gust lays the grass over, and it flashes paler
o.albedo = float4(col, k);
o.fog = ComputeFogFactor(o.positionCS.z);
o.sun = GcCloudSun(root, tm);
return o;
}
half4 frag(Varyings i) : SV_Target
{
// a flat ribbon lit like a round tube
float s = i.side;
float3 n = normalize(i.rightWS * s + i.viewWS * sqrt(saturate(1 - s * s)) + _GcCamUp.xyz * 0.35);
float k = i.albedo.a;
Light main = GetMainLight(TransformWorldToShadowCoord(i.positionWS));
float3 v = normalize(GetCameraPositionWS() - i.positionWS);
float ndl = saturate(dot(n, main.direction) * 0.6 + 0.4);
float back = pow(saturate(dot(v, -main.direction)), 3) * 0.45 * k;
float shadow = lerp(0.35, 1, main.shadowAttenuation) * i.sun;
float3 col = i.albedo.rgb * (main.color * (ndl + back) * shadow + SampleSH(float3(0, 1, 0)) * 0.9 + GcLamp(i.positionWS));
// the soft shine down the middle of a sausage
col += main.color * pow(saturate(dot(n, normalize(main.direction + v))), 18) * 0.14 * k * shadow;
col *= GcContact(i.positionWS);
col = MixFog(col, i.fog);
return half4(col, 1);
}
ENDHLSL
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6361c17e6784cc844b6e556877639e0a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,138 @@
// 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;
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);
// 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
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 42dcba3049c104b42a2c783fde9a891e
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

104
Assets/Shaders/Planet.hlsl Normal file
View File

@ -0,0 +1,104 @@
// What every shader on Herbaria-7 shares: the ball (Planet.cs), its soil heights, a tiling 3D noise, and the sector being
// drawn with its mow map (HexGrid.cs, MowMap.cs). "up" is simply the direction from the centre.
#ifndef GC_PLANET_INCLUDED
#define GC_PLANET_INCLUDED
TEXTURE2D_ARRAY(_GcHeights); SAMPLER(sampler_GcHeights);
TEXTURE3D(_GcNoise3); SAMPLER(sampler_GcNoise3);
TEXTURE2D(_GcMaskTex); SAMPLER(sampler_GcMaskTex);
float4 _GcPlanet; // centre, radius
float4 _GcLampPos, _GcLampDir; // the headlamp: position and reach, direction and power
float _GcCloudShade; // how much of the sun a passing cloud takes away
/// How much of the player's own headlamp reaches a point.
float GcLamp(float3 p)
{
float3 to = p - _GcLampPos.xyz;
float d = max(length(to), 1e-3);
float cone = smoothstep(0.84, 0.95, dot(to / d, _GcLampDir.xyz));
float fall = saturate(1 - d / _GcLampPos.w);
return _GcLampDir.w * cone * fall * fall * 2.2;
}
float4 _GcContacts[24]; // where the machines stand (ContactShade.cs): a ground point and how far its dark reaches
float _GcContactCount;
/// The dark under the machines: 1 out in the open, less right under a tyre or a body. Measured in 3D, so a grass blade
/// standing up out of it is darker at its root than at its tip.
float GcContact(float3 p)
{
float k = 1;
int n = (int)_GcContactCount;
[loop] for (int c = 0; c < n; c++)
{
float4 q = _GcContacts[c];
float3 to = p - q.xyz;
float d2 = dot(to, to) / max(q.w * q.w, 1e-4);
float f = saturate(1 - d2);
k *= 1 - 0.5 * f * f;
}
return k;
}
float _GcHeightRes;
// per draw: the sector (MaterialPropertyBlock)
float4 _GcC, _GcE1, _GcE2;
float4 _GcSalt; // xy = seed, z = flat frame metres to mow map uv
float4 _GcBorders[6];
float GcHeight(float3 d)
{
float3 a = abs(d);
float2 uv;
float f;
if (a.x >= a.y && a.x >= a.z) { uv = d.zy / a.x; f = d.x > 0 ? 0 : 1; }
else if (a.y >= a.z) { uv = d.xz / a.y; f = d.y > 0 ? 2 : 3; }
else { uv = d.xy / a.z; f = d.z > 0 ? 4 : 5; }
uv = ((uv * 0.5 + 0.5) * (_GcHeightRes - 1) + 0.5) / _GcHeightRes;
return SAMPLE_TEXTURE2D_ARRAY_LOD(_GcHeights, sampler_GcHeights, uv, f, 0).r;
}
float3 GcSoil(float3 d) { return _GcPlanet.xyz + d * (_GcPlanet.w + GcHeight(d)); }
// r, g, b, a: four unrelated value noises, one lattice cell per unit of p
float4 GcNoise(float3 p) { return SAMPLE_TEXTURE3D_LOD(_GcNoise3, sampler_GcNoise3, p / 64.0, 0); }
// a cloud's shadow going over: 1 in the sun, less under it. Big soft blobs that drift with the wind.
float GcCloudSun(float3 p, float time)
{
float n = GcNoise(p * 0.009 + float3(-0.8, 0.1, -0.45) * time * 0.02).a;
return 1 - smoothstep(0.5, 0.62, n) * _GcCloudShade;
}
// tangent axes that flow smoothly over the ball, t1 along the wind
void GcTangents(float3 up, out float3 t1, out float3 t2)
{
const float3 wind = float3(0.87, 0.11, 0.48);
t1 = normalize(wind - up * dot(wind, up) + 1e-5);
t2 = cross(up, t1);
}
// this sector's mow map at a spot of its flat frame: r = cut (0..1), g = nothing grows here
float2 GcMask(float2 plane)
{
return SAMPLE_TEXTURE2D_LOD(_GcMaskTex, sampler_GcMaskTex, plane * _GcSalt.z + 0.5, 0).rg;
}
// how close a cut is: the map blurred over half a metre, so the grass beside a narrow strip can stand lower than the rest
float GcMaskNear(float2 plane)
{
return SAMPLE_TEXTURE2D_LOD(_GcMaskTex, sampler_GcMaskTex, plane * _GcSalt.z + 0.5, 1.5).r;
}
// A spot in the flat frame of this draw's sector, on the ball. Each strand belongs to exactly one sector: the one whose
// borders all lie ahead of it. edge = metres to the nearest of them.
bool GcInSector(float2 plane, out float3 dir, out float edge)
{
dir = normalize(_GcC.xyz * _GcPlanet.w + _GcE1.xyz * plane.x + _GcE2.xyz * plane.y);
edge = 1e5;
for (int k = 0; k < 6; k++) edge = min(edge, -dot(dir, _GcBorders[k].xyz));
return edge >= 0;
}
#endif

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 429487f7618502947935586b033dc957
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

158
Assets/Shaders/Sky.shader Normal file
View File

@ -0,0 +1,158 @@
// Tethys-B sky: soft overcast-teal gradient, a hazy sun, drifting cloud banks and a huge ringed gas giant.
Shader "GrassCutter/Sky"
{
Properties
{
_ZenithColor ("Zenith", Color) = (0.33, 0.62, 0.86, 1)
_HorizonColor ("Horizon", Color) = (0.78, 0.9, 0.93, 1)
_GroundColor ("Below horizon", Color) = (0.55, 0.72, 0.78, 1)
_SunColor ("Sun", Color) = (1, 0.95, 0.85, 1)
_SunDir ("Sun direction", Vector) = (0.3, 0.55, -0.6, 0)
_CloudTex ("Cloud noise", 2D) = "white" {}
_CloudColor ("Clouds", Color) = (1, 1, 1, 1)
_CloudShade ("Cloud shade", Color) = (0.62, 0.74, 0.84, 1)
_CloudCover ("Cloud cover", Range(0,1)) = 0.5
_PlanetTex ("Planet", 2D) = "black" {}
_PlanetDir ("Planet direction", Vector) = (-0.55, 0.42, 0.72, 0)
_PlanetSize ("Planet angular size", Float) = 0.42
_PlanetTint ("Planet tint", Color) = (1, 1, 1, 1)
_Exposure ("Exposure", Float) = 1.0
}
SubShader
{
Tags { "Queue" = "Background" "RenderType" = "Background" "PreviewType" = "Skybox" "RenderPipeline" = "UniversalPipeline" }
Cull Off ZWrite Off
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _ZenithColor, _HorizonColor, _GroundColor, _SunColor, _SunDir, _CloudColor, _CloudShade, _PlanetDir, _PlanetTint;
float _CloudCover, _PlanetSize, _Exposure;
float4 _CloudTex_ST, _PlanetTex_ST;
CBUFFER_END
TEXTURE2D(_CloudTex); SAMPLER(sampler_CloudTex);
TEXTURE2D(_PlanetTex); SAMPLER(sampler_PlanetTex);
TEXTURE3D(_GcNoise3); SAMPLER(sampler_GcNoise3);
float _OsTime, _GcSkyOn, _GcNight;
// weather (all 0 when nothing sets them): extra cloud, storm gloom, a lightning flash, acid tint, sunrise/sunset
float _GcCoverAdd, _GcStorm, _GcFlash, _GcAcid, _GcDusk;
float4x4 _GcSkyRot; // the sky hangs over wherever the camera stands on the planet
struct A { float4 pos : POSITION; };
struct V { float4 pos : SV_POSITION; float3 dir : TEXCOORD0; };
V vert(A a)
{
V o;
o.pos = TransformObjectToHClip(a.pos.xyz);
o.dir = a.pos.xyz;
return o;
}
float Noise(float3 p) { return SAMPLE_TEXTURE3D_LOD(_GcNoise3, sampler_GcNoise3, p / 64.0, 0).r; }
// billows on a dome: a big slow shape, bent about so it never lines up, its edges worn away by finer noise
float Billows(float2 uv, float t)
{
float3 p = float3(uv.x + t * 0.012, t * 0.004, uv.y + t * 0.005);
float3 bend = SAMPLE_TEXTURE3D_LOD(_GcNoise3, sampler_GcNoise3, p * 0.5 / 64.0, 0).gba - 0.5;
return Noise(p * 0.55 + bend * 1.6) * 0.62 + Noise(p * 1.4 + bend) * 0.26 + Noise(p * 3.7) * 0.09 + Noise(p * 8.3) * 0.03;
}
float Clouds(float3 d, float3 sun, float t, out float lit)
{
lit = 1;
if (d.y <= 0.0) return 0;
// curved cloud dome: the big offset keeps the projection from stretching into streaks at the horizon
float2 uv = d.xz / (d.y + 0.3) * 2.2;
float a = Billows(uv, t);
float edge = lerp(0.68, 0.36, saturate(_CloudCover + _GcCoverAdd));
float c = smoothstep(edge, edge + 0.13, a);
if (c <= 0) return 0;
// the side away from the sun is the one with more cloud in front of it
lit = saturate(0.6 + (a - Billows(uv + normalize(sun.xz + 1e-4) * 0.16, t)) * 6);
// clouds thin out into haze toward the horizon
return c * smoothstep(0.02, 0.2, d.y);
}
float Stars(float3 d)
{
float3 g = floor(d * 420);
float h = frac(sin(dot(g, float3(12.9898, 78.233, 37.719))) * 43758.5453);
return step(0.9988, h) * (h - 0.9988) * 700 * smoothstep(-0.02, 0.2, d.y);
}
half4 frag(V i) : SV_Target
{
float3 d = normalize(i.dir);
if (_GcSkyOn > 0.5) d = mul((float3x3)_GcSkyRot, d);
float3 sun = normalize(_SunDir.xyz);
float t = _OsTime;
float up = d.y;
float3 sky = lerp(_HorizonColor.rgb, _ZenithColor.rgb, pow(saturate(up), 0.55));
sky = lerp(sky, _GroundColor.rgb, saturate(-up * 6));
float sd = saturate(dot(d, sun));
// sunrise and sunset: the horizon catches fire, hottest under the sun, and the zenith turns violet
float2 flatD = normalize(d.xz + 1e-4), flatS = normalize(sun.xz + 1e-4);
float toward = pow(saturate(dot(flatD, flatS) * 0.5 + 0.5), 3);
float low = 1 - saturate(abs(up) * 2.2);
float3 fire = lerp(float3(0.95, 0.38, 0.32), float3(1.0, 0.55, 0.16), toward) * lerp(0.75, 1.3, toward);
sky = lerp(sky, fire, _GcDusk * low * (0.5 + 0.5 * toward));
sky = lerp(sky, sky * float3(0.82, 0.66, 1.0), _GcDusk * saturate(up * 1.5) * 0.55);
sky += _SunColor.rgb * (pow(sd, 6) * 0.25 + pow(sd, 64) * 0.6);
// gas giant (drawn behind clouds)
float3 pd = normalize(_PlanetDir.xyz);
float3 pr = normalize(cross(float3(0, 1, 0), pd));
float3 pu = cross(pd, pr);
float facing = dot(d, pd);
if (facing > 0)
{
float2 puv = float2(dot(d, pr), dot(d, pu)) / (facing * _PlanetSize) * 0.5 + 0.5;
if (all(puv > 0) && all(puv < 1))
{
float4 p = SAMPLE_TEXTURE2D(_PlanetTex, sampler_PlanetTex, puv) * _PlanetTint;
// atmospheric fade near the horizon
float haze = saturate(up * 4 + 0.2);
sky = lerp(sky, p.rgb * 1.05 + sky * 0.12, p.a * haze * 0.96);
}
}
// sun disc
sky += _SunColor.rgb * smoothstep(0.9993, 0.9998, sd) * 4;
// clouds, lit from the sun side
float lit;
float c = Clouds(d, sun, t, lit);
float3 cloud = lerp(_CloudShade.rgb, _CloudColor.rgb, lit);
// at sunrise and sunset the clouds glow from below
cloud = lerp(cloud, cloud * float3(1.25, 0.72, 0.55), _GcDusk * 0.7);
cloud *= lerp(1, 0.42, _GcStorm);
sky = lerp(sky, cloud, c * 0.92);
// the thin edges of the clouds near the sun catch fire
sky += _SunColor.rgb * pow(sd, 10) * c * (1 - c) * 2.4;
// weather: storms grey the whole sky out, acid rain stains it sulphur-green, lightning lights the clouds
float grey = dot(sky, float3(0.3, 0.5, 0.2));
sky = lerp(sky, grey * float3(0.5, 0.56, 0.62), _GcStorm * 0.7);
sky = lerp(sky, sky * float3(0.85, 1.05, 0.55), _GcAcid * 0.6);
sky += _GcFlash * float3(0.75, 0.8, 1.0) * (0.25 + c * 1.2);
// night: the sky goes out and the stars come through the gaps in the clouds
float3 dark = sky * 0.07 + float3(0.012, 0.018, 0.04) + Stars(d) * (1 - c);
sky = lerp(sky, dark, _GcNight);
return half4(sky * _Exposure, 1);
}
ENDHLSL
}
}
FallBack Off
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 33919bf3ea3c95545b717ff211769f53
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,85 @@
// The look of the people on the video calls (the Director, his assistant): lit by the studio's own lamps, fixed in view
// space, so the planet's sun, its night and its fog have nothing to do with them. A warm key from up front and to one side,
// a cool fill, a rim from behind, soft wrap-round light like a toy under studio lamps. _Lit 0 is the plain picture
// behind them. _Flush reddens the skin when he's angry.
Shader "GrassCutter/Studio"
{
Properties
{
_BaseMap ("Texture", 2D) = "white" {}
_BaseColor ("Colour", Color) = (1, 1, 1, 1)
_Lit ("Lit", Float) = 1
_Flush ("Flush", Color) = (0, 0, 0, 0)
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", Float) = 2
}
SubShader
{
Tags { "RenderType" = "Opaque" "Queue" = "Geometry" "RenderPipeline" = "UniversalPipeline" }
Pass
{
Name "Studio"
Tags { "LightMode" = "UniversalForward" }
Cull [_Cull]
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
float4 _BaseMap_ST;
float4 _BaseColor;
float _Lit;
float4 _Flush;
float _Cull;
CBUFFER_END
struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; float2 uv : TEXCOORD0; };
struct Varyings { float4 positionCS : SV_POSITION; float3 normalVS : TEXCOORD0; float2 uv : TEXCOORD1; float3 viewVS : TEXCOORD2; };
Varyings vert(Attributes i)
{
Varyings o;
float3 ws = TransformObjectToWorld(i.positionOS.xyz);
o.positionCS = TransformWorldToHClip(ws);
o.normalVS = mul((float3x3)UNITY_MATRIX_V, TransformObjectToWorldNormal(i.normalOS));
o.viewVS = -TransformWorldToView(ws);
o.uv = TRANSFORM_TEX(i.uv, _BaseMap);
return o;
}
float4 frag(Varyings i, bool front : SV_IsFrontFace) : SV_Target
{
float3 albedo = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, i.uv).rgb * _BaseColor.rgb;
if (_Lit < 0.5) return float4(albedo, 1);
float3 n = normalize(i.normalVS) * (front ? 1 : -1);
float3 v = normalize(i.viewVS);
// view space: x right, y up, z toward the viewer
float3 key = normalize(float3(-0.55, 0.6, 0.6));
float3 fill = normalize(float3(0.7, 0.1, 0.5));
float3 rim = normalize(float3(0.35, 0.45, -0.8));
float k = saturate(dot(n, key) * 0.6 + 0.4); // wrapped, so the shadow side never goes black
float f = saturate(dot(n, fill) * 0.5 + 0.5);
float r = pow(saturate(1 - dot(n, v)), 3) * saturate(dot(n, rim) + 0.6);
float3 light = 0.38 * float3(0.92, 0.95, 1.05) // the room
+ 0.6 * k * float3(1.03, 0.99, 0.94) // the key, a little warm
+ 0.14 * f * float3(0.82, 0.9, 1.0) // the fill, cool
+ 0.32 * r * float3(1.0, 0.98, 0.94); // the rim
float3 c = albedo * light;
// a touch of shine where the key glances off
float3 h = normalize(key + v);
c += pow(saturate(dot(n, h)), 40) * 0.08;
// red in the face: skin is the warm, light colours
float skin = saturate((albedo.r - albedo.b) * 2.2 - 0.3) * saturate((albedo.r - 0.35) * 3);
c = lerp(c, c * float3(1.25, 0.62, 0.55), _Flush.a * skin);
// the painted colours are strong: taken down a little toward grey, and a soft shoulder on the brights,
// as the planet's camera does with its tone mapping
float l = dot(c, float3(0.2126, 0.7152, 0.0722));
c = lerp(l.xxx, c, 0.8);
c = c / (1 + 0.2 * c) * 1.12;
return float4(c, 1);
}
ENDHLSL
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 75086abd6d6120d4bb4d4e7f0be0cd44
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: