Sepia sprite shader

Shan Shui sea, mountain and boat sprite with and without a sepia effect applied

This tutorial shows you how to apply a sepia effect to a sprite using a shader. The code is written in the GLSL programming language.

What is Sepia?

“Sepia is a reddish-brown color, named after the rich brown pigment derived from the ink sac of the common cuttlefish Sepia.”

Sepia (color) – Wikipedia

Sprites

Original sprite

Shan Shui mountain, sea and boat sprite

Sepia sprite

Shan Shui mountain, sea and boat sprite with sepia colour applied

Full GLSL shader code

Explanation

We first get the pixel colour and convert the pixel colour to greyscale using the GREY_WEIGHTS.

More information on the greyscale algorithm here:

Greyscale sprite shader – Agate DRAGON

We then add the SEPIA_WEIGHTS to the greyscale colour, to get the sepia colour.

The SEPIA_WEIGHTS are calculated from the RGB value taken from the sepia Wikipedia page, and converted into the 0 to 1 range by dividing by 255.

Finally we just need to mix the original pixel colour with the sepia colour, using the intensity value to control the strength of the effect.

Shan shui mountain and sea sepia sprite
Shan shui mountain and sea sepia sprite

Thank you for reading this tutorial, I hope you found it useful!

Leave a comment

Blog at WordPress.com.