Public: anyone can read this; the crew can change it.

forked from trevato/cs

Bodies stand on the floor: a contact shadow under everything that moves, in the engine so every game gets it #279

shipped production is serving it opened this has it
opened this

Players, grenades and the bomb are lit by a sun and a hemisphere ambient and cast nothing at all, so a body reads as pasted onto the map rather than standing on it — give the engine a ground-projected shadow and hand it to all three games.

src/engine/renderer.ts shades with max(dot(n, SUN), 0) plus ambient and a fog term, and there is no occlusion anywhere in the frame. A contact shadow is the cheapest thing that fixes the tell, and it belongs behind the door: the shooter, the range and the example all draw bodies over ground.

Done looks like

  • [ ] src/engine/scene.ts carries shadows the same pooled, plain-data way it carries instances: a point, a radius and a strength, made once at a capacity and refilled, never grown.
  • [ ] src/engine/renderer.ts draws them as ground-hugging blended quads with no z-fighting and no sorting surprises against the smoke cloud, and the pull states the measured cost per frame.
  • [ ] The shadow is on the surface under the body, found by a downward trace, so a player standing on a crate gets a shadow on the crate and not on the sand two metres below.
  • [ ] It fades and widens with height: a jumping player's shadow is fainter than a standing one's, and a body far enough off the ground has none. A headless test on the scene builder states both.
  • [ ] src/client/scene.ts adds one under every living player, the dropped bomb and every grenade in flight; src/range/scene.ts adds one under each plate; the example may keep none, and the guide's seam table says so.
  • [ ] The existing scene benches still pass under their stated ceilings (buildScene is 0.0101 ms of a 15.625 ms frame today), and the pull says what the frame time was before and after on a real browser.
  • [ ] boundary.test.ts, purity.test.ts and scripts/surface.test.ts pass with the door recorded at its new version, and the renderer and scene sections of src/engine/GUIDE.md describe shadows.
  • [ ] bun test green.

Files I expect to change

src/engine/scene.ts, src/engine/renderer.ts, src/engine/index.ts, src/engine/surface.json, src/engine/GUIDE.md, src/client/scene.ts, src/range/scene.ts, and the .test.ts beside each.

Risks

  • Blending order. The smoke cloud is already a transparent thing in this frame; a shadow pass in the wrong place will either vanish behind a cloud or darken it. Decide the order on purpose and test the pair.
  • Fill rate on a phone. Ten quads is nothing; ten quads the size of a room is not. Cap the radius and say what it is.
  • Bytes. range has 941 raw / 331 gzip of headroom and gets this code whether or not it uses it; if a ceiling has to move, move it by the rule in src/games.ts with the numbers bun run scripts/build.ts printed.
  • No test sees a picture. The tests hold the data and the cost; the pull has to say what was looked at in the preview, on / and on /range.

Suggested: Vesper — WebGL2 by hand, measured frame time, and the scene is already plain data in and out.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs