Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/intelstream/hands/static/assets/hands.js

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions web/hands/src/render/renderer-gpu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,32 @@ describe("quality tiers on the graphics card", () => {
expect(gl.created.programs).toBe(programs);
expect(key.castShadow).toBe(true);
expect(key.shadow.intensity).toBe(0);
// The shadow map is no longer drawn, and its depth target is freed.
expect(key.shadow.map).toBeNull();
// The shadow map is no longer drawn, and its depth target is freed. Every lit shader still samples a shadow
// map, so a tiny one, drawn once, stays in its place: with none the graphics card refuses to draw anything lit.
expect(gl.alive(depth)).toBe(false);
const kept = key.shadow.map;
expect(kept?.width).toBe(16);
expect(gl.alive(glTexture(internals.renderer, kept?.depthTexture))).toBe(true);
// The comparison is what the graphics card checks the shadow sampler's texture for.
expect(kept?.depthTexture?.compareFunction).toBe(THREE.LessEqualCompare);
expect(key.shadow.autoUpdate).toBe(false);
expect(key.shadow.needsUpdate).toBe(false);
fight.labFrame(time + 0.15);
expect(key.shadow.map).toBe(kept);
setScale(0.7);
fight.labFrame(time + 0.2);
expect(gl.created.programs).toBe(programs);
expect(key.shadow.intensity).toBe(1);
expect(key.shadow.map).not.toBeNull();
expect(key.shadow.map?.width).toBe(1024);
// Down and up again, as a struggling client goes: a map with a live depth target is there after every frame.
for (const [step, scale] of [0.55, 1, 0.55, 0.85].entries()) {
setScale(scale);
fight.labFrame(time + 0.3 + step / 10);
expect(key.shadow.map?.width).toBe(scale === 0.55 ? 16 : 2048);
expect(gl.alive(glTexture(internals.renderer, key.shadow.map?.depthTexture))).toBe(true);
}
expect(gl.created.programs).toBe(programs);
});
});

Expand Down
13 changes: 10 additions & 3 deletions web/hands/src/render/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,27 @@ export function compileForComposer(
const KEY_SHADOW_BIAS = -0.0004;
/** Past the shadow camera's far plane, so every lit pixel skips the shadow lookups. */
const SKIPPED_SHADOW_BIAS = 10;
/** The side of the shadow map kept while the shadow is off. */
const SKIPPED_SHADOW_SIZE = 16;

/**
* Sets the key light's shadow for a quality tier without touching castShadow, which is part of every
* material's program key: flipping it would recompile every shader in one frame on the slowest
* devices. Turned off, the shadow stops being drawn, its depth target is freed, and it is hidden.
* devices. Turned off, the shadow stops being drawn and is hidden, and its depth target is swapped for a
* tiny one drawn once. It is never left without one: every lit shader still samples it, and with no map
* three binds a stand-in that is no comparison texture, which the graphics card refuses, so nothing lit is drawn.
*/
export function setKeyShadowTier(shadow: THREE.LightShadow, off: boolean, size: number): void {
const side = off ? SKIPPED_SHADOW_SIZE : size;
shadow.autoUpdate = !off;
shadow.intensity = off ? 0 : 1;
shadow.bias = off ? SKIPPED_SHADOW_BIAS : KEY_SHADOW_BIAS;
if ((off && shadow.map !== null) || shadow.mapSize.x !== size) {
shadow.mapSize.set(size, size);
if (shadow.mapSize.x !== side) {
shadow.mapSize.set(side, side);
shadow.map?.dispose();
shadow.map = null;
// The next frame draws the map at its new size, whether or not it goes on being drawn after that.
shadow.needsUpdate = true;
}
}

Expand Down
Loading