An Intuitive Introduction to Global Illumination and Path Tracing

https://www.scratchapixel.com/lessons/3d-basic-rendering/global-illumination-path-tracing/introduction-global-illumination-path-tracing

in this lesson we will use Monte Carlo methods to simulate global illumination. it will be hard if not impossible to understand this lesson fully if u are not familiar with Monte Carlo methods.
hopefully for u, we have covered this topic extensively in the section the mathematics of computer graphics. read these lessons first before proceeding.

what is global illumination anyway?
global illumination is actually pretty simple to simulate. though generally, the main or principal issue with global illumination is that no matter what u do, it is generally very expensive to simulate and difficult to simulate efficiency.

An Intuitive Introduction to Global Illumination and Path Tracing
but what is global illumination in the first place anyway? as u know, we see things because light emitted by light sources such as the sun bounces off of the surface of objects. when light rays bounce only once from the surface of an object to reach the eye, we speak of direct illumination. but when light rays are emitted by a light source, they can bounce off of the surface of objects multiple times before reaching the eye. this is what we call indirect illumination because light rays follow complex paths before entering the eye. this effect is clearly visible in the images above. some surfaces are not exposed directly to any light sources (often the sun), and yet they are not completely black. this is because they still receive some light as an effect of light bouncing around from surface to surface.
An Intuitive Introduction to Global Illumination and Path Tracing
so far, we learned about simulating direct illumination. global illumination involves to simulate both effects: direct plus indirect illumination. simulating both effects is important to produce realistic images.

being able to simulate global illumination seems like a feature that every rendering system should have so why making a big deal out of it? 看起来全局照明应该是每个渲染系统的特性,但是为啥还有小题大做呢?because while simple in some cases, it is complex to solve in a generic manner and also generally expensive. this explains why for example most real-time rendering systems do not offer to simulate (at least accurately) global illumination effects.

  1. it is hard to come with a generic solution that solves all light paths: light rays can interact with many different kind of materials before entering the eye. for example a light ray freshly emitted from a light source may be reflected by a diffuse surface first, then travel though a glass of water (it has been refracted then which menas a slight shift or change of direction), then hit a metal surface, then another diffuse surface and then finally hit the eye. there is an infinity of possible combinations. the path that a light ray follows from the light source to the eye is simply called a light path. as u know, in the real world, light travels from light sources to the eye. from a mathematical point of view, we know the rules that define the way light rays are reflected off from the surface of various materials. for example we know about the law of reflection, we know about refractoin, etc. simulating the path of a light ray as it interacts with various materials is thus something that we can easily do with a computer. though the problem as u know, is that forward tracing in computer graphics is not an efficient way of making up an image. simulating the path of light rays from the light source they are emitted from to the eye is inefficient (see the lesson Introduction to Ray Tracing: a Simple Method for Creating 3D Images). we prefer backward tracing which consists of tracing the path of light rays from the eye, back to the light source where they originated from. the problem is that backward tracing is an efficient way of computing direct illumination indeed but not always an efficient way of simulating indirect lighting. we will show why in this lesson.
    An Intuitive Introduction to Global Illumination and Path Tracing
    Figure 2: simulating indirect diffuse using backward ray-tracing.

  2. direct lighting mostly involves to cast shadow rays from the shared point to the various light sources contained in the scene. how fast computing direct lighting is depends directly on the number of light sources contained in the scene. though computing indirect lighting is generally many times slower than computing direct lighting because it requires to simualte the path of a great number of additional light rays boucing around the scene. generally, simulating these light paths can be more easily done with rays and ray-tracing though ray-tracing as we also know is quite expensive. as we progress with the lesson, understanding why simulating global illumination is an expensive process will become clearer.
    What you need to remember from this part of the lesson, is essentially that there is two ways for an object to receive light: it can receive light directly from a light source or indirectly from other objects. Objects in a way can also been seen as light sources. Not because they emit light though but because they reflect light. Thus we need to take them into consideration when we compute the amount of light a shaded point receives (of course, to reflect light these objects need to be illuminated themselves somehow either directly or indirectly). You may guess that this is a complex problem on its own because light reflected by an object A towards an object B might be reflected by B back to A, which in turns will reflect some of that light again back to B, etc. The lighting of B depends on A, but the lighting of A also depends on B (figure 3). The process implies an exchange of energy between surfaces which can go for ever. Putting this in mathematical form is possible, but solving the resulting equations is much harder (for a more formal introduction to this topic check the lesson devoted to the Rendering Equation in the next sections).
    Simulating indirect illumination is about simulating the paths that light rays take from the moment they are emitted by a light source to the moment they enter the eyes. For this particular reasons we generally speak of light transport, the transport of light or its propagation in space as it bounces from surface to surface. A light transport algorithm (backward tracing which we will talk about again this chapter is an example of such algorithm) is an algorithm that describes how this light transport problem can be solved. As you we will explain in this lesson, simulating light transport is a complex problem, and it is hard to come with one algorithm that makes it possible to describe all sort of light paths that we find in the real world.
    An Intuitive Introduction to Global Illumination and Path Tracing
    Figure 3: exchange of light energy between two unoccluded patches. Illumination of B depends on the light reflected or emitted by A in the direction of B, but some of that light is reflected back to B which reflects it again to A, etc.

