-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React-three-fiber integration #5
Comments
+1 ! I would love to see this work in react-tree-fiber :) |
Yes, there seems to be an issue when trying to use the effects in r3f, https://twitter.com/0beqz/status/1634313769357656064?t=FKjfhzkQdV8B99LwDcrSsQ&s=19. I'll debug them when I have time to see what exactly causes the artifacts. |
Although somewhat limited still, it should work now in r3f. Not all materials are supported yet (e.g. ShadowCatchers). I'll keep working on it but it should be supported now. |
@klavinski import { extend, ReactThreeFiber, useFrame, useThree } from '@react-three/fiber'
//@ts-ignore
import { SSGIEffect, HBAOEffect, MotionBlurEffect, VelocityDepthNormalPass } from 'realism-effects'
import {
// Fixes type shadowing between "postprocessing" and "three"
EffectComposer as PostEffectsComposer,
EffectPass as PostEffectPass,
RenderPass as PostRenderPass,
} from 'postprocessing'
import { useEffect, useRef } from 'react'
extend({
PostRenderPass,
PostEffectPass,
SSGIEffect,
VelocityDepthNormalPass,
PostEffectsComposer,
})
declare module '@react-three/fiber' {
interface ThreeElements {
velocityDepthNormalPass: ReactThreeFiber.Node<VelocityDepthNormalPass, typeof VelocityDepthNormalPass>
sSGIEffect: ReactThreeFiber.Node<SSGIEffect, typeof SSGIEffect>
postEffectsComposer: ReactThreeFiber.Node<PostEffectsComposer, typeof PostEffectsComposer>
postRenderPass: ReactThreeFiber.Node<PostRenderPass, typeof PostRenderPass>
postEffectPass: ReactThreeFiber.Node<PostEffectPass, typeof PostEffectPass>
}
}
export function PostEffectComposer() {
const { camera, scene, size } = useThree()
const composerRef = useRef<PostEffectsComposer>(null!)
const velocityDepthNormalPassRef = useRef(null!)
useEffect(() => {
if (composerRef.current) {
composerRef.current.setSize(size.width, size.height)
}
}, [composerRef.current, size])
// This kills the automatic rendering. Don't forget to add a call to gl.render somewhere else.
useFrame((_, delta) => {
composerRef.current && composerRef.current.render(delta)
}, 2)
const gl = useThree(({ gl }) => gl)
return (
<postEffectsComposer ref={composerRef} args={[gl]}>
<postRenderPass args={[scene, camera]} attach={(parent, self) => parent.addPass(self)} />
<velocityDepthNormalPass
ref={velocityDepthNormalPassRef}
args={[scene, camera]}
attach={(parent, self) => parent.addPass(self)}
/>
{velocityDepthNormalPassRef.current && (
<postEffectPass
args={[camera, new SSGIEffect(scene, camera, velocityDepthNormalPassRef.current)]}
attach={(parent, self) => parent.addPass(self)}
/>
)}
{velocityDepthNormalPassRef.current && composerRef.current && (
<postEffectPass
args={[
camera,
new HBAOEffect(composerRef.current, camera, scene),
new MotionBlurEffect(velocityDepthNormalPassRef.current),
]}
attach={(parent, self) => parent.addPass(self)}
/>
)}
</postEffectsComposer>
)
} Add somewhere else: useFrame(({ scene, camera , gl}) => {
gl.render(scene, camera)
}, 1) I hope this helps! |
Thx, yeah I'm planning to add codesandboxes for SSGI + R3F after releasing the new version. |
Hiiii,good.job!!!! have you find a solution for R3F integration? |
In my case, it was actually quite simple. This is how I use it on my blog: import { EffectComposer, EffectComposerContext, SMAA } from "@react-three/postprocessing"
// In your R3F Canvas
<Canvas>
...
<EffectComposer>
<RealismEffects/>
<SMAA/> // Or any other effect you would like to add
</EffectComposer>
</Canvas>
// How <RealismEffects/> is made
const RealismEffects = () => {
const { scene, camera, composer } = useContext( EffectComposerContext )
const velocityDepthNormalPass = useMemo( () => new VelocityDepthNormalPass( scene, camera ), [ scene, camera ] )
useLayoutEffect( () => {
composer.addPass( velocityDepthNormalPass )
return () => {
composer.removePass( velocityDepthNormalPass )
}
}, [ velocityDepthNormalPass, composer ] )
const ssgiEffect = useMemo( () => new SSGIEffect( scene, camera, velocityDepthNormalPass ), [ scene, camera, velocityDepthNormalPass ] )
return <primitive object={ ssgiEffect }/>
} |
The probleme is we cant see our rectangulaire light.... |
Is there a recommended way to integrate the SSGI with
@react-three/fiber
? I tried adapting your code like this, but it did not work:The text was updated successfully, but these errors were encountered: