当前位置:网站首页>Games101 review: ray tracing
Games101 review: ray tracing
2022-07-28 03:04:00 【Lao Yan is working hard】
Catalog
0. shadow :Shadow Mapping( From the perspective of rasterization )
1. Ray tracing : light path ( Line ) Reversibility of 、 Refraction of light 、 Coloring contribution
1.0 Why Ray Tracing? Limitations of rasterization
1.1 Recursive (Whitted-Style) Ray Tracing: Simulate the process of continuous light ejection
1.2 Intersection of light and surface Ray-Surface Intersection
1.2.1 Ray equation :r(t) = o + td
1.2.2 The light intersects with the sphere :
1.2.3 Intersection of light and implicit surface :
1.2.4 Intersection of light and triangular mesh : The two methods
2.1 Bounding Volumes:AABB( Axis alignment bounding box )
2.2.1 Oct-Tree、KD-Tree、BSP-Tree
2.2.2 KD-Tree Light intersection judgment process :
2.3 Object division :Object Partitions & Bounding Volume Hierarchy(BVH)
3.1 Radiant Energy & Flux(Power)
3.1.2 Radiant Flux:Lumen( Lumen )、 power
3.2 Radiant Intensity: Intensity of light emitted per solid angle
3.3 Irradiance: How much energy is received per unit surface
3.4.1 Incident Radiance: Per unit solid angle reaching the surface Irradiance
3.4.2 Exiting Radiance: Emitted per unit area away from the surface Intensity
3.5.1 Reflection Equation : The contribution of all incident light to a reflected light
3.5.2 Rendering equations The Rendering Equation: Reflection Equation + Self luminous items
3.5.3 Global illumination : Understanding of reflection equation — Direct light + Indirect care
4.2.1 Monte Carlo method for definite integral ( Simple case : Direct light )
4.2.2 Monte Carlo definite integral ( Global illumination )
0. shadow :Shadow Mapping( From the perspective of rasterization )
thought :
- A visible point , You can see , The light source can also be seen
- An invisible point ( shadow ), You can see , The light source cannot be seen
classical Shadow Mapping It can only deal with point light ( Hard shadow , The boundary is either black or white )
1. Starting from the light source , Look at each pixel , Record the depth of each point
2. Starting from the camera , From the point of view Project back to the light source , Record a depth , If this point is visible , Then the two depth effects are the same
3. Starting from the camera , Project back to the light source from the point you see , Record a depth , It is found that the depth is different from the depth from the light source , It's a shadow




If an object has soft shadows , Then its light source must be of size .
The difference and principle between hard shadow and soft shadow , That is, the umbra (Umbra) And penumbra (Penumbra) The difference between .
thus ,shadow maps There are some problems :


1. Ray tracing : light path ( Line ) Reversibility of 、 Refraction of light 、 Coloring contribution
1.0 Why Ray Tracing? Limitations of rasterization
Limitations of rasterization :
- Unable to deal with multiple light ejections , Global illumination
- Rasterization is fast , But the quality is relatively low
1.1 Recursive (Whitted-Style) Ray Tracing: Simulate the process of continuous light ejection
Quote teacher Yan's original words in class to make a refinement :
- This is a glass ball , Light from the line of sight , Two things happen : Refraction and reflection
- The coloring has changed : Originally, we only focused on whether the point can be illuminated by the light source , Calculate only once ;Whitted-Style It is considered that if the light source can illuminate any point where ejection can occur , Just add the value of their coloring to the value of pixels .
- Consider the energy loss of light .

The results of each light path that calculates the refraction of light at different times are accumulated into one pixel .
At every ejection point , Will calculate the value of its coloring . Finally, it will be added to the pixel points through which the line of sight passes .
1.2 Intersection of light and surface Ray-Surface Intersection
1.2.1 Ray equation :r(t) = o + td

1.2.2 The light intersects with the sphere :


1.2.3 Intersection of light and implicit surface :

1.2.4 Intersection of light and triangular mesh : The two methods
- decompose : First find the intersection of light and surface , Then judge whether the intersection point is in the triangle
- The plane normal and a point in the plane determine the plane equation , Equal to the ray equation
- Möller Trumbore Algorithm: The coordinates of the center of gravity , Directly judge the intersection of triangle and light , Clem's law


2. Ray tracing acceleration :
The most basic ray tracing will intersect all triangular faces in the scene , And calculate the value of each pixel ,Very Slow!
2.1 Bounding Volumes:AABB( Axis alignment bounding box )
And x,y,z Three faces with parallel axes , Therefore, it is called axis alignment .

2.2.1 Judge whether the light is consistent with AABB The intersection : Take the intersection of the maximum entry time and the minimum departure time
- When the light Align faces through all axes , Enter AABB
- When the light Just leave one side , Just leave AABB
- When light enters Box Time is less than leaving Box Time , That is, the light source is Box Inside