How Do We Simulate Indirect Lighting with Backward Tracing
To understand the problem of simulating global illumination with backward tracing, you first need to understand how we can simulate indirect lighting. As suggested, many attempts have been made to formalize this process i.e. putting the process into a mathematical form (interested and mathematically savvy readers can fine some information in the reference section at the end of this lesson). Though, we will first explain the process in simple terms. If you are interested in the maths, please check the advanced lessons on rendering in the next sections.

we know from the previous lesson that light illuminating a given point P on the surface of an object, can come from all possible directions contained within a hemisphere oriented about the surface normal N at P. when u deal with direct light sources, finding where light comes from is simple. we just need to loop over all the light sources contained in the scene and either consider their direction if it is a directional light or trace a line from the light source to P if the light is spherical or point light source. though when we want to account for indirect lighting, every surface above P may redirect light towards P. though, as we just mentioned. finding the direction of light rays when u deal with delta lights 很小的光源 is simple but how do we do that when light is emitted by a surface? 如果是一个表面就不是那么简单了。?
there is no unique point light position from which the light direction can be computed. in fact, since we deal with a surface, there is as an inifinity 无穷 of points we could chose on the surface of that object to compute the light direction. and why should we choose one direction rather than another considering that every point on the surface of that object is likely to reflect light towards P?

the answer to this question is both simple and difficult. in some very specific situations, the problem can be sovled analytically, there is a closed-form solution to this problem. in other words, it can be solved with an equation. this happens when the shapes of the objects making up the scene are simple (sphere, quads, rectangles), when the objects are not shadowing each other and when they have constant illumination across their surface.
as u can see this makes a lot of “if”. in other words, it is for example quite simple to compute the exchange of light energy between two rectangular patches or between a rectangle and a sphere as long as they are not occluded by some other objects and as long as they have a constant color. but as soon as we place a third object between the patch and the sphere or as soon as we shade these objects, then these simple analytical closed-form solutions do not work anymore. to find more information on this topic please check the lessons on rendering in the next sections (and especially the lesson on radiosity).

we thus need to find a more robust solution to this problem in which the solution works regardless of the obejcts shapes and does not depends on objects visibility. it turns out that solving this problem with these constraints限制 is pretty hard. hopefully we can use a simple method called Monte Carlo integration. the theory behind Monte Carlo integration is explained in great detail in two lessons u can find in the section The Mathematics of Computer Graphics. But why integration? because in essence what we are trying to do is “gather” all light coming from all possible directions above the hemisphere oriented about the normal at P and this in mathematics, can be done using what we call an “integral” operator:
An Intuitive Introduction to Global Illumination and Path Tracing
Ω (the capital Greek letter for omega) here represents the hemisphere of directions oriented about the normal at P. it defines the region of space over which the integral is performed.

what we integrate is generally a function. so what is that function in our case? if u look at firgure 3, u can see the illumination of P by other objects in the scene, as a function.

An Intuitive Introduction to Global Illumination and Path Tracing

figure 4: the amout of light reflected by objects in the scene towards PP the shading point, can be written as function of solid angle, which we can also re-write in terms of spherical coordinates. In the 2D case, it is just a function of the angle θθ. This is the function that we want to integrate over all directions contained in a half-disk in the 2D case and a hemisphere in 3D.

this function is non-zero in whatever parts of the half-disk onto which objects in the scene are projected to (assuming the objects themselves are not black). This function can be parametrised in different ways. It can be a function of solid angle (the Greek letter omega: ωω) or a function of the spherical coordinates θθ and ϕ (the Greek letters theta and phi). These are just two different ways (but equally valid) of parametrising the hemisphere. If we just consider the 2D case (figure 3), then this can simply be defined as function of the angle θ.