perf: release GPU resources correctly and reuse render targets
Dispose scene resources before renderer allocation records are cleared and release the bloom high-pass material. Avoid unused bloom depth buffers and the final screen pass swap, keeping the same visual output and quality. Batch sign-stage layout reads before applying existing masks. Validated approved assets, types, client and SSR builds, prerendered content, artifacts and transfer budgets. Checked 32 matching transition renders, 66 browser interactions and repeated quality-change resource cleanup.
This commit is contained in:
@@ -43,6 +43,7 @@ interface BloomPassLike {
|
||||
strength: number;
|
||||
radius: number;
|
||||
threshold: number;
|
||||
materialHighPassFilter?: { dispose(): void };
|
||||
renderTargetBright?: RenderTargetLike;
|
||||
renderTargetsHorizontal?: readonly RenderTargetLike[];
|
||||
renderTargetsVertical?: readonly RenderTargetLike[];
|
||||
@@ -63,9 +64,27 @@ export interface PostProcessingFactories {
|
||||
const productionFactories: PostProcessingFactories = {
|
||||
createComposer: (renderer) => new EffectComposer(renderer),
|
||||
createRenderPass: (scene, camera) => new RenderPass(scene, camera),
|
||||
createBloomPass: () =>
|
||||
new UnrealBloomPass(new THREE.Vector2(1, 1), 0.3, 0.38, 1.05),
|
||||
createOutputPass: () => new OutputPass(),
|
||||
createBloomPass: () => {
|
||||
const bloom = new UnrealBloomPass(new THREE.Vector2(1, 1), 0.3, 0.38, 1.05);
|
||||
// These fullscreen passes overwrite every color pixel. No pass samples
|
||||
// their depth, and scene depth lives in the composer's separate targets.
|
||||
for (const target of [
|
||||
bloom.renderTargetBright,
|
||||
...bloom.renderTargetsHorizontal,
|
||||
...bloom.renderTargetsVertical,
|
||||
]) {
|
||||
target.depthBuffer = false;
|
||||
}
|
||||
return bloom;
|
||||
},
|
||||
createOutputPass: () => {
|
||||
const output = new OutputPass();
|
||||
// Output is always the last pass and renders directly to the canvas.
|
||||
// Neither RenderPass nor bloom swaps buffers, so swapping here would only
|
||||
// alternate the scene between two identical full-resolution GPU targets.
|
||||
output.needsSwap = false;
|
||||
return output;
|
||||
},
|
||||
};
|
||||
|
||||
export function createPostProcessor(
|
||||
@@ -114,6 +133,8 @@ export function createPostProcessor(
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
renderPass.dispose();
|
||||
// Three r185 omits this material from UnrealBloomPass.dispose().
|
||||
bloomPass.materialHighPassFilter?.dispose();
|
||||
bloomPass.dispose();
|
||||
outputPass.dispose();
|
||||
composer.dispose();
|
||||
|
||||
Reference in New Issue
Block a user