当前位置:网站首页>Games101 notes (III)
Games101 notes (III)
2022-07-05 16:44:00 【Small margin, rush】
Catalog
Find the intersection of light and object surface
Encircling nuclear acceleration
Traverse all pixels to generate light
Two 、 Accelerate the structure
Spatial Partitions( Space division )
Object Partition & Bounding Volume Hierarchy(BVH)
Four 、 Light propagation and global illumination
Monte Carlo Integration Monte Carlo integral
One 、 Ray tracing
Rasterization cannot handle the global effect well , So use ray tracing
Due to the algorithm principle of rasterization , There are many performance limitations , such as :
- Unable to represent real soft shadows
- Unable to show rough reflection effects such as ground glass
- Unable to show indirect illumination ( Only global illumination can be used instead )
The light
- Light travels in a straight line
- There is no collision between light rays , Each spreads its own
- Light is emitted from the light source, and then reflected and refracted for many times , Finally, it is introduced into eye in . It can also be considered that the light path is reversible , from eye The emitted perceptual light can return to the light source in the same way
- Ray tracing is to simulate the process of continuous light ejection
- Refract and reflect light everywhere light Calculate once ( Whether it is shadow in ), Add the shading values of all points
Based on “ Optical path reversibility ” for , For efficiency , The method of rendering is to send out from the camera “ Perceiving light ” Rendering .
Definition of light : It's rays , A point and a direction .r(t) Is any point on the light
Find the intersection of light and object surface
Explicit surfaces are described by triangular meshes , Then the problem becomes the intersection of light and triangle
Define the plane through the three vertices of the triangle , Then intersect with the ray , Satisfaction coefficient b1,b2,(1-b1,b2) All are greater than 0, That is, there is an inner intersection of triangles , The specific solution is to solve linear equations by Clem's law .
Encircling nuclear acceleration
Bounding Box(AABB Axis-Aligned Bounding Box, Axis alignment bounding box )
Calculate the time to enter the three opposite sides and the time to work out the three opposite sides , Only when all three opposite sides enter the cube , Go out and leave . So the time to enter the cube is the maximum time to enter the three opposite sides , The time to leave the cube is the minimum time to leave three opposite sides .
In three dimensions , Light enters AABB Time for , It is the time to enter three groups at the same time , Light out AABB Time for , It's the time opposite any group . therefore , Light goes AABB Time for , Is the latest tmin Time ,tenter=max{tmin}, Out AABB Time for ,texit=min{tmax}, yes tmax The earliest time , If tenter<texit, It means that the light is AABB For some time , That is, there may be an intersection with the object in the surrounding core . There are several special cases
- texit <0 ,AABB Behind the light source
- texit >=0 && tenter < 0, The light source is AABB in
inline bool Bounds3::IntersectP(const Ray& ray, const Vector3f& invDir,
const std::array<int, 3>& dirIsNeg) const
{
// invDir: ray direction(x,y,z), invDir=(1.0/x,1.0/y,1.0/z), use this because Multiply is faster that Division
// dirIsNeg: ray direction(x,y,z), dirIsNeg=[int(x>0),int(y>0),int(z>0)], use this to simplify your logic
// TODO test if ray bound intersects
float x_min = (pMin.x - ray.origin.x) * invDir[0];
float y_min = (pMin.y - ray.origin.y) * invDir[1];
float z_min = (pMin.z - ray.origin.z) * invDir[2];
float x_max = (pMax.x - ray.origin.x) * invDir[0];
float y_max = (pMax.y - ray.origin.y) * invDir[1];
float z_max = (pMax.y - ray.origin.y) * invDir[2];
if (!dirIsNeg[0])
{
swap(x_min, x_max);
}
if (!dirIsNeg[1])
{
swap(y_min, y_max);
}
if (!dirIsNeg[2])
{
swap(z_min, z_max);
}
float t_enter = max(x_min, max(y_min, z_min));
float t_exit = min(x_max, min(y_max, z_max));
return t_enter < t_exit && t_exit >= 0;
}
repair :
Traverse all pixels to generate light
The purpose of the renderer is to assign colors to each pixel of a frame
About generating rays , What we need is to find these pixels in grid space (raster space) Coordinates in and in world space (world space) The relationship between the coordinates of the same pixel expressed in .
First, we need to normalize the size of each frame (normalize) Pixel position (pixel position), The new normalized pixel coordinates are defined in the normalized device coordinate system (NDC space):
We add a small displacement in the pixel position (0.5), Because we want the final camera light to pass through the middle of the pixel .
Two 、 Accelerate the structure
Spatial Partitions( Space division )
The simplest form of space division :Uniform Grids ( Divide evenly ). Divide the space evenly into several grids of equal size , Record whether there is an object surface in each grid , Then the light passes through the scene , Judge whether the grid along the way has an object surface : If exist , Judge whether it intersects with the object surface ; If it does not exist ,continue.
If it is too big , The extreme condition is a whole piece , Then there is no acceleration effect ; If it's too small , There are a lot of cubes in space , That will add a lot of computation .
3D It should be divided into :cell = 27*objs
Uneven division
The first one is , The most intuitionistic ,oct-tree, Octree , Each grid is divided into eight parts , Until there are enough objects or no objects in the grid .
The second kind ,bsp-tree, Divide the space in two each time , The direction of the divided face can be arbitrary , The arbitrariness of the dividing surface destroys AABB The nature of .
The third kind of ,kd-tree, The course focuses on the acceleration structure , One knife at a time
Use kd-tree Building an acceleration structure has the following characteristics
- The split plane splits along the axis
- Binary tree shape
- All the objects , Stored on leaf nodes
Light passes through space , Intersection with each layer node in turn , If it does not intersect a node , Then the ray will not intersect all nodes on the subtree with this node as the root node ; If it intersects a node , Then you need to continue to judge whether it intersects with its left and right child nodes , Until the leaf node intersects with the ray , Then judge whether the object in the leaf node intersects with the light .
Object Partition & Bounding Volume Hierarchy(BVH)
BVH How to build it :
- Find a surrounding core
- In some way , Divide the object surrounding the core into two parts
- The two parts recalculate the surrounding kernel
- And then according to kd-tree Thought , Circular dichotomy recursion according to different dimensions , Until the suspension conditions are met ( The number of objects is small enough )
- Store the object on each leaf node , Other nodes are used to speed up judgment
Every space divided by space has no intersection , But objects can span multiple spaces ; The space divided by objects may have intersection , But objects only exist in one space .
Intersection BVHAccel::getIntersection(BVHBuildNode* node, const Ray& ray) const
{
// TODO Traverse the BVH to find intersection
Intersection myIntersection;
if (node == nullptr || !node->bounds.IntersectP(ray, ray.direction_inv, { 0,0,0 }))
return myIntersection;
if (node->left == nullptr && node->right == nullptr)
{
myIntersection = node->object->getIntersection(ray);
return myIntersection;
}
Intersection l1, l2;
l1 = getIntersection(node->left, ray);
l2 = getIntersection(node->right, ray);
myIntersection = l1.distance <= l2.distance ? l1 : l2;
return myIntersection;
}
3、 ... and 、 Radiometry
Radiometry defines a set of physical models of illumination , Is the basis of ray tracing .
Basic concepts :Radiant Energy and Flux (Power) Energy and power
Definition :Radiant Energy The energy of electromagnetic radiation ( The energy radiated by the light source ) Q[J=Joule]
Definition :Radiant Flux (Power) :energy per unit time ( power ) Φ = dQ/dt[w=watt][lm=lumen]
Radiant Intensity, Power per unit solid angle
( Solid angle is a three-dimensional extension of two-dimensional radian angle , In two dimensions , We use the ratio of arc length to radius to describe the angle , As the radius increases , The arc length increases proportionally , This ratio remains unchanged , Meet the needs of description . In three dimensions , Look at the object from the center of the ball , Intersect with the unit sphere to form an area , The ratio of area to radius squared defines the solid angle , It is essentially a cone angle . Use θ( Vertical angle ),Φ( Horizontal angle ) Describe the direction vector , Bonding radius r You can determine the position of any point in space , The radius of the unit sphere is 1.)
The unit area on the sphere is :dA=(rdθ)(rsinθdΦ)
The unit solid angle is :dω= dA/(rr)=sinθdθdΦ
At the unit solid angle , Power per unit projected area .
ncident Radiance( The incident ), That is to say Irradiance It will radiate in all directions , But measuring a certain direction irradiance became Radiance, You can see it Radiance Than Irradiance More directionality .
Exiting Radiance( Exit ), It is emitted by the unit projected area intensity.
dA The energy received by the area from all aspects is Irradiance, And the energy incident in one direction is Radiance, therefore Irradiance and Radiance The essential difference is directionality , For all directions Radiance Integral can get Irradiance.
Four 、 Light propagation and global illumination
A beam of light hits a plane , The plane absorbs the energy of this light . Then this plane acts as an energy source to radiate energy in all directions , Use BRDF(Bidirectional Reflectance Distribution Function), Bidirectional reflection distribution equation to describe the energy distribution .
Integrate the energy emitted in each direction , You can get the energy absorbed by the plane . If the plane reflects more than just light , At the same time, it is also a light source , This part of energy needs to be added .
L=E+KL:L,E Is a vector .K Is an operator that represents the integral to the kernel
- E, Constant term , Light from its own light source
- KE, One time , The light source directly irradiates the shading points , Direct light , There is an ejection of light
- K2E, Second term , Indirect illumination , Light is ejected twice
Global illumination , It is a collection of direct light and indirect light , And the coloring in rasterization , Only direct lighting and light source itself , namely E+KE. The more higher-order terms are introduced into the global illumination , That is, the closer to the real scene , But the effect of higher-order terms is not linear , As the number increases , The later improvements tend to be more saturated .
Monte Carlo Integration Monte Carlo integral
The rendering equation satisfies the real physical laws , It can describe the propagation of light , But there is an integral term in the rendering equation , This integral function is difficult to solve the integral by directly writing the mathematical analytic formula .
Monte Carlo method can solve mathematical problems by random sampling , For solving definite integral problems , An approximate numerical solution can be estimated by Monte Carlo method . We regard the integral variable as a continuous random variable , Every sampling , Just use the function value mapped by the sampled variables , Represents the function value corresponding to all variables in all integral intervals , Multiple sampling gradually approximates the integral value of the real function in the integral domain .
In solving the integral , We just need to know what the variable corresponds to Function value and Probability density distribution that will do . Divide the function value by the probability density , It is equivalent to the process of estimating the population with a single use of samples , Then estimate and average several times to approximate the true value .
Monte Carlo integral is an unbiased estimation , By calculating the mathematical expectation of the integral formula , It can be found that the expectation is the definite integral value .
Ray tracing
Whitted-style ray tracing.
- Light hits an object , Then connect with the light source .
- Encounter smooth objects , Reflection and refraction occur .
- Encounter diffuse objects , The light stops .
Light meets diffuse objects , The light should not stop , Therefore, the object rendering effect of diffuse material is not realistic (glossy reflection), And it ignores the light emitted by diffuse objects , The environment lacks the effect of its irradiation ( Brightness and color ).
Rendering equations have two characteristics :
- Contains an integral term on the hemisphere
- Because there is no distinction between light sources ( Light source and reflected light ), Solving equations is a recursive process
1. Direct light
2. Global illumination
Global illumination is direct illumination plus indirect illumination
use n=1 Do Monte Carlo integral , It's called Path Tracing.
Russian Roulette
Is to set a probability that the light will continue to eject , That is, through probability , Let recursion terminate , Before starting recursion , First calculate a random number , If within the probability range , Continue iteration ; otherwise return, The result of illumination is 0.
边栏推荐
- [js] skill simplification if empty judgment
- If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats
- Fleet tutorial 09 basic introduction to navigationrail (tutorial includes source code)
- 公司自用的国产API管理神器
- Google Earth Engine(GEE)——Kernel核函数简单介绍以及灰度共生矩阵
- Dare not buy thinking
- One click installation script enables rapid deployment of graylog server 4.2.10 stand-alone version
- Data Lake (XIV): spark and iceberg integrated query operation
- Jarvis OJ Flag
- Seaborn绘制11个柱状图
猜你喜欢
The new version of effect editor is online! 3D rendering, labeling, and animation, this time an editor is enough
ES6 deep - ES6 class class
文件操作--I/O
【 brosser le titre 】 chemise culturelle de l'usine d'oies
Fleet tutorial 09 basic introduction to navigationrail (tutorial includes source code)
Solve cmakelist find_ Package cannot find Qt5, ECM cannot be found
Accès aux données - intégration du cadre d'entité
Spring Festival Limited "forget trouble in the year of the ox" gift bag waiting for you to pick it up~
深潜Kotlin协程(二十一):Flow 生命周期函数
如何安装mysql
随机推荐
有序链表集合求交集 方法 总结
How was the middle table destroyed?
Hiengine: comparable to the local cloud native memory database engine
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
Quelques réflexions cognitives
单商户 V4.4,初心未变,实力依旧!
Cartoon: what is distributed transaction?
scratch五彩糖葫芦 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
Fleet tutorial 09 basic introduction to navigationrail (tutorial includes source code)
Mongodb getting started Tutorial Part 04 mongodb client
Oneforall installation and use
What is the difference between EDI license and ICP business license
【刷题篇】鹅厂文化衫问题
Bs-xx-042 implementation of personnel management system based on SSM
【学术相关】多位博士毕业去了三四流高校,目前惨不忍睹……
ES6 deep - ES6 class class
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
Practice independent and controllable 3.0 and truly create the open source business of the Chinese people
One click installation script enables rapid deployment of graylog server 4.2.10 stand-alone version