Blog

CG educational blog focused on look development.

Beginner's Guide To Shading ( Foundations )

Light Behaviour ·  Shaders · Reflection (Diffuse and Specular) · Refraction (Dispersion and Subsurface Scattering)

Hello guys and welcome to the first post on this blog in which I am going to talk about the basics of shading!  Today I will focus on light theory, which can be successfully applied in VFX, Games, Arch-Viz and pretty much every area of CG! 

Disclaimer: This is going to be a relatively long read so prepare yourself some coffee, sit comfortably and enjoy this post filled with geeky stuff about light rays, shader components and some physically based rendering theory. The content you're going to read will present my understanding of the subject and is based on my own experience and different resources (some of them available at the bottom of the page). Do not hesitate to add some corrections/suggestions if you feel the need to do it!

Without any further ado let's get to the fun part:

Let's begin with the way light interacts with the objects around us. It is important to understand this concept because whenever we create a material, we need to think about the influence of light over it. In consequence, we have to know how to work with the parameters offered by our shaders and understand how to balance them accordingly rather than just guessing.

Light Behaviour:

In nature, every object that we see reflects light. While the light physics is a complicated subject, as artists, we still need to understand some basics: 

A ray that hits a surface (called also incidence ray) is reflected at the same angle as the incidence angle (the angle between the normal on the surface and the incident ray). The reflected ray will never carry more energy (be brighter) than the incident ray. This rule is called energy conservation and is very important for achieving photorealism.

When a light ray goes through a homogeneous surface, it keeps a similar trajectory. When it goes through a non-homogeneous surface, the light ray will be scattered through, absorbed or a combination of these two.

As a result, different materials will produce different effects:

  • Clear water will not absorb the light and the scattering will be low, so the direction of the light will be similar with the initial direction (and I say similar because the light ray will be affected by refraction, which we will discuss a bit later). If the water is dirty, then the light rays will hit the dust particles,  get absorbed and change their initial trajectory. 
  • When we look at materials such as caramel, paint or skin, we can observe how their colour looks brighter on the thinner parts. It comes from the fact that part of the light is absorbed based on the thickness of the object that it goes through: the more it travels, the less intense it becomes.

In conclusion, whenever a light ray hits an object, a few things can happen to that ray: it is reflected, refracted, absorbed, scatters through.

These are some basic rules, but simply understanding them will give us a better idea about our targets when creating materials in CG!

Shaders:

In order to recreate the look of our materials, we use shaders. Without going in deep details, shaders are little programs that offer us with a set of controls which can modify the material behaviour when interacting with the light. These controls are available in most of the shaders provided by different renderers. While they may have different names, it should be quite easy for you to identify them after you understand their behaviour!

Now let's move on to the reflections! 

There are two main types of reflection: diffuse and specular. I could not find a clear border between them, where specular reflection becomes diffuse, but it looks like there are a few aspects people use to differentiate them.

Diffuse Reflection:

The diffuse, sometimes referred as Lambertian reflection is the type of reflection in which the incident light is scattered equally (or almost equally, depending on the shading model used) in all directions. In consequence, the surface that creates this type of reflection is not as smooth as you may think. In reality, if you would be able to zoom in a lot to that surface, you would see multiple facets that send the light rays in different directions.

We can see a representation of this type of reflection on materials such as paper or chalk. The diffuse reflections do not change their appearance based on the viewer’s position, which is another aspect that helps us to identify them.

Rough materials such as paper, rocks and some textiles creating diffuse reflections.

Specular Reflection:

The specular reflection can be observed on polished surfaces. In ideal situations, if multiple parallel rays will hit such surface, the reflected rays will stay parallel. While the diffuse reflection does not change with the position of the viewer, the specular will change as the viewer moves around the surface.

The real world is not perfect though, and as I mentioned before, the light rays will interact with the micro-facets. Depending on how these micro-facets are distributed (how irregular the surface is), the specular will spread more or less, which will make it look rougher or glossier. 

