Direct and indirect illumination
Our current task is to add indirect light on the basis of direct light and shadow, that is to say, we need to add other surface reflection light to our current vertex/pixel illumination. We can use the same method as path raytrace. First, our rendering formula is divided into two parts: Direct Illumination and indirect illumination.
L = l1 + L2
= L1 + hybrid BRDF * l (X1) * cos θ * V * D ω
L1 indicates Direct Illumination, L2 indicates indirect illumination. L (X1) indicates the brightness of other surface reflections.
Like the two cases described above, we assume that the plane where our vertex/pixel is located is an ideal diffuse surface. We need to solve the problem of indirect illumination in our formula. We use the Monte Carlo Method to Calculate the indirect illumination.
L = l1 + hybrid BRDF * l (X1) * cos θ * D ω
≈ L1 + (P 1/PI) * (1/n) * Σ (L (X1) * cos θ)/P (X1)
Through the above expression, we can conclude that the steps for calculating the indirect illumination part are: First, we take the vertex/pixel that needs to be computed as the center, at random, n lines of light and scenes and other objects are emitted in the hemisphere determined by the vertex/pixel and the normal of the surface. If there is no collision with the scene or other objects, there is no indirect light in this direction, it can also be expressed as L (X1) = 0. Otherwise, it indicates that there is indirect illumination in this direction. Then we need to calculate the brightness of the reflection from this intersection point in this direction. For this intersection, the brightness of the reflection light in this direction is equal to the brightness of the reflection light for direct and indirect illumination. Here, we only use the brightness of the reflected light from the intersection to represent the brightness of the reflected light from the intersection. In this way, we need to calculate the brightness of the direct light reflection for the intersection. We use the Direct Illumination + shadow method mentioned above to calculate the reflected brightness of the Cross-point Direct Illumination. So we further get
L ≈ l1 + (P 1/PI) * (1/n) * Σ (L (X1) * cos θ)/P (X1)
≈ L1 + (P 1/PI) * (1/n) * Σ (∫ BRDF * l (X1) * cos θ * D ω) * cos θ) /P (X1)
≈ L1 + (P 1/PI) * (1/n) * Σ (LI * t2i) * cos θ)/P (X1)
≈ (P/PI) * Sigma li * t1i + (P 1/PI) * (1/n) * Sigma (LI * t2i) * cos θ) /P (X1)
We randomly sample the hemisphere determined by the current vertex/pixel and the normal of the plane where it is located. In this case, P (X1) = 1/(2 * PI ), enter the last expression above to obtain
L ≈ (P/PI) * Sigma li * t1i + (P 1/PI) * (1/n) * 2 * pI * Sigma (LI * t2i) * cos θ)
≈ (P/PI) * Σ li * t1i + (P 1/PI) * (1/n) * 2 * pI * Σ (LI * Σ (t2i * cos θ ))
Through the above derivation, we can see that when we calculate the direct and indirect illumination effects, we calculate the T (x) coefficient Ti of the vertex/pixel, first, we need to calculate the T (x) coefficient t1i of the vertex/pixel in the direct illumination effect. Then, in the hemisphere determined by the vertex/pixel and the normal of the plane, we randomly sample n lines of light, scenes, and objects for collision detection. For each intersection, we use interpolation to calculate the T (x) coefficient of the intersection under the direct illumination effect. Multiply the coefficients of all the intersections to the coo-cos θ value of the normal of the plane where the light and the intersection are located, and then obtain the average t2i value. The T (x) coefficient of our final direct light and indirect light is equal to the sum of the two coefficients calculated above. Ti = t1i + t2i.
The final rendering still uses the dot Multiplication operation between the pre-calculated Spherical Harmonic lighting and Radiance Transfer Coefficients to obtain the final vertex/pixel reflected light brightness value.