React-Three-Fiber custom PostProcessing render target solution (Without using the EffectComposer)

Napoleon Services
1 min readSep 7, 2021

Do you want to use a simple fragment shader to spice up your scene without loosing a lot of performance? Or simply want to avoid big imports that you just don’t understand on what they actually do?

Well I got news.

First, save this PostFX file in the src/ folder:

(Shoutout to Luigi for that code)

Keep in mind that this works well, but it isn’t react hooks yet. If someone wants to convert it to react hooks, I’m happy to help :)

Then we have to decouple the renderer from React and pipe the scene and camera through PostFX. We are doing this with a component:

function Effect() {  const { gl, scene, camera, size } = useThree()  const renderer = new PostFX(gl)  return useFrame((state) => {    renderer.render(scene, camera)  }, 1)}

After that, simply put the Component inside your Canvas.

<Canvas>  <Effect />

Final result:

Now you can simply push some mousemovement values or time values to the PostFX component.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Responses (1)

Write a response

It works great but it is possible to change with useFrame the uniforms of the shader? I tried but it didn't work, the <Effect /> object loads only once and doesn't seem to evolve after that.Did you try or it is actually the benefit of this method to be static but light... ?