GAMES101 Lec 14 (2)~16: Ray Tracing (2) BRDF, rendering equation, global illumination, path tracing

0 Introduction - Overview of Radiometry

  • When we talked about the Blinn-Phong shading model before, we set a number as the light intensity, but we don’t know the real physical meaning of this number. We just greatly simplified it into a number. Whitted-style ray tracing is not a real result
    .
    These are resolved by radiometry, which is the basis of path tracinginsert image description here

Radiometrics provides a series of measurement methods and units to define light.
It defines the properties of light in space, which is completely correct in physics. At the same time,
Teacher Yan provided him with a way to learn new things: learn from exploring why, what it is, how it works insert image description here

1 Related concepts

1.1 Radiant Energy and Flux (Power)

  • Radiant energy: radiation energy, unit joule J,
    Radiant Flux (Power): energy radiated per unit time, which can represent the brightness of light. insert image description hereFlux can also be understood as the number of photons passing through this plane per unit timeinsert image description here

Knowing these two concepts, we can define other physical quantities. The
following three concepts briefly describe
Radiant Intensity—the light source will radiate energy in all directions. We need to define a directional and energy-related concept
Irradiance—the amount received on the surface of an object. Energy
Radiance - the energy of light in propagationinsert image description here 

1.2 Radiant Intensity

  • Radiant Intensity: The energy radiated to each solid angle (Solid Angle) in unit timeinsert image description here

So what is a solid angle? Let’s start with the plane angle.
The definition of the plane angle is the arc length divided by the radius. At this time, the enlargement and reduction of the circle does not affect this angle. The plane angle is at most 2π and
extended to three dimensions. The definition is the area divided by the square of the radius. According to the integral, the maximum solid angle is 4π 

 insert image description here

After defining the solid angle, we then define the unit solid angle.
Divide the unit area by the square of the radius.
We define the unit area by the change of θ and φ of the spherical coordinates to getinsert image description here 

The integral of the unit solid angle can be obtained as 4π, confirming the previous conclusioninsert image description here 

Now looking back at Intensity, we define a point light source that emits uniform light, integrate all the Intensities on the unit solid angle to get energy, and the Intensity on the unit solid angle is also divided by 4πinsert image description here 

Let’s give an example in daily life.
The LED lamp marked with 60w actually has a power consumption of 11w, and its brightness is equivalent to an incandescent lamp of 60w.
We can also calculate its Intensity. Assuming that it emits light evenly, divide the energy lumens by the area 4π to get the unit Intensity on solid angleinsert image description here 

1.3 Irradiance
Irradiance definition: within a unit time, the energy of light received by each unit area,
that is, power per unit area
, for comparison, the previous Radiant Intensity is power per unit solid angle

Note: The unit area must be perpendicular to the light. If it is not perpendicular, the area should be projected in the vertical direction (cos is not written in the figure, just a dA for the time being)
insert image description here

Similar to the content in the previous Biling - Phong.
Left: the unit area is perpendicular to the light, so you can directly use the calculation formula of Irradiance.
Middle: the area is not perpendicular to the light, and its projection can only receive three or half of the light, so you need ×1/2
right picture: more generally, when the unit area is not perpendicular to the light, it needs to be projected to the vertical direction by ×cos.
insert image description here
 

The above Lambert's cosine theorem explains why the earth has seasonal changes.
When the northern hemisphere is summer, the sun shines directly on the northern hemisphere, and there is more Irradiance in the northern hemisphere, which means it is hotter; and when the northern hemisphere is winter, there is a certain distance between the light and the surface of the earth. The included angle, Irradiance decreases, so the winter is colder. (As shown in the black dotted line in the earth above) insert image description here

