Energy Conservation In Shaders
By Neil Blevins
Created On: Aug 21st 2013

So when someone says a shader uses "Energy Conservation", what do they mean? The law of conservation of energy states that energy may neither be created nor destroyed. Therefore the sum of all the energies in the system is a constant. This is how real materials and lights work, so if you want your objects to look photorealistic, you need to have your shaders follow the law of Energy Conservation.

As stated in Siggraph 96 course notes book #30 Pixel Cinematography: A lighting approach for Computer Graphics...

"When light hits an object, the energy is reflected as one of two components; the specular component (the shiny highlight) and the diffuse (the color of the object). The relationship of these two components is what defines what kind of material the object is. These two kinds of energy make up the 100% of light reflected off an object. If 95% of it is diffuse energy, then the remaining 5% is specular energy. When the specularity increases, the diffuse component drops, and vice versa. A ping pong ball is considered to be a very diffuse object, with very little specularity and lots of diffuse, and a mirror is thought of as having a very high specularity, and almost no diffuse."

In the real world, light shoots from your light source as energy, hits your object, some of that energy is absorbed into your object (depending on its color) and the rest bounces off the object into your scene.

Lets assume in the diagram above that 100% of the light hitting the object bounces off (no absorption). So if the energy from your light source has a value of 1, and the Diffuse Reflection is 0.75, then your Specular Reflectivity (sometimes just called Reflectivity) should be set to 0.25. Even if your object does absorb some of the light (ie, it has a color to it), whatever amount of light that does bounce off into the eye needs to retain that diffuse / specular relationship, where the more diffuse, the less specular, and vice versa.

Many shaders that ship with the major renderers and 3d packages automatically perform Energy Conservation. If it does, then this relationship is automatically calculated for you. So if you increase the amount of reflectivity the shader has, it will automatically reduce the diffuse amount.

Here's an example...

These two spheres are very, very reflective (specular reflection), ie, they should be close to a perfect mirror of their environment. Knowing this, you'd expect the reflection in the mirror of a black object (the background) to be black, like it is on the sphere on the right, whereas the sphere on the left is still blue. So the sphere on the right follows the laws of energy conservation, and the one on the left does not (it's actually just adding the reflection on top of the diffuse, instead of dimming the diffuse to compensate). You can set up a scene like this if you want to find out if your shader automatically follows the laws of energy conservation or not.

If your shader does not automatically follow the laws of energy conservation, then you can achieve the same look by hand. So if you increase the reflectivity of the shader, make sure to reduce the brightness of your diffuse by the opposite amount, and the law will be upheld.

This site is ©2023 by Neil Blevins, All rights are reserved. Twitter Mastodon Bluesky Instagram Blogger Facebook LinkedIn ArtStation Kickstarter Gumroad YouTube IMDB