![]() |
Learning ObjectivesBy the end of this lecture, you will be able to:
|
We've talked a lot about how rays reflect off of surfaces, but not so much about how they might go through surfaces. In this lecture, we'll talk about modeling translucent materials, in which rays will enter a surface at one point and exit at some other point.
The crystal giraffe above can be modeled as a solid piece of glass. Glass is a refractive material which bends (refracts) light rays as they enter and leave the surface. Refractive materials have refraction indices denoted by
Let's start with a ray with direction
where
In the figure below
It's important to note that if the stuff inside the square-root of the equation above is negative, then refraction doesn't happen. Instead, we would have Total Internal Reflection (TIR). When this is detected, you should actually cast a reflection ray (like when we discussed mirror reflections). TIR can be observed by jumping into a pool and looking up at the surface of the water, like in this picture.
Rays don't always reflect/refract in such predictable ways. It's possible that a ray will enter a surface scatter off the material inside the surface and then reflect back out from some other point. This is a phenomenon known as subsurface scattering and can be used to model things like gummy bears, jello, milk, soap, etc.
In the picture of gummy bears below, notice that some of the gummy bears in the background are contributing to the color of the gummy bears in the foreground. This is because light is reflecting off of the background gummy bears, and then passing/scattering through the foreground ones.
Subsurface scattering is a phenomenon in which rays enter a material, and then bounce off of stuff inside the surface (in kind of a random way) before reflecting back out of the surface. For example, in the image below (source), the incoming yellow ray enters the surface, scatters off the material below the surface and then exits at a different (rather unpredictable) location.
There are many techniques that have been proposed to model subsurface scattering, which range in fidelity and computational time. The technique we'll focus on below is a simplification of the technique proposed by Colin Barré-Brisebois and Marc Bouchard in this presentation from 2011.
We can implement this technique by assuming there is some kind of "backlight" (with a position
As a result, the main idea (and difficulty) of this technique is to first estimate the distance a ray would have to travel through a surface (from the backlight). We can then use this distance to compute a rough approximation to how much subsurface scattering would be produced through the surface.
Consider the sketch below. To estimate the distance, we'll cast a secondary ray from the surface intersection point
However, we want more backlight contribution for a shorter distance, and less backlight contribution for a longer distance. There are different ways to achieve this, and one possible relationship is
In the pictures below, there is a backlight source behind the gummy bear. The leftmost picture shows the distance (darker represents smaller distance) the backlight rays would need to travel to hit the surface points that we can see (the ones hit by the camera rays). The middle picture shows an approximation to the thickness using the expression above.
The final color at a point on the surface
where
The calculation of
Now let
The color contribution from subsurface scattering can be calculated from:
where
The clamp(x, a, b)
function will clamp the value of x
to be in the [a, b]
range. A possible implementation could be:
const clamp = (x, a, b) => {
if (x < a) return a;
if (x > b) return b;
return x;
};
Please note that this is a simplification of the original method, and our calculation of the thickness is different. Some of the terms have been omitted to avoid adding tunable parameters, while still producing the effect of subsurface scattering. Please see the presentation linked above for a description of the original method.
Subsurface scattering is often used to render skin. However, please keep in mind that this visual phenomenon is more characteristic of white skin. I would encourage you to watch this presentation about Anti-Racist Graphics Research by Professor Theodore Kim which discusses this limitation in computer graphics technologies.