As mentioned before, we assume that energy is concentrated on a spherical shell. As the spherical shell increases, the light intensity will have an r-square attenuation; now it can be correctly
explained by Irradiance:
on the innermost unit sphere, I rradiance ( E ) = φ / 4 π Irradiance(E) = φ/4πIrradiance(E)=φ/4π, the energy received per unit area is φ / 4 π φ/4πφ/4π, and on the outer spherical
surface , I rradiance ( E ' ) = φ / 4 π r 2 Irradiance(E') = φ/4πr^2Irradiance(E')=φ/4πr 
2
 , the energy received on the unit area is φ / 4 π r 2 φ/4πr^2φ/4πr 
2
 , so it is the r-squared attenuation.
So we can know that it is not Radiant Intensity that is attenuating here, but Irradiance is attenuating.
If you draw a cone with a solid angle from the center of the sphere, you can know that as the spherical surface becomes larger, the size of the solid angle remains constant, but the size of the unit area corresponding to the solid angle becomes larger and larger, so the spherical
surface The larger the dA is, the smaller the Irradiance will be.insert image description here

 

1.4 Radiance

  • Radiance is the fundamental field quantity (fundamental field quantity) that describes the distribution of light in the environment.
    It is mainly used to accurately describe some properties of light.
    Accurate ray tracing has a great relationship with radiance. Rendering is to calculate radianceinsert image description here

Radiance definition:
English definition: The radiance (luminance) is the power emitted, reflected, transmitted or received by a surface, per unit solid angle, per projected unit area. Definition: Radiant Flux
(Power) It is in each unit solid angle, How much is there on the surface of each projection
, that is, the energy emitted by a certain unit surface in the direction of a certain unit solid angle

insert image description here

1.5 The connection and difference between Radiance&Irradiance&Intensity

We distinguish and summarize these conceptsinsert image description here

Radiance : Irradiance per solid angle

According to the interpretation of Radiance:
Radiance means the energy that the unit area dA radiates from the energy it receives in the direction of w.

Conversely, according to the explanation of absorbed energy (Irradiance):
the Radiance emitted from the w direction to the unit area dA is accumulated in all directions, and the total energy received by the unit area dA is Irradiance, which is the
component of Irradiance in the direction of w, which is Radiance
insert image description here

Radiance: Radiant Intensity per projected unit area

  • Intensity represents the energy that all areas will radiate in the direction of a certain unit solid angle, and
    Radiance represents the projection/component of this Intensity on a certain unit area dA
    insert image description here

The difference and connection between Radiance and Irradiance are used a lot in graphics, let's summarize it again

  • Radiance is the energy radiated by a certain unit facing a certain unit solid angle.
    Irradiance is the energy received from all directions on a certain unit area.
    Irradiance is obtained by integrating all the Radiance on the hemisphere.
    insert image description here

2 Bidirectional Reflectance Distribution Function (Bidirectional ReflectanceDistribution Function, BRDF)
We said before that
if the light is emitted from one place and hits a mirror, then the light will be reflected in another direction; if it hits a diffuse reflective object, it will go in all directions
. There needs to be a function to describe this property: how much energy comes in from a certain direction and is reflected in a certain direction

In our previous understanding, reflection means that a ray of light reaches a surface and then reflects to other directions.
This process can also be regarded as light coming from a certain direction. After reaching the surface of an object, it is absorbed by the surface of the object, and then Then it is emitted from the surface of the object to other directions,
which is to use Radiance and Irradiance to explain reflection
insert image description here

d E ( wi ) dE(w_i)dE(w 
i
​)
 means: Radiance emitted from the direction of wi w_iw 
i
​ is
 absorbed and transformed when it reaches the reflection point, and then the obtained Irradiance
d L ( x , wr ) dL( x,w_r)dL(x,w 
r
​)
 means   the Radiance reflected from the reflection point in the direction of wr w_rw
r ​We know that the reflection point must absorb Radiance from a certain direction to turn it into Irradiance, and then reflect it to all directions On the solid angle Radiance , but we don’t know how much energy the Radiance reflected in the direction of wr will have, so we define a function for this and calculate: Consider a tiny area d A dAdA, from a certain tiny solid angle dwi dw_idw   How will the Irradiance received on i be distributed to each solid angle. In fact, what is obtained is a ratio. What is the ratio? This ratio is (radiance sent out on any solid angle) / (Irradiance received by unit area d A dAdA) This is the definition of BRDF , which tells us how to radiate the energy collected on the surface at a certain ratio go the other direction














BRDF can represent the energy collected from each incident direction and reflected to each outgoing direction in a certain proportion,
that is, the energy distribution reflected in different directions after a certain light hits the surface of an object.
If it is specular reflection, then only the reflection direction will have energy, and there will be no energy in all other directions; if it is diffuse reflection, the incoming energy will be equally distributed to all directions

Ignoring the derivation part, BRDF actually describes the interaction between objects and light.
It is precisely because of this concept of BRDF that determines what the different materials of objects are, that is, BRDF defines materials
———— ———————————

d E ( wi ) dE(w_i)dE(w 
i
​)
 means: Radiance emitted from the direction of wi w_iw 
i
​ is
 absorbed and transformed when it reaches the reflection point, and then the obtained Irradiance
d L ( x , wr ) dL( x,w_r)dL(x,w 
r
​)
 means   the Radiance reflected from the reflection point in the direction of wr w_rw
r ​We know that the reflection point must absorb Radiance from a certain direction to turn it into Irradiance, and then reflect it to all directions On the solid angle Radiance , but we don’t know how much energy the Radiance reflected in the direction of wr will have, so we define a function for this and calculate: Consider a tiny area d A dAdA, from a certain tiny solid angle dwi dw_idw   How will the Irradiance received on i be distributed to each solid angle. In fact, what is obtained is a ratio. What is the ratio? This ratio is (radiance sent out on any solid angle) / (Irradiance received by unit area d A dAdA) This is the definition of BRDF , which tells us how to radiate the energy collected on the surface at a certain ratio go the other direction














BRDF can represent the energy collected from each incident direction and reflected to each outgoing direction in a certain proportion,
that is, the energy distribution reflected in different directions after a certain light hits the surface of an object.
If it is specular reflection, then only the reflection direction will have energy, and there will be no energy in all other directions; if it is diffuse reflection, the incoming energy will be equally distributed to all directions

Ignoring the derivation part, BRDF actually describes the interaction between objects and light.
It is precisely because of the concept of BRDF that determines what the different materials of objects are, that is, BRDF defines materials.
insert image description here

 

3 The Reflection Equation→The Rendering Equation (The Reflection Equation→The Rendering Euqation)

The Reflection Equation (The Reflection Equation)
can be obtained from the above analysis, d Lr( Wr) is Withe energy incident from the angle and finally reflected to Wrthe direction.

  • In the process of reflection, we do not only reflect a single energy from a certain direction, but collect energy from all directions and reflect it to a certain angle.
  • So to get the final reflection effect, it should be:
    Calculate through BRDF: the energy received in each direction Wrand how much energy it reflects in the direction
    , and then add up all these energies, and Wrthe energy reflected in the direction
    can be obtained by integrating Representation (the integral area represented by the square of H is the entire hemisphere, and the entire expression below is the reflection equation)insert image description here

When considering the reflection equation, we should also note that
the energy received by the reflection point (Irradiance) is not only from the light source, but also from the light reflected from other surfaces (Irradiance) and
the energy reflected from the reflection point (Radiance ) will not only be reflected to the Camera or human eyes, but will also be reflected to other surfaces as Irradiance,
so the definition of the reflection equation becomes a recursive definition, and therefore, the number of light reflections is different, and the final effect is also It won’t be different
, but we don’t consider these for now, put the recursive thinking here first, and make a generalizationinsert image description here
 

The Rendering Euqation

Compared with the reflection equation, the rendering equation just adds a self-luminous energy.
Because when we consider the reflection of light on the surface of the object, we don't consider the object's own light emission, so the rendering equation adds the energy of the object's own light emission.
Rendering effect = reflected light + self-illumination, the rendering equation is as follows:
(note that all directions are outward by default
insert image description here

4 In-depth understanding of the rendering equation Understanding the rendering equation

We deepen our understanding of the rendering equation

  • We first look at the reflection equation, assuming there is a point light source
    whose reflected light = self-illumination + incident light × BRDF × angle between incident light and normalinsert image description here

 If there are many point light sources, then it is natural to add up, adding up the energy of each point light source to illuminate this pointinsert image description here

What if there is a surface light source? We understand the surface light source as a collection of point light sources, that is, to integrate, insert image description here  but if it is not only the light source, but also the light reflected from other objects,
we regard the reflective surface of other objects as the light source,
which can also be said to go from this point to a certain direction. The radiated Radiance is also dependent on the Radiance radiated from other points, that is, the recursive process
insert image description here

 The effect picture of the paper on the rendering equation of the year
insert image description here

4.1 Global illumination

  • We abbreviate the equation, and use a generalization of the two variables of position + angle to become u and v, and write it into an integral formulainsert image description here

Continue to write the equation in the form of an operator. insert image description here Use the operational properties of the operator (inversion and Taylor expansion) to solve the equation, and solve L. insert image description here Then the rendering equation is disassembled into many items distinguished by the number of light ejections.
The number of times the light is ejected The items are added up, that is, the global illumination is obtainedinsert image description here

Use the rendering equation to understand rasterization. Rasterization only does self-illumination and direct lightinginsert image description here 

Let's take a look at the effect diagram corresponding to the number of different light ejections

  • direct light
    insert image description here

Global illumination of one ejection (direct lighting + one ejection)
insert image description here 
global illumination of two ejections
(note that the light is black at this time) 
insert image description here

The global illumination of four ejections
(note that the light is on at this time, and the light is ejected at this time, because some objects need a certain number of ejections to come out after the light enters)
insert image description here . will gradually converge 
insert image description here


insert image description here 

5 Probability Review Probability Review

Everyone has studied probability theory in college, so I briefly wrote

  • Discrete Random Variables and Their Distributions
    insert image description here

insert image description here The Expectation of a Discrete Random Variable 
insert image description here

The probability density function (PDF) of a continuous random variable and insert image description here the function of an expected random variable insert image description here

6 Monte Carlo Integration Monte Carlo Integration

Regarding learning Monte Carlo integrals, we first take three steps

  • Why
    The Monte Carlo integration method is to calculate the definite integrals that are difficult to calculate (the analytical formula is difficult or impossible to write), and it provides a numerical method that can directly calculate the valueinsert image description here

What&How
To give a simple example, we can randomly take a sample in the domain of definition, and then get the corresponding value of f(x), then the integral of the whole function is f(x). We can also take multiple samples, and then put
their The value is averaged, and the integral of the whole function is the resultinsert image description here 

The formal definition of Monte Carlo integral is that in order to calculate a definite integral, a pdf is used to sample the domain of definition,
so the value of the definite integral can be approximated by the sampled value and pdf in the form of the following box. Let insert image description here us see a uniform distribution Sampling example 
insert image description here

insert image description here Monte Carlo integration can calculate any integral, it only needs to know how much the sampling pdf is to calculate the integral,
of course more sampling will be more accurate
, and where the sampling is done, the integration will be done 
insert image description here

7 Path Tracing Path Tracing
7.1 Review the Whitted-Style Ray Tracing problem
After talking about Monte Carlo integration, we have enough knowledge reserves to do path tracing

We have already learned about Whitted-Style Ray Tracing,
which will reflect on the specular surface and stop on the diffuse surface,
but this is not right, we can use the Path Tracing method to make better results
insert image description here

Whitted-Style Ray Tracing cannot do Glossy material, and it cannot be said that the light hitting the Glossy material also goes in the direction of Specular
(typical model The Utah teapot)insert image description here 

Whitted-Style Ray Tracing does not consider the effect of diffuse reflection, but in fact there is still an effect between the diffuse reflection surface and the diffuse reflection surface. For example, the
comparison between direct illumination and global illumination in the color bleeding image below shows the effect
(typical model The Cornell box)insert image description here 

Whitted-Style Ray Tracing is wrong, but the rendering equation is correct. The
solution of the rendering equation involves the calculation of integrals on the hemisphere and the execution of recursioninsert image description here 

7.2 Solve the rendering equation A Simple Monte Carlo Solution

Let's consider a simple scene.
This scene has a large surface light source, a shading point, other objects that may block the light, and an observation direction.
We first calculate the direct illumination of this point.insert image description here

We ignore the luminous term. The last light we see at this shading point is the light from all directions and the BRDF effect and then reflected to our viewing direction. This is the
integral on the hemisphere. We use the Monte Carlo method to solve We insert image description here consider the coloring point as point P,
and first use a simple uniform sampling method (the area of ​​the hemisphere is 2π, and the probability density function is also 1/2π) insert image description here

So we can use Monte Carlo integral to calculate direct lighting and insert image description here express it in pseudo-code
. First select N directions, and for each direction to light, if the light source is hit (here is the reverse of the derivation), it will be accumulated and calculated.
insert image description here

 Direct lighting is easy to do, but we also need to introduce indirect lighting to be more realistic

  • As shown in the figure, the light source passes through Q to P to the eyes.
    We want to know how much it is from Q to P, and we look at Q from P. In fact, it is equivalent to the direct light of Q when the eyes are at P.
    insert image description here

We use a simple and intuitive method to add a paragraph to the pseudo code to see if it has light hitting the Q where the object is, and perform recursion to find indirect lighting,
but this does not work.insert image description here 

7.2.1 Problem 1: Quantity problem→N=1

Doing path tracing in the above way will not work, one problem is that the number of rays will explode

  • The number of rays increases exponentiallyinsert image description here

Then when N is what, the exponent will not explode. Then only when N is 1, that is, each coloring point has only one ray.
Of course, we also know that N is 1, which is a result of a large error. How to solve it is a later story. For the time being Shelving
So far, we use N to
be 1 to do Monte Carlo integration , which means path tracing insert image description here . There can be many paths in a pixel, all of which will pass through this pixel

  • What is the final color of the pixel depends on the average of the Radiance of these paths,
    so we only need to have enough Paths.insert image description here

 Take N positions in the pixel, and for each position, form a ray and calculate the coloring.
Randomly generating N paths is actually a Monte Carlo integral
insert image description here

7.2.2 Problem 2: Recursion problem→Russian roulette

  • The second problem is that this recursion has no termination condition
    insert image description here

But in the real world of light ejection, the light will not stop, because the limited number of times will lose energy. For example, the following comparison chart of three ejections and seventeen ejections shows an obvious difference in brightness
insert image description here 


insert image description here 

So how should we solve it? We introduce the concept of Russian Roulette

  • Russian roulette is also a concept similar to Bernoulli distribution
    insert image description here

We use a method similar to calculating the expectation of the Bernoulli distribution to calculate the energy.
Let us calculate the expected result, that is, L0
the expectation of the roulette wheel is still the original energy result,
that is, P × ? + ( 1 − P ) × ? ? = L0
us Cleverly let
the probability of P get the energy    L0/P, and the energy obtained by the probability of 1-P is 0, which is
just right at this time
insert image description here

We summed up the pseudo-code, at
the beginning, we played roulette
and then divided by P in the following codeinsert image description here 

7.3 Sampling the Light

Now we have a correct Path Tracing method.
The left side uses a lower sampling rate, which runs fast but the effect
is poor. The right side uses a high sampling rate, which runs slowly but the effect
is not high. We want to use a low sampling rate. Also works well.
insert image description here
Where is the problem?
Sometimes the light sources are big and small
. In this case, in the previous method, the shading point is uniformly sampled outward. When the light is shot out, a lot of light is wasted. Very few can actually hit the light source. We don’t want
this A wasteful phenomenon, is it possible to have other pdf samples
insert image description here

What is a sample that is not wasted at all?

If we can sample directly on the light source,
that is, the sampling samples are directly distributed on the surface of the light source, then all the light will not be wasted.
We sample on the light source, and the light source itself has a normal n'
light source and a line connecting the shading point. , to get two angles, one is the angle θ with the normal of the shading point, and the other is the angle θ with the normal of the surface of the light source.
We sample the light source, and the light source is understood as a two-dimensional frame on this two-dimensional plane Uniform sampling, that is, pdf=1/A (assuming that the area of ​​the light source is A, because the area is sampled to integrate the pdf and needs to be 1, so the pdf must be 1/A) but the rendering equation is not defined on the light source,
rendering The integral of the equation is defined on the solid angle, and the
Monte Carlo integral defined on the hemisphere of the shading point requires the integration and sampling to be in a domain. Now we are sampling the area of ​​the light source, and the integral of the solid angle of the hemisphere at the shading point, that's wrong

insert image description here

In order to continue to use the rendering equation, we have to write the rendering equation as an integral on the light source
. In order to rewrite, we only need to know the relationship between dw and dA to replace it.
dA is a small surface on the light source, and dw is the small surface What is the solid angle corresponding to the surface of the unit sphere
? So we turn dA over (multiply by cos), and divide by the square of the distance to the center of the circle at this time is the solid angle dw (definition of solid angle)
insert image description here

Next, we rewrite the rendering equation, changing dw to dA
now becomes, sampling the light source and integrating the light source
, and because it is a uniform sampling of the light source, the pdf is 1/A 
insert image description here

In the past, we blindly shot in all directions on the shading point. Whether we hit the light source or not depends on luck. Now we directly sample the light source. At this time, when considering the coloring result, it is divided into two parts: the contribution
from
the light source, and the direct sampling light source
comes from Contribution of other reflectors, do it with Russian roulette insert image description here

Write the above logic in the form of pseudocodeinsert image description here 

In fact, we still have a small problem with sampling the light source, that is, there may be occlusion between the light source and the object.
We need to judge whether it is occluded.
So far, the path tracing is over.insert image description here 

8 Some Side Notes

  • It is not easy to write correct path tracing, and you can understand it more deeply through learning
    . The current path tracing may be higher than the entry level, but it is very moderninsert image description here

path tracing is exactly rightinsert image description here 

Summarizing Ray tracing
For now, Ray tracing represents a large collection of ray propagation methods: one-way or two-way path tracing, photon mapping...insert image description here 

Topics not covered:
How to make the directions evenly distributed on the hemisphere?
Which pdf is better for Monte Carlo integration? (Importance Sampling)
Is there a quality distinction for random numbers?insert image description here 

Topics not covered:
We can sample light sources and hemispheres, can they be combined? (muliple imp. sampling)
Why is the path energy equal to pixels on average? Do you want to weight it?
We get radiance, but the final pixel display needs color, we need to do gamma correction, how to do it?
Does path tracing count as a starter? Getting Startedinsert image description here 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/jiuzhouhi/article/details/123197061