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:
NiemandKG
2026-11-09 20:01:02 +06:00
parent 80271aea72
commit 57d0f4d31a
17 changed files with 360 additions and 20 deletions

View File

@ -47,6 +47,15 @@ float4 _GcC, _GcE1, _GcE2;
float4 _GcSalt; // xy = seed, z = flat frame metres to mow map uv
float4 _GcBorders[6];
// a shader that draws many sectors in one go defines these first (GrassFur: GC_SECTOR_BUFFER)
#ifndef GC_SECTOR_C
#define GC_SECTOR_C _GcC
#define GC_SECTOR_E1 _GcE1
#define GC_SECTOR_E2 _GcE2
#define GC_SECTOR_SALT _GcSalt
#define GC_SECTOR_BORDER(k) _GcBorders[k]
#endif
float GcHeight(float3 d)
{
float3 a = abs(d);
@ -82,22 +91,22 @@ void GcTangents(float3 up, out float3 t1, out float3 t2)
// 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;
return SAMPLE_TEXTURE2D_LOD(_GcMaskTex, sampler_GcMaskTex, plane * GC_SECTOR_SALT.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;
return SAMPLE_TEXTURE2D_LOD(_GcMaskTex, sampler_GcMaskTex, plane * GC_SECTOR_SALT.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);
dir = normalize(GC_SECTOR_C.xyz * _GcPlanet.w + GC_SECTOR_E1.xyz * plane.x + GC_SECTOR_E2.xyz * plane.y);
edge = 1e5;
for (int k = 0; k < 6; k++) edge = min(edge, -dot(dir, _GcBorders[k].xyz));
for (int k = 0; k < 6; k++) edge = min(edge, -dot(dir, GC_SECTOR_BORDER(k).xyz));
return edge >= 0;
}