Here we consider the following premises : Light is a ray !, With several special cases of concentration :
:Box After the light source , That is, light and Box There are no intersections !
&&
: The light source is Box Inside , There are intersections !
All in all , If and only if :
&&
, Light and Box There are intersections !
Then why use axial symmetry This nature ? The reason is simple , It avoids the trouble of calculating the normals that are not parallel to the axis plane !

2.2 Space division

2.2.1 Oct-Tree、KD-Tree、BSP-Tree
Oct-Tree: Similar to cutting tofu , Cut three knives for three-dimensional objects , Divided into eight pieces ; Cut two knives for two-dimensional objects , Divided into four pieces ; And so on .
How to cut ? For example, cut two knives in two-dimensional space ( More 4 block ), I found that three pieces were empty after this part was cut , Then there is no need to continue cutting . Of course, this is just an example of intuitive understanding , In fact, when to stop depends on the specific constraints , For example, how many objects in this part can stop , Or until this grid is empty .
But as dimensions increase , Tangent space is called exponential rise .
KD-Tree: Each time along a horizontal or vertical axis (xyz) Divide , In two


2.2.2 KD-Tree Light intersection judgment process :







but
- How to judge triangle and AABB It is difficult to have intersections , therefore KD-Tree Gradually reduce the use .
- An object may appear in multiple leaf nodes , That is, in multiple grids .
2.3 Object division :Object Partitions & Bounding Volume Hierarchy(BVH)
Divide the objects into two piles , Recalculate the bounding box
Fast selection algorithm : Fast selection algorithm - Salty_Fish - Blog Garden (cnblogs.com)
3. Radiometry (Radiometry)
3.0 Motivation
The intensity of light Intensity?etc...
Give a precise definition of all aspects of the physical meaning of light !
3.1 Radiant Energy & Flux(Power)
3.1.1 Radiant Energy: energy
3.1.2 Radiant Flux:Lumen( Lumen )、 power

3.2 Radiant Intensity: Intensity of light emitted per solid angle



3.3 Irradiance: How much energy is received per unit surface


3.3.1 Lamber's Cosint Law: The energy received by the surface is only related to the vertical direction

3.4 Radiance: Per unit solid angle 、 Per unit surface Accept 、 How much energy is emitted ( Describe light )



3.4.1 Incident Radiance: Per unit solid angle reaching the surface Irradiance

3.4.2 Exiting Radiance: Emitted per unit area away from the surface Intensity

Irrandiance And Radiance The connection and difference between : The relation of integral , Different units

3.5 Bidirectional Reflectance Distribution Function (BRDF): Describe the energy of light incident in a certain direction and reflected in a certain direction
A light enters from a certain direction , It will reflect in all directions , What we need is the energy carried by the reflected light in a specific direction .
It can also be understood as : Light carries energy into a certain point , This point will absorb the energy of light , Then reflect and release this part of energy from this point . But we don't know how much energy is emitted in a specific direction , At this time, we need such a function , That is to say BRDF.
BRDF Describes how light interacts with objects , It is this concept , Determines the material of the object ,BRDF Items define different materials .
3.5.1 Reflection Equation : The contribution of all incident light to a reflected light


3.5.2 Rendering equations The Rendering Equation: Reflection Equation + Self luminous items

3.5.3 Global illumination : Understanding of reflection equation — Direct light + Indirect care
Reflected light = Self luminous +Sum(( Point light emitting )× BRDF( texture of material ) × Angle of incident light cos )

If it is an area light source , Then it can be obtained by integrating the point light source on the surface :

A linear representation of the reflection equation , Its purpose is to understand that under ray tracing , Light is a combination of direct and indirect light , Indirect illumination includes one direct illumination and several bounces ( It's a little vague here , I still have to go back and listen to the teacher's explanation ) :







4. Monte Carlo path tracking
4.1 Monte Carlo integral : Find the definite integral of a complex function — Analytic solution --> Numerical solution
Want to find an integral , But the function form is particularly complex , Cannot provide a mathematical expression , That is, the analytic form , To calculate the definite integral .
How to solve ? Approximate the definite integral by averaging the randomly sampled values .


Monte Carlo integral formula :


4.2 Path tracking
reflection :Whitted Style Must ray tracing be right ?
Constantly eject light , Connect a light anywhere .
Hit objects such as glass , Reflection or refraction will occur ;
Hit the diffuse object , And it stopped .
Are these two things really right ?
not always . Here's the picture , Specular reflection Whitted It may be right , but Glossy It's wrong. , He should not be with specular The same reflection

The following example illustrates a problem more : The light hits diffuse Objects should never stop

