This is the first tech post by our new technical artist Lukas Orsvärn! To familiarize himself with the engine he has been experimenting with physically-based rendering shaders. We know this is not the highest priority task for completing Overgrowth, but with our expanded team, we are still making a lot of progress on gameplay programming and level design, and want to get back into writing some tech posts for you all.

What is PBR?

Physically-based rendering (PBR) has become increasingly popular over the past few years. Unity 5, Unreal Engine 4, Frostbite, Fox Engine, and many more game engines use it, as well as an increasing number of asset-authoring tools like Marmoset Toolbag.

The image below is a comparison between the current rendering in Overgrowth and physically based rendering. PBR allows us to tint the reflection of the gold bands and blade inlay to make them look more like gold, and allows us to sharpen the reflection on the blade to make it read better as polished metal.

PBR relies not on our intuition of what looks right, but on research and what is right. This means applying what we know about the real physical interactions between light and materials to real-time graphics. Keep in mind that no real-time applications can achieve fully "correct" rendering, only get as close as possible based on their performance targets and available development time.

Components of PBR

Here is an outline of the most important parts of PBR.

Specular and diffuse reflection

Diffuse reflection refers to the light that enters a surface, bounces around, and then emerges again in a random direction. Some wavelengths of the incoming light are absorbed in this process, resulting in the perceived color of a surface. A common example of a very diffuse material is a ping pong ball. Specular light refers to light that reflects immediately off the surface in a single bounce, resulting in a reflection of the environment that can be more or less blurry based on the roughness of the surface.

Energy conservation

No surface can reflect more light than it receives. This means that if a surface is 100% specular, then it can have no diffuse reflection, and vice versa. We need to be careful to make sure that the specular and diffuse reflections never add up to more than 100%, because that situation is not physically possible.

The Fresnel effect

The balance between diffuse and specular reflections changes based on the angle at which you view the surface. For example, if you look out across a lake, you will mostly see the specular reflection of the opposite shore and the sky. However, if you look straight down at the lake from above, you will mostly see the diffuse reflection from the dirt and algae inside the lake. This effect is governed by the Fresnel equations, and is often referred to as the Fresnel effect (pronounced fruh-nell).

You can test this with almost any surface by first looking straight at it: you might see your reflection to some extent if it has a high specular component with low roughness, or you might just see the color of the surface from the diffuse reflection. Now look along the surface from the side. It is going to look more and more reflective the greater the angle between your view and the direction of the surface. Try it with your phone screen! In the real world, all materials approach a 100% specular component when viewed exactly from the side.

Here are two photos of cords on a table to demonstrate the Fresnel effect in real life. First, you can see how the black cords are highlighted along the edges because of the increasing angle between the view and the surface. Second, you can see how in the second picture, which is taken from a lower angle, there is more of a reflection of the cords in the table.

Metals are different

Most materials that are not metals reflect about 4% of incoming light as specular reflection (when viewed straight on) and the rest as diffuse reflection. This varies by only a few percent from material to material, and can never reach 0% specular. However metals almost only produce specular reflection and have almost no diffuse reflection. They also tint the reflected light differently depending on the metal: this is how we can tell the difference between gold or copper or bronze, the specular light is tinted differently.

PBR in practice

There are many guidelines when it comes to texturing for PBR that should be followed to achieve the best results; you can find information about those at the end of this blog post. What it means to work with PBR is going to vary from project to project, but in the most commonly used model — the metallic-roughness model — the following data is needed:

Color , this is used as a simple diffuse color if the metallic component is 0% (black), and is used as the tint of the reflected light as the metallic component approaches 100% (white). Every metal in the real world has a measured value that can be used in PBR to closely approximate the look of that metal. This allows artists to simply work from a palette of real-world measurements for most materials, without having to worry about whether their 'gold' is going to actually look like gold or not under all lighting conditions.

, this is used as a simple diffuse color if the metallic component is 0% (black), and is used as the tint of the reflected light as the metallic component approaches 100% (white). Every metal in the real world has a measured value that can be used in PBR to closely approximate the look of that metal. This allows artists to simply work from a palette of real-world measurements for most materials, without having to worry about whether their 'gold' is going to actually look like gold or not under all lighting conditions. Roughness , this makes highlights wider and reflections blurrier the higher it is. A ball bearing might have a very low roughness value, while a fogged-up mirror will have a higher one.

, this makes highlights wider and reflections blurrier the higher it is. A ball bearing might have a very low roughness value, while a fogged-up mirror will have a higher one. Metallic, if this is 100% the surface will behave more like a metal by turning down diffuse reflection to 0%, turning up the specular reflection light to 100% and applying the color channel to the specular instead of the diffuse reflection.

PBR is not going to be the right choice in every case: if a game does not try to mimic how light behaves in real world, then these concepts of how the real world works might not be useful. However games that aim for realistic lighting can greatly benefit from physically-based rendering. Using PBR can..

Give more predictable results under different lighting conditions.

Give more realistic and unified results since everything is based on the real world.

Make it easier for artists to produce content since there is less guesswork involved.

Further reading

If you would like to learn more about the wonderful world of PBR, I would recommend checking out The comprehensive PBR guide by Allegorithmic as well as the PBR theory, practice and texture conversion tutorials by Marmoset. If you want to get more into the math behind PBR, check out the course notes links on this post of the Self Shadow blog.