Frame time on a big farm: batched grass, sleeping bundles, no light probes
Measured in a real 2560x1440 window on the player's Mommy save (RTX 4090): the GPU took ~5 ms, the main thread the rest. - Grass: a fully mown sector draws only its floor (one draw, not up to six); untouched and fully mown sectors share a mow map look, so the fur pile draws them all in one instanced call per pile (GC_SECTOR_BUFFER, sector frames from a structured buffer). Grass draws 1112 -> 337 at the base, 876 -> 439 in the meadow. - Bundles: loose ones sleep when they come to rest (our gravity kept ~600 bodies awake), ones on belts skip the ground checks, and all of them are stepped from one CargoTick instead of two Unity messages each. - Belts leave a jammed line alone and only look every few steps whether it can move; splitters test distance before transforming every bundle. - Light probes off on everything (the planet has none) and the GPU Resident Drawer off: both cost CPU per moving renderer for nothing. - -demogpu N -onscreen measures frame time with one feature off at a time. Base view 17-19 ms -> 14-15 ms, meadow 14-16 ms -> 11.5-12 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -37,9 +37,26 @@ Shader "GrassCutter/GrassFur"
|
||||
#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
|
||||
// many sectors in one draw: instance = sector * shells + shell, the sector's frame from a buffer. Only for
|
||||
// sectors that share a mow map look (untouched, or mown to the last blade): on a small planet there are
|
||||
// hundreds of them in view, and one draw each was most of a frame's CPU.
|
||||
#pragma multi_compile_local _ GC_SECTOR_BUFFER
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#if defined(GC_SECTOR_BUFFER)
|
||||
struct GcSectorData { float4 c, e1, e2, salt, grid; float4 b[6]; };
|
||||
StructuredBuffer<GcSectorData> _GcSectorBuf;
|
||||
static GcSectorData gcS;
|
||||
#define GC_SECTOR_C gcS.c
|
||||
#define GC_SECTOR_E1 gcS.e1
|
||||
#define GC_SECTOR_E2 gcS.e2
|
||||
#define GC_SECTOR_SALT gcS.salt
|
||||
#define GC_SECTOR_BORDER(k) gcS.b[k]
|
||||
#define GC_GRID gcS.grid
|
||||
#else
|
||||
#define GC_GRID _GcGrid
|
||||
#endif
|
||||
#include "Planet.hlsl"
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
@ -77,6 +94,7 @@ Shader "GrassCutter/GrassFur"
|
||||
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;
|
||||
nointerpolation uint sid : TEXCOORD6; // which sector of the draw
|
||||
float2 plane : TEXCOORD4; // the sector's flat frame (mow map)
|
||||
float2 air : TEXCOORD5; // x = sun through the clouds, y = gust passing
|
||||
};
|
||||
@ -84,18 +102,23 @@ Shader "GrassCutter/GrassFur"
|
||||
Varyings vert(Attributes v)
|
||||
{
|
||||
float shells = _GcShells.x;
|
||||
uint sid = v.iid / (uint)shells;
|
||||
uint shell = v.iid - sid * (uint)shells;
|
||||
#if defined(GC_SECTOR_BUFFER)
|
||||
gcS = _GcSectorBuf[sid];
|
||||
#endif
|
||||
// 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);
|
||||
float t = shells > 1 ? 1 - (float)shell / (shells - 1) : 0;
|
||||
float2 plane = v.positionOS.xz * GC_GRID.x;
|
||||
float3 up = normalize(GC_SECTOR_C.xyz * _GcPlanet.w + GC_SECTOR_E1.xyz * plane.x + GC_SECTOR_E2.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 hs = GC_GRID.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);
|
||||
float3 root = _GcPlanet.xyz + up * (_GcPlanet.w + ground + 0.01 + GC_GRID.y * 0.012);
|
||||
|
||||
float dist = length(root - _GcCam.xyz);
|
||||
float fade = 1 - smoothstep(_GcFade.x, _GcFade.y, dist);
|
||||
@ -148,6 +171,7 @@ Shader "GrassCutter/GrassFur"
|
||||
o.plane = plane;
|
||||
o.fog = ComputeFogFactor(o.positionCS.z);
|
||||
o.air = float2(GcCloudSun(root, tm), gust);
|
||||
o.sid = sid;
|
||||
return o;
|
||||
}
|
||||
|
||||
@ -161,8 +185,11 @@ Shader "GrassCutter/GrassFur"
|
||||
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
|
||||
#if defined(GC_SECTOR_BUFFER)
|
||||
gcS = _GcSectorBuf[i.sid];
|
||||
#endif
|
||||
float3 d = normalize(i.root - _GcPlanet.xyz);
|
||||
for (int b = 0; b < 6; b++) if (dot(d, _GcBorders[b].xyz) > 0) discard;
|
||||
for (int b = 0; b < 6; b++) if (dot(d, GC_SECTOR_BORDER(b).xyz) > 0) discard;
|
||||
|
||||
float2 mask = GcMask(i.plane);
|
||||
bool solid = t < 0.001; // the bottom of the pile: the floor everything stands on
|
||||
|
||||
Reference in New Issue
Block a user