Whitted It's wrong. , But the rendering equation is right :
Rendering equations need to solve two problems :
- How to integrate it ?( In the hemisphere )
- How to deal with recursive process ?( Because every point of ejection comes from the light received by the previous point )
4.2.1 Monte Carlo method for definite integral ( Simple case : Direct light )
Consider a simple case first , This point does not glow , Find the integral result of direct illumination , That is to say, starting from this point, start tracking , See how much light directly reaches the light source :

In this simple case , We do not consider self illumination at this point , And also know the hemisphere PDF, Then we can use Monte Carlo integral to approximate the result :

The pseudo code is as follows , Well understood. , From this point out wi Root light , If a ray of light reaches the light source , Then add the result to the value of this part of the energy integral .
4.2.2 Monte Carlo definite integral ( Global illumination )
So how to consider the global illumination ?
Suppose the traced light reaches an object , Not the light source , At the same time, the hit object is also affected by the light source , Then at this time, let's consider the problem of transformation :
Convert the global illumination into direct illumination between objects , That is to treat the object as a light source , It becomes a local direct illumination , Recursively find the direct illumination of the next object .
The depth of recursion , That is, the number of times light is ejected from the light source to the pixel .
thus , Convert the total ejection times of global illumination into the number of local objects “ Direct light ”

The pseudocode is as follows :

But there are still two problems :
- If a point is ejected once , issue 100 Root light , At the next ejection 100 Root light , Only two ejections , Light from just one point , There will be 10000 The root light emits . This exponential level algorithm is unacceptable .
- When recursion stops ? As mentioned above, recursion stops a certain number of times , But in nature, light can be ejected countless times , How to solve this problem ?

At this time, the basic situation of path tracking is introduced : When N=1 when , That is, each ejection point emits only one light , It's route tracking . Remove from pseudo code for Circulation is enough :

At this time, each pixel is calculated radiance The pseudo-code is as follows :
that N=1 The situation is path tracking , Solved the problem of explosion of light quantity index , So how to solve the problem of recursion depth ?
Russian Roulette !

in other words , We stop and continue to track the path with a certain probability .
Its principle is also relatively simple : Finally, the expectation of probability is still the result of definite integral :


It's right in principle , But there are still some problems : Whether you can reach the light source depends entirely on luck !
Because it is a probability based event , The amount of light emitted by the point and the size of the light source have a great relationship with probability !
A lot of light is wasted !

At this time, other sampling methods need to be considered .
We consider the , No more sampling from all directions , Only consider sampling in the area of the light source .
But there's a problem here , I sample on the light source area , But the solid angle of the hemispherical region of the point is integrated ,
Then we have to write the rendering equation as an integral on the light source . as follows , Need a corresponding relationship : Unit solid angle and unit area





Finally, consider the last case : Whether there are objects blocking the direct illumination

边栏推荐
- unity中物体碰撞反弹(学习)
- [ACNOI2022]总差一步
- [brother hero's July training] day 27: picture
- 社恐适合什么工作?能做自媒体吗?
- selenium+pytest+allure综合练习
- Es6.--promise, task queue and event cycle
- Redis群集
- GAMES101复习:光线追踪(Ray Tracing)
- [wechat applet development (VI)] draw the circular progress bar of the music player
- RTSP/Onvif协议EasyNVR视频平台一键升级方案的开发设计逻辑
猜你喜欢
![[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code](/img/a7/8f0d929457d285adc8020c7f5d33ea.png)
[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code

OA项目之我的审批(会议查询&会议签字)

Interpretation of cesium3dtilesets using customshader and examples of Omni effects

JS event object offsetx/y clientx y pagex y

蓝桥杯原题

JS 事件对象 offsetX/Y clientX Y PageX Y

1313_ Pyserial installation and document generation

【微信小程序开发(六)】绘制音乐播放器环形进度条

“29岁,普通功能测试,我是如何在一周内拿到5份Offer的?”

Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!
随机推荐
小程序已获取数据库合集中的总记录、用户位置,怎么用Aggregate.geoNear将经纬度由近到远排列?
Pytorch 相关-梯度回传
pytest最好的测试框架
[image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code
从硬件编程到软件平台的ci/cd
[red team] att & CK - file hiding
style=“width: ___“ VS width=“___“
Data center construction (III): introduction to data center architecture
牛客-TOP101-BM340
微服务架构统一安全认证设计与实践
数据湖:各模块组件
超参数调整和实验-训练深度神经网络 | PyTorch系列(二十六)
[email protected]注解使用
别再用 offset 和 limit 分页了,性能太差!
【stream】stream流基础知识
Chapter III queue
Redis群集
GBase8s如何在有外键关系的表中删除数据
MySQL index learning
selenium+pytest+allure综合练习

:Box After the light source , That is, light and Box There are no intersections !
&&
: The light source is Box Inside , There are intersections !