Skip to content

Migrate hand-rolled effects to useLiveDefaults - #367

Open
kvvasuu wants to merge 1 commit into
pr3/simple-effectsfrom
pr4/hand-rolled-effects
Open

Migrate hand-rolled effects to useLiveDefaults#367
kvvasuu wants to merge 1 commit into
pr3/simple-effectsfrom
pr4/hand-rolled-effects

Conversation

@kvvasuu

@kvvasuu kvvasuu commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fourth PR in the stack (base: pr3/simple-effects).
Migrates the effects that can't use createEffectComponent because their postprocessing class requires real constructor arguments (scene/camera/etc., so new EffectClass() doesn't work with zero arguments) - Outline, SelectiveBloom, ShockWave, GodRays, DepthOfField, SSAO, LUT, N8AO. These stay hand-built with useMemo, but now apply live props through useLiveDefaults instead of reconstructing the whole effect on every change.

This is where nearly every real runtime bug found during review lived - kept as its own PR deliberately, not diluted with PR3's more mechanical changes:

  • SSAO's color, fade, minRadiusScale, and world* proximity/distance thresholds didn't reset to SSAOEffect's real constructor defaults on removal - they were being forwarded to the constructor and tracked live, so the live tracker's "default" snapshot captured whatever was passed on the first render instead of the library's true default.
  • DepthOfField's depthTexture was construction-only (any change reconstructed the whole effect, render targets and passes included) despite DepthOfFieldEffect.setDepthTexture() existing specifically to update an existing instance. Now applied live.
  • GodRays (swapping sun) and N8AO (config/quality changes) mutate their effect directly, outside r3f's reconciler, so nothing was ever calling invalidate() - both now correctly repaint under <Canvas frameloop="demand">.

Outline, SelectiveBloom, ShockWave, GodRays, DepthOfField, SSAO, LUT, and N8AO all need real constructor args (scene/camera/etc.), so they stay hand-built with useMemo, but now apply live props through useLiveDefaults instead of reconstructing on every change.

This is where nearly every real runtime bug from review surfaced: a first-apply bug where a still-correct value's setter fired anyway (Outline's multisampling disposing its render target before first use - the actual reason several of these didn't render at all), SSAO's color/fade/minRadiusScale/world* thresholds not resetting on removal, DepthOfField's depthTexture reconstructing instead of using the live setDepthTexture, and GodRays/N8AO not invalidating on live changes under frameloop="demand".
@kvvasuu
kvvasuu force-pushed the pr4/hand-rolled-effects branch from 89dfefb to 8a776a9 Compare August 5, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant