react-three-next icon indicating copy to clipboard operation
react-three-next copied to clipboard

Parent html not respected when using r3f PostProcessing effects

Open ThimoDEV opened this issue 2 years ago • 4 comments

When I Add postprocessing effects the canvas is positioned absolute. My content is positioned correctly when I give it its own canvas. Is there something specific about the post processing package to use it in a View?

ThimoDEV avatar May 07 '23 14:05 ThimoDEV

I experienced the same issue. For now, I ended up updating the usePostProcess hook (from the starter) to add my effects.

backuardo avatar Oct 06 '23 15:10 backuardo

I experienced the same issue. For now, I ended up updating the usePostProcess hook (from the starter) to add my effects.

Can you share the code here?

ThimoDEV avatar Oct 07 '23 12:10 ThimoDEV

@ThimoDEV I haven't tested this thoroughly, but it seems to be fine (120 FPS on my mac). Probably need to handle window resize and stuff, but this should get you going.

These shaders are from three-stlib

export const usePostProcess = () => {
  const { scene, camera, gl, size } = useThree()
  const composer = useMemo(() => {
    const composer = new EffectComposer(gl)
    composer.setSize(size.width, size.height)

    const renderPass = new RenderPass(scene, camera)
    composer.addPass(renderPass)

    const dotScreenPass = new ShaderPass(DotScreenShader)
    dotScreenPass.uniforms['scale'].value = 3
    composer.addPass(dotScreenPass)

    const rgbShiftPass = new ShaderPass(RGBShiftShader)
    rgbShiftPass.uniforms['amount'].value = 0.005
    composer.addPass(rgbShiftPass)

    return composer
  }, [scene, camera, gl, size])

  useFrame((_, delta) => {
    composer.render(delta)
  }, 2)

  return null
}

and the usage is just calling this hook in a component:

export const Dog: React.FC<PrimitiveProps> = (props) => {
  const ref = useRef(null!)
  const { scene } = useGLTF('/dog.glb')

  usePostProcess()

  useFrame((state, delta) => {
    ref.current.rotation.y += 1 * delta
  })

  return <primitive ref={ref} object={scene} {...props} />
}

backuardo avatar Oct 07 '23 12:10 backuardo

Any updates in the codebase in relation to this bug? i can't mount effectcomposer.

szymonhernik avatar Dec 06 '23 17:12 szymonhernik