Therefore, the highlights on the surface have different appearances (bigger and blurrier on rough surfaces, smaller and sharper on glossy surfaces). Although the same amount of light is reflected no matter the roughness of the surface, the specular varies in brightness, based on how "focused" it is.

The shape of the specular also differs based on the type of material: isotropic or anisotropic. Some materials such as brushed metal are made out of small repetitive patterns. Thanks to these, the reflections and highlights produced by the material have a stretched and directional aspect. The isotropic materials have a round specular while anisotropic materials produce an ellipsoid specular shape.

Some examples of anisotropy.

Fresnel is an effect which can be well observed when looking at highly reflective materials ( even though everything has Fresnel :) ). It means that the materials tend to appear more reflective when looking at their grazing angles than when we look perpendicularly on them (face them). There are a lot of resources available on-line that can show how material reflectance changes at different viewing angles, but probably the best-known one is refractiveindex.info.  

The difference between electrics and dielectrics (materials that conduct electricity or not) as well as the Fresnel effect will be presented in more detail in a practical article that I am going to release in the future.

Now that we covered both types of reflection, we can continue talking about the refraction and subsurface scattering, important phenomenons that we are using a lot in CG.

Refraction:

Refraction is a phenomenon that happens whenever light travels between two different media. When this happens, the light rays will bend and change their speed. Refraction is the reason behind effects like lens distortion or dispersion.

We know how much a ray will bend using something called index of refraction (IOR). The IOR is the ratio between the speed of light in a vacuum and phase velocity of the light in another medium (the one we're interested in). If we take for example a material with an IOR value of 2, it means that light goes through this material with half of the speed it goes through a vacuum.

Thankfully, most of the materials IOR values are easily available on-line.Taking into consideration these values is a must whenever we want to reproduce refractive materials.

Dispersion is a phenomenon in which the white light splits in light of different colours. This produces the well known "rainbow" effect and is quite helpful when reproducing materials such as glass or gems. Dispersion happens because not all the wavelengths of the light have the same IOR. In fact, the smaller the wavelength of the light, the larger the IOR will be. This means that red light, for example, will bend less than green light when passing in a different medium, because it has a smaller index of refraction.  

Subsurface Scattering:

Subsurface scattering, also known as SSS, is an effect produced when light penetrates a surface and scatters through it. Based on the material it scatters through, part of the light will be absorbed and the rest will make its way back to the initial medium. This effect is strongly related to the thickness of the material that light will scatter through. As mentioned at the beginning of this article, the more it travels, the more light gets absorbed. As a result this effect is especially visible on the thinner parts of the object.

Some materials such as wax, skin, milk, etc exhibit sub surface scattering features. When set-up correctly, the SSS strongly increases the realism of the shaded objects. One common mistake people tend to do is making this effect too strong and getting it to look unrealistic.

Light scattering through the objects.

Now you are equipped with the essential knowledge which you need to get started with shading. If you are unsure what rendering engine to start with this will help you "survive" no matter what you decide to chose so just go for it! 

In the future articles, we will talk about more specific things such as the difference between metals and plastics (electrics and dielectrics), different types of lights, skin shading, etc. and we will have a bit more of a practical approach, as this is, at least in my opinion, the best way of learning CG! I hope that you guys learned something from this one and that now, when we will start applying these concepts in shading, no matter what level you are on, we will have a common ground!

That's it for now! For any questions, please do not hesitate to add a comment or/and send me an e-mail using the Contact section! Also, if you liked this article and you would like to share it with anyone else please do ;)!

These resources came in handy when creating the article! Go check them up!

The PBR Guide. Arnold Documentation. Vray Documentation. Redshift Documentation. Neil Blevin's Article about Anisotropy. Khan Academy's Geometric opticsMathematical and Computer Programming Techniques for Computer Graphics by Peter Comninos.  RefractiveIndex.info. Images from Pixabay.