Simple postprocessing in three.js

Luigi De Rosa
1 min readJan 25, 2019

--

Instead of drawing all our scene directly into the screen, we render the whole scene in a texture, and then render this single texture to screen with a new mesh and shaders. That’s what postprocessing means.

There are already multiple examples and implementation in three.js.

Usually those implementation creates a new Scene with a Quad (a full screen plane) and an Orthographic camera and they support multiple passes.

I thought this may be overkill for my projects, so here’s my little light implementation.

Two main differences:

  • Instead of using a Quad with 4 vertices, we’re going to use just 3. It might seems silly that will give us a performance boost, but it really does. Read here and here to find out more.
  • We are not going to use a “camera”, we simply pass the values directly in clip-space coordinates. This will save some matrix multiplication in the vertex shader.
  • We are not using any uvattribute, instead we use gl_FragCoord/resolution

Please note:

  • Make sure to disable antialiasing when creating your WebGL context. Antialias will be performed just on the final framebuffer, so it won’t help us. Implement your own antialiasing in the postprocessing, I suggest you glsl-fxaa

Going further.

I’ve seen some clever techniques that using gl_VertexIDto draw our triangle without any attribute buffer. gl_VertexID is available in OpenGL ES 3.00, thus WebGL2, some links:

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

--

--

Luigi De Rosa
Luigi De Rosa

Responses (1)

Write a response