Skip to content
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

Parent html not respected when using r3f PostProcessing effects #131

Open
ThimoDEV opened this issue May 7, 2023 · 4 comments
Open

Parent html not respected when using r3f PostProcessing effects #131

ThimoDEV opened this issue May 7, 2023 · 4 comments

Comments

@ThimoDEV
Copy link

ThimoDEV commented May 7, 2023

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?

@backuardo
Copy link

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

@ThimoDEV
Copy link
Author

ThimoDEV commented Oct 7, 2023

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?

@backuardo
Copy link

@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} />
}

@szymonhernik
Copy link

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

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

No branches or pull requests

3 participants