postprocessing-optimization — Claude Code rule: setup and usage
postprocessing-optimization is a rule for Three.js and React Three Fiber that helps optimize post-processing by combining shader passes and tuning render settings.
MIT ★ 4,719 updated 2026-10-24
.claude/rules/postprocessing-optimization.mdWhat postprocessing-optimization does
The rule establishes standards for real-time graphics pipelines. It guides agents to switch from the default Three.js composer to pmndrs/postprocessing, turn off hardware multisampling when not needed, and disable stencil and depth buffers directly on WebGLRenderer.
It enforces batching compatible post-processing stages into a single EffectPass rather than chaining multiple passes. Final stages receive tone mapping and anti-aliasing like SMAAEffect or FXAA, while heavy glows switch to SelectiveBloomEffect. Native TSL node passes handle WebGPU projects.
Keeping antialias: true on WebGLRenderer wastes GPU cycles when a post-processing anti-aliasing pass already runs at the end.
What it helps with
- bundle multiple post-processing effects into a single
EffectPass - disable redundant depth and stencil buffers in
WebGLRenderer - restrict bloom to chosen objects using
SelectiveBloomEffect - configure native TSL post-processing for WebGPU
Example prompts for the agent
- Review my Three.js post-processing pipeline and merge compatible passes
- Set up selective bloom for the highlighted mesh and place SMAA at the end
- Configure WebGLRenderer settings and disable unneeded multisampling
How to install postprocessing-optimization
Manually: put the files in place
.claude/rules/postprocessing-optimization.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/postprocessing-optimization.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/postprocessing-optimization.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/postprocessing-optimization.mdManually: put the files in place
.clinerules/postprocessing-optimization.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about postprocessing-optimization
How do I install postprocessing-optimization in Claude Code?
Save the rule file to .claude/rules/postprocessing-optimization.md.
What does postprocessing-optimization do?
It directs the coding agent to apply proven performance tweaks for Three.js effects passes, renderer flags, and WebGPU TSL setups.
Why does the rule advise against Three.js default EffectComposer?
It recommends pmndrs/postprocessing because that library combines compatible shaders into fewer draw calls.
Source text
postprocessing-optimization.md · MIT
# Post-Processing Optimization
> Source: [100 Three.js Tips - Utsubo](https://www.utsubo.com/blog/threejs-best-practices-100-tips)
Post-processing can significantly impact performance. Optimize carefully.
## Use pmndrs/postprocessing (WebGL)
The pmndrs library is more performant than Three.js default EffectComposer:
```javascript
import { EffectComposer, Bloom, Vignette, EffectPass, RenderPass } from 'postprocessing';
const composer = new EffectComposer(renderer);
composer.addPass(new RenderPass(scene, camera));
composer.addPass(new EffectPass(camera, new Bloom(), new Vignette()));
// In render loop
composer.render();
```
## Configure Renderer for Post-Processing
```javascript
const renderer = new THREE.WebGLRenderer({
powerPreference: 'high-performance',
antialias: false, // AA handled by post-processing
stencil: false, // Disable if not needed
depth: false // Disable if not needed
});
```
## Disable Multisampling When Not Needed
```jsx
// React Three Fiber
<EffectComposer multisampling={0}>
<Bloom />
</EffectComposer>
```
## Apply Tone Mapping at Pipeline End
```javascript
renderer.toneMapping = THREE.NoToneMapping;
// Add ToneMappingEffect as the LAST effect
composer.addPass(new EffectPass(camera, new ToneMappingEffect()));
```
## Add Antialiasing at the End
```javascript
import { SMAAEffect } from 'postprocessing';
// SMAA as the final pass
composer.addPass(new EffectPass(camera, new SMAAEffect()));
```
## Merge Compatible Effects
Reduce passes by combining effects:
```javascript
// BAD: Multiple passes
composer.addPass(new EffectPass(camera, new Bloom()));
composer.addPass(new EffectPass(camera, new Vignette()));
composer.addPass(new EffectPass(camera, new ChromaticAberration()));
// GOOD: Single pass with multiple effects
composer.addPass(new EffectPass(
camera,
new Bloom(),
new Vignette(),
new ChromaticAberration()
));
```
## Resolution Scaling
Half resolution can double frame rate:
```javascript
// Render at half resolution
composer.setSize(window.innerWidth / 2, window.innerHeight / 2);
```
## Selective Bloom
Only bloom objects that need it:
```javascript
import { SelectiveBloomEffect } from 'postprocessing';
const bloom = new SelectiveBloomEffect(scene, camera, {
luminanceThreshold: 0.9,
luminanceSmoothing: 0.3
});
// Add objects to bloom selection
bloom.selection.add(glowingObject);
```
## Bloom Parameter Tuning
| Parameter | Range | Description |
|-----------|-------|-------------|
| intensity | 0.5-2.0 | Overall strength |
| luminanceThreshold | 0.8-1.0 | Minimum brightness to bloom |
| radius | 0.5-1.0 | Spread size |
## WebGPU Native Post-Processing
For WebGPU, use Three.js native TSL-based post-processing:
```javascript
import { pass, bloom, fxaa } from 'three/tsl';
const postProcessing = new THREE.PostProcessing(renderer);
const scenePass = pass(scene, camera);
postProcessing.outputNode = scenePass
.pipe(bloom({ threshold: 0.8, intensity: 1.0 }))
.pipe(fxaa());
// In render loop
postProcessing.render();
```
## Performance Checklist
- [ ] Use pmndrs/postprocessing for WebGL
- [ ] Disable renderer AA, stencil, depth when using post-processing
- [ ] Merge compatible effects into single pass
- [ ] Add AA (SMAA/FXAA) as final effect
- [ ] Apply tone mapping at end
- [ ] Consider resolution scaling for mobile
- [ ] Use selective bloom instead of full-screen
- [ ] Disable multisampling when not needed
- [ ] Use TSL post-processing for WebGPU
© zebbern · MIT · zebbern/claude-code-guide