1-Bit Post-Processing Shader in Three.js

A GLSL post-processing shader that renders an otherwise full-color 3D scene in only two colors.

by Chad Hillary

This project was inspired by trying to replicate techniques used in Lucas Pope's "Return of the Obra Dinn". This post-processing fragment shader works by first converting each fragment's RGB value to a matching 32-bit grayscale value, then comparing it to a threshold value dictated by the fragment's position in relation to a repeating eight by eight Bayer matrix. If the color's grayscale value is higher than the threshold, it will be replaced by color 1, otherwise, it will be replaced by color 0.

The demo also uses shader code, and modifies the MeshLambertMaterial code from three.js source to determine the color of object edges, based on wheather the fragment lies in a shadow or not, to make the objects pop out.

Click here for Source Code (Github)

See the screenshots below:


Resources Used;
Skeleton code for First-Person controls modified from: https://threejs.org/examples/misc_controls_pointerlock.html
Three js Effect Composer (Post-Processing) Library; https://github.com/mrdoob/three.js/tree/dev/examples/js/postprocessing
“Standard Male Figure” (figure.json) Model provided by Clara.io user “Ben Houston”; https://clara.io/view/d49ee603-8e6c-4720-bd20-9e3d7b13978a
Floor Texture (floor.jpg) by FreePik user “yingyang” @ https://www.freepik.com/free-photos-vectors/wood-texture
“Color FAQ” by Charles Ponyton – Article about how accurate luminance, gamma, color, etc. conversions are calculated in computer graphics, used to find the RGB weights for my grayscaling method; http://poynton.ca/notes/colour_and_gamma/ColorFAQ.html#RTFToC9
Matrix coefficients and information used in dithering found from; https://en.wikipedia.org/wiki/Ordered_dithering
Original forum post (Inspiration) by Lucas Pope, briefly explaining how his 1-bit was achieved in Unity, and his efforts to make the dither respond more smoothly to movement https://forums.tigsource.com/index.php?topic=40832.msg1363742#msg1363742