Film Grain

This is part of the WebGL image processing series and it relies on information in previous articles. See all articles here.

It is designed to be used on desktop.

What is film grain?

Film grain is an optical effect created from the presence of small particles of metallic silver or dye clouds found in the liquid when developing film stock.

We can simulate this effect in GLSL by generating noise, then blending this into our RGB values.

Let's first take a look at how we can use a hash function to generate random noise (though generating truly random noise in WebGL is broadly considered impossible).

Loading code...

Now that we have our grain, we can mix this with our image.

Loading code...

This has added some texture to the image, but it looks more like digital noise than the grain from film processing.

Creating more realistic film grain

Researching this further led me to Matt DesLauriers' glsl-film-grain package, based on an article by Martins Upitis. It uses a mixture of perlin and simplex noise for the grain, along with a blend mode that adapts the amount of noise added to each pixel depending on its luminosity.

Luckily, this package is under the MIT license so let's take a closer look. It uses the pnoise3 and snoise3 from glsl-noise.

Loading code...

This generates a more textured noise pattern, and we can increase the grain size with this dial.

Using this algorithm on our photos from before with an increased grain size, gives us a more natural film grain look. But we still run into issues when we increase the mix, since it takes over the image. Worse still, this is different for different images - so we'd have to set an amount for each image manually.

Instead of using the GLSL mix function we can use a blend-soft-light function (this is the blend mode mentioned above) with the texel luminance. The below code is from the blending tips section on the glsl-film-grain repo.

Loading code...

In the next article of the series we'll look at using a gradient map to convert our image into a duotone image.