Transparency and Refraction in Ray Tracing



Transparency and Refractions play an important role in rendering materials like glass, water, and diamonds. These effects give objects their unique appearance. In this chapter, we will see how transparency and refraction are handled in ray tracing.

Transparency in Ray Tracing

Ray tracing works by simulating the behavior of light as it interacts with objects in a scene. It calculates reflections, shadows, and other lighting effects by tracing the path of rays from the camera to light sources.

Transparency refers to how much light passes through a material. In ray tracing, transparency is simulated by allowing some rays to pass through an object instead of reflecting off it.

When light passes through transparent materials like glass or water, the light rays bend, causing what we know as refraction. This effect occurs because light travels at different speeds in different materials.

Transparency in Ray Tracing

For example, when light moves from air (which has a refractive index of 1.0) into water (which has a refractive index of 1.33), it bends according to Snell's Law. The refractive index measures how much light slows down in a medium compared to a vacuum.

Snell's Law and Refraction

Refraction is the bending of light as it passes from one material to another. Snell's Law is a fundamental equation in ray tracing that describes how light bends. It states:

$$\mathrm{n \:\sin\: \theta \:=\: n_t \:\sin\: \varphi}$$

Where,

  • n is the refractive index of the first material
  • θ is the angle of the incoming ray
  • nt is the refractive index of the second material
  • is the angle of the refracted ray

In simple terms, when light hits a surface, part of it is reflected, and part of it is transmitted into the material, changing its direction. The amount of bending depends on the refractive indices of the two materials.

Refractive Indices

From the following list, you can observe how materials like diamond have a much higher refractive index than air, making light bend sharply when passing through them.

  • Air: 1.00
  • Water: 1.33-1.34
  • Window Glass: 1.51
  • Optical Glass: 1.49-1.92
  • Diamond: 2.42

Mathematics behind Refraction

To calculate the refraction, it needs determining the angles of incidence and refraction using trigonometry. Since computing sines and cosines can be complex, a more convenient approach uses the relationship −

$$\mathrm{\cos^2 \varphi \:=\: 1 \:-\: \frac{n^2}{n_t^2} \left( 1 \:-\: \cos^2 \theta \right)}$$

In this formula, θ is the angle between the incident ray and the surface normal. If the refractive indices are reversed, so are the angles θ and . This equation helps ray tracing programs calculate how light bends when it passes through objects.

Refraction Vector

To convert these angles into a 3D vector for use in ray tracing, we define the transmission vector t as −

$$\mathrm{t \:=\: \sin \varphi \:\cdot\: b \:-\: \cos \varphi \:\cdot\: n}$$

Where, b is a basis vector and n is the surface normal.

This vector represents the direction in which the light travels after refraction.

Total Internal Reflection

From the class of physics we know another important thing called the internal total reflection. Sometimes, light doesn't refract but instead reflects entirely inside the material. This phenomenon is known as total internal reflection.

Total Internal Reflection occurs when light tries to move from a material with a high refractive index to one with a lower index at a steep angle. If the angle is too steep, the light reflects back into the material rather than passing through. This effect is commonly seen in diamonds and glass, giving them their sparkling, reflective appearance.

Reflectivity and Fresnel Equations

For ray tracing we must understand the physics. Another important equation that is needed is the Fresnel equations. These equations describe how much light is reflected and how much is refracted when it hits a surface.

The amount of reflection depends on the angle of incidence. As the angle increases, more light is reflected.

A simplified version of this equation, called the Schlick approximation, is often used in ray tracing −

$$\mathrm{R(\theta) \:=\: R_0 \:+\: (1 \:-\: R_0)(1 \:-\: \cos \theta)^5}$$

Where R0 is the reflectance at normal incidence, calculated as −

$$\mathrm{R_0 \:=\: \left( \frac{n_t \:-\: 1}{n_t \:+\: 1} \right)^2}$$

This approximation allows for more efficient calculations without significantly affecting visual quality.

Attenuation and Beers Law

From physics we know that transparent materials also filter light. This changes its intensity and color as it passes through. This filtering effect is governed by Beer’s Law. The law states that the intensity of light decreases as it travels through a material.

The formula for Beer’s Law is −

$$\mathrm{I(s) \:=\: I_0 e^{-\ln(a) s}}$$

Where,

  • I(s) is the intensity at a distance s,
  • I0 is the original intensity,
  • a is the attenuation constant, which depends on the material.

In computer graphics, this equation is often adjusted by trial and error to achieve the desired appearance. The effects of Beer’s Law are visible when glass takes on a tint, like the green hue often seen in thick panes of glass.

Attenuation and Beers Law

Implementing Transparency in Ray Tracing

To implement transparency and refraction in ray tracing, the renderer must calculate when a ray is entering or exiting a transparent object. Usually, objects are assumed to be in the air with a refractive index of 1.0, and the surface normals point outward from the object. The renderer then calculates whether to reflect or refract the ray using the formulas discussed above.

When a ray refracts, its color is calculated based on how much light passes through the object and how much is reflected. The program uses these values to create realistic renderings of transparent materials.

Let us see a simple code for transparency in ray tracing −

if (p is on a dielectric) then
  r = reflect(d, n)
  if (d  n < 0) then
    refract(d, n, n, t)
    c = d  n
  else
    kr = exp(art)
    kg = exp(agt)
    kb = exp(abt)
  if refract(d, n, 1/n, t) then
    c = t  n

This code handles the calculation of reflections and refractions. This ensures that transparent objects behave realistically when rendered.

Conclusion

In this chapter, we explained the basics of transparency and refraction in ray tracing. We also covered the key principles of Snell's Law, total internal reflection, Fresnel equations, and Beers Law. We explored how ray tracing simulates the behavior of light as it passes through materials like glass and water, creating realistic renderings of transparent objects.

Through examples and mathematical explanations, we have shown how these concepts are implemented in ray tracing software.

Advertisements