Use the Effects abstraction for post-processing
masterThe Effects component provides an abstraction around Three.js's EffectComposer. It simplifies the management of post-processing passes by automatically handling the attachment of children to the composer.
Key Behaviors
- Automatic Setup: By default, it prepends a
render-passand agammacorrection-passto the effect chain. - Automatic Attachment: Children of the
<Effects />component are automatically cloned and have theattachproperty applied to them. - Usage Restriction: Only
passesoreffectsshould be used as children within the<Effects />component. - Render Target: By default, it creates a render target using
HalfFloatTypeandRGBAFormat, though these can be customized via props.
import { SSAOPass } from "three-stdlib"
import { extend, useThree } from "@react-three/fiber"
import { Effects } from "@react-three/drei"
// Register the pass so it can be used as a JSX element
extend({ SSAOPass })
function Scene() {
const { scene, camera } = useThree()
return (
<Effects multisamping={8} renderIndex={1} disableGamma={false} disableRenderPass={false} disableRender={false}>
<SSAOPass args={[scene, camera, 100, 100]} kernelRadius={1.2} kernelSize={0} />
</Effects>
)
}