Real-Time Rendering大纲

FPS:frames per second

A coarse division of the real-time rendering pipeline into four main
将实时渲染管道粗略划分为四个主要部分

1 stages—application, geometry processing, rasterization, and pixel processing。

阶段-应用、几何处理、光栅化和像素处理。

image.png

1.1 application

the application stage is driven by the application and is therefore typically implemented in software running on general-purpose CPUs.
应用程序阶段由应用程序驱动,因此通常在通用CPU上运行的软件中实现。
include collision detection, global acceleration algorithms, animation, physics simulation, and many others, depending on the type of application.
包括碰撞检测、全局加速算法、动画、物理模拟以及许多其他功能,具体取决于应用程序的类型。

1.2 geometry processing

deals with transforms, projections,and all other types of geometry handling.
处理变换、投影和所有其他类型的几何体处理。
performed on a graphics processing unit (GPU) that contains many programmable cores as well as fixed-operation hardware.
在包含许多可编程内核以及固定操作硬件的图形处理单元(GPU)上执行。
This stage is further divided into the following functional stages:vertex shading, projection, clipping, and screen mapping
此阶段进一步分为以下功能阶段:顶点着色、投影、裁剪和屏幕映射


image.png

1.2.1 Vertex Shading

The vertex shader is now a more general unit dedicated to setting up the data associated with each vertex
顶点着色器现在是一个更通用的单元,专门用于设置与每个顶点相关联的数据
There are two main tasks of vertex shading, namely, to compute the position for a vertex and to evaluate whatever the programmer may like to have as vertex output data, such as a normal and texture coordinates.
顶点着色有两个主要任务,即计算顶点的位置和计算程序员想要作为顶点输出数据的任何内容,例如法线和纹理坐标。

1.2.2 orthographic projection and perspective projection

正交投影和透视投影

1.2.3 Optional Vertex Processing:tessellation,geometry shading, and stream output.

可选的顶点处理:细分、几何体着色和流输出。
每个都是可选的
tessellation:hull shader, tessellator, and domain shader
细分:外壳着色器、细分器和域着色器
geometry shader:it takes in primitives of various sorts and can produce new vertices.
几何体着色器:它接受各种类型的基本体,并可以生成新的顶点。
stream output:This stage lets us use the GPU as a geometry engine。
流输出:此阶段允许我们使用GPU作为几何引擎。
geometry shader and stream output both typically used for particle simulations
几何体着色器和流输出通常都用于粒子模拟

1.2.4 clipping

It is the primitives that are partially inside the view volume that require clipping.
需要剪裁的是部分位于视图体积内的基本体。
The advantage of performing the view transformation and projection before clipping is that it makes the clipping problem consistent; primitives are always clipped against the unit cube.
在裁剪之前执行视图转换和投影的优点是,它使裁剪问题保持一致;基元总是根据单位立方体进行裁剪。

perspective division and normalized device coordinates

透视分割和归一化设备坐标
Finally, perspective division is performed, which places the resulting triangles’ positions into three-dimensional normalized device coordinates.
最后,执行透视划分,将生成的三角形的位置放置到三维归一化设备坐标中。
The last step in the geometry stage is to convert from this space to window coordinates.
几何阶段的最后一步是将此空间转换为窗口坐标。

1.2.5 Screen Mapping

屏幕映射
the screen mapping is a translation followed by a scaling operation.The new x- and ycoordinates are said to be screen coordinates.
屏幕映射是平移,然后是缩放操作。新的x和y坐标称为屏幕坐标。

1.3 rasterization stage

光栅化阶段
typically takes as input three vertices, forming a triangle, and finds all pixels that are considered inside that triangle.
通常以三个顶点作为输入,形成一个三角形,并查找该三角形内考虑的所有像素。
The window coordinates along with this remapped z-value are passed on to the rasterizer stage.
窗口坐标与该重新映射的z值一起被传递到光栅化级。

1.3.1 triangle setup (also called primitive assembly) and triangle traversal

三角形设置(也称为基本体装配)和三角形遍历
triangle setup:In this stage the differentials, edge equations, and other data for the triangle are computed.
三角形设置:在此阶段计算三角形的微分、边方程和其他数据。
triangle traversal:Finding which samples or pixels are inside a triangle is often called triangle traversal. Each triangle fragment’s properties are generated using data interpolated among the three triangle vertices。
三角形遍历:查找三角形内有哪些样本或像素通常称为三角形遍历。每个三角形片段的属性是使用在三个三角形顶点之间插值的数据生成的。

1.4 pixel processing stage

像素处理阶段
executes a program per pixel to determine its color and may perform depth testing to see whether it is visible or not. It may also perform per-pixel operations such as blending the newly computed color with a previous color.
按像素执行程序以确定其颜色,并可执行深度测试以查看其是否可见。它还可以执行每个像素的操作,例如将新计算的颜色与先前的颜色混合。
The rasterization and pixelprocessing stages are also processed entirely on the GPU.
光栅化和像素处理阶段也完全在GPU上处理。
pixel processing stage is divided into pixel shading and merging。
像素处理阶段分为像素着色和像素合并两个阶段。

1.4.1 Pixel Shading

像素着色
Any per-pixel shading computations are performed here, using the interpolated shading data as input. The end result is one or more colors to be passed on to the next stage.
使用插值的着色数据作为输入,在此执行任何逐像素着色计算。最终结果是要传递到下一阶段的一种或多种颜色。

1.4.2 Merging

合并
It is the responsibility of the merging stage to combine the fragment color produced by the pixel shading stage with the color currently stored in the buffer.
合并阶段负责将像素着色阶段产生的碎片颜色与当前存储在缓冲器中的颜色组合。
This stage is also responsible for resolving visibility.
这一阶段还负责解决可见性问题。
Transparency is one of the major weaknesses of the basic z-buffer.
透明度是基本z-Buffer的主要弱点之一。
contain color buffer, z-buffer, alpha channel, stencil buffer.
包含颜色缓冲区、z缓冲区、Alpha通道、模板缓冲区。
However, some APIs have support for raster order views, also called pixel shader ordering, which enable programmable blending capabilities.
但是,一些API支持栅格顺序视图,也称为像素着色器排序,它支持可编程混合功能。
The framebuffer generally consists of all the buffers on a system.
帧缓冲区通常由系统上的所有缓冲区组成。
double buffering:back buffer, front buffer.The swapping often occurs during vertical retrace.
双缓冲:后缓冲、前缓冲。垂直回溯时经常发生交换。

2 The Graphics Processing Unit

图形处理单元
single instruction, multiple data(SIMD)
单指令、多数据(SIMD)。
Threads that use the same shader program are bundled into groups, called warps by NVIDIA and wavefronts by AMD.
使用相同着色器程序的线程被捆绑到组中,NVIDIA将其称为(扭曲)(?),AMD将其称为(波前)(?)。

image.png

instruction set architecture (ISA)
指令集体系结构
A processor that implements this model is called a common-shader core in DirectX, and a GPU with such cores is said to have a unified shader architecture.
指令集体系结构(ISA)。
在DirectX中,实现此模型的处理器称为通用着色器核心,具有此类核心的GPU被称为具有统一着色器体系结构。

Shaders are programmed using C-like shading languages such as DirectX’s High-Level Shading Language (HLSL) and the OpenGL Shading Language (GLSL). DirectX’s HLSL can be compiled to virtual machine bytecode, also called the intermediate language (IL or DXIL), to provide hardware independence.
着色器使用类似C的着色语言编程,例如DirectX的高级着色语言(HLSL)和OpenGL着色语言(GLSL)。DirectX的HLSL可以编译成虚拟机字节码,也称为中间语言(IL或DXIL),以提供硬件独立性。

The basic data types are 32-bit single-precision floating point scalars and vectors
基本数据类型为32位单精度浮点标量和矢量

A draw call invokes the graphics API to draw a group of primitives, so causing the graphics pipeline to execute and run its shaders.
绘制调用调用图形API来绘制一组基元,从而导致图形管道执行和运行其着色器。
Each programmable shader stage has two types of inputs: uniform inputs, with values that remain constant throughout a draw call (but can be changed between draw calls), and varying inputs, data that come from the triangle’s vertices or from rasterization.
每个可编程着色器阶段都有两种类型的输入:统一输入,值在绘制调用期间保持不变(但可以在绘制调用之间更改);变化输入,即来自三角形顶点或光栅化的数据。

The number of available constant registers for uniforms is much larger than those registers available for varying inputs or outputs.
可用于同类的常量寄存器的数量比可用于变化输入或输出的寄存器多得多。
The virtual machine also has general-purpose temporary registers, which are used for scratch space.
虚拟机还具有通用临时寄存器,用于临时空间。

The term flow control refers to the use of branching instructions to change the flow of code execution.
术语流控制指的是使用分支指令来更改代码执行流。
Static flow control branches are based on the values of uniform inputs.
静态流量控制分支基于统一输入的值。
Dynamic flow control is based on the values of varying inputs。
动态流量控制基于可变输入的值。

2.1. vertex shader

顶点着色器。
some data manipulation happens before this stage. In what DirectX calls the input assembler [175, 530, 1208], several streams of data can be woven together to form the sets of vertices and primitives sent down the pipeline.
一些数据操作发生在此阶段之前。在DirectX所称的输入汇编器[175,530,1208]中,几个数据流可以编织在一起,形成沿管道发送的顶点和基元集。

**blending for animating joints
**用于设置关节动画的混合。
**silhouette rendering
**轮廓渲染。
**Object generation, by creating a mesh only once and having it be deformed by the vertex shader.
**对象生成,只创建一次网格,并使其由顶点着色器变形。
**Animating character’s bodies and faces using skinning and morphing techniques.
**使用蒙皮和变形技术设置角色身体和面部的动画。
**Procedural deformations, such as the movement of flags, cloth, or water
**程序变形,如旗帜、布料或水的移动。
**Particle creation, by sending degenerate (no area) meshes down the pipeline and having these be given an area as needed.
**粒子创建,将退化(无区域)网格沿管道发送,并根据需要为这些网格指定一个区域。
**Lens distortion, heat haze, water ripples, page curls, and other effects, by using the entire framebuffer’s contents as a texture on a screen-aligned mesh undergoing procedural deformation.
**镜头扭曲、热雾、水纹、页面卷曲和其他效果,方法是将整个帧缓冲区的内容用作经过程序变形的屏幕对齐网格上的纹理。
**Applying terrain height fields by using vertex texture fetch
**使用顶点纹理提取应用地形高度场

2.2 tessellation stage

曲面细分
Beyond memory savings, this feature can keep the bus between CPU and GPU from becoming the bottleneck for an animated character or object whose shape is changing each frame.
除了节省内存之外,这一特性还可以防止中央处理器和图形处理器之间的总线成为动画角色或对象的瓶颈,这些角色或对象的形状每帧都在变化。
hull shader, tessellator, and domain shader
外壳着色器、细分器和域着色器。
In OpenGL the hull shader is the tessellation control shader and the domain shader the tessellation evaluation shader
在OpenGL中,外壳着色器是细分控制着色器,域着色器是细分评估着色器
the input to the hull shader is a special patch primitive
外壳着色器的输入是一个特殊的面片图元
The hull shader has two functions. First, it tells the tessellator how many triangles should be generated, and in what configuration. Second, it performs processing on each of the control points.
外壳着色器有两个功能。首先,它告诉细分器应该生成多少个三角形,以及以什么配置生成。其次,它对每个控制点执行处理。
Also, optionally, the hull shader can modify the incoming patch description, adding or removing control points as desired.
另外,可选地,外壳着色器可以修改输入的面片描述,根据需要添加或移除控制点。
The hull shader outputs its set of control points, along with the tessellation control data, to the domain shader.
外壳着色器将其一组控制点以及细分控制数据输出到域着色器。


image.png

The tessellator is a fixed-function stage in the pipeline
细分器是管道中的固定功能阶段
It has the task of adding several new vertices for the domain shader to process.
它的任务是为域着色器添加几个要处理的新顶点。
The hull shader sends the tessellator information about what type of tessellation surface is desired: triangle, quadrilateral, or isoline. Isolines are sets of line strips, sometimes used for hair rendering
外壳着色器向细分器发送关于所需细分曲面类型的信息:三角形、四边形或等值线。等值线是一组线条,有时用于头发渲染
The other important values sent by the hull shader are the tessellation factors (tessellation levels in OpenGL). These are of two types: inner and outer edge. The two inner factors determine how much tessellation occurs inside the triangle or quadrilateral. The outer factors determine how much each exterior edge is split
外壳着色器发送的其他重要值是细分因子(OpenGL中的细分级别)。它们有两种类型:内边缘和外边缘。这两个内部因素决定了三角形或四边形内部有多少曲面细分。外部因素决定了每个外部边缘的分割程度
The hull shader always outputs a patch, a set of control point locations,sends it to the domain shader. sends it to the domain shader.
外壳着色器总是输出一个面片,即一组控制点位置,将其发送到域着色器。
The control points for the curved surface from the hull shader are used by each invocation of the domain shader to compute the output values for each vertex.
域着色器的每次调用都使用外壳着色器中曲面的控制点来计算每个顶点的输出值。
The domain shader has a data flow pattern like that of a vertex shader, with each input vertex from the tessellator being processed and generating a corresponding output vertex.
域着色器具有类似于顶点着色器的数据流模式,处理来自细分的每个输入顶点并生成相应的输出顶点。

The tessellator performs an involved but fixed-function process of generating the vertices, giving them positions, and specifying what triangles or lines they form
细分器执行一个复杂但功能固定的过程,生成顶点,给它们位置,并指定它们形成什么三角形或线。
The domain shader takes the barycentric coordinates generated for each point and uses these in the patch’s evaluation equation to generate the position, normal, texture coordinates, and other vertex information desired.
域着色器获取为每个点生成的重心坐标,并在面片的计算公式中使用这些坐标来生成位置、法线、纹理坐标和其他所需的顶点信息。

2.3. The geometry shader

The geometry shader is designed for modifying incoming data or making a limited number of copies.
几何着色器设计用于修改传入数据或生成有限的副本数量。

2.4. Stream Output

After vertices are processed by the vertex shader (and, optionally, the tessellation and geometry shaders), these can be output in a stream, i.e., an ordered array, in addition to being sent on to the rasterization stage.
顶点着色器(以及可选的细分和几何体着色器)处理顶点后,除了发送到光栅化阶段外,还可以在流(即有序数组)中输出这些顶点。
the focus of much of its use is transforming vertices and returning them for further processing.
它的主要用途是变换顶点并返回它们进行进一步处理。
Primitives are guaranteed to be sent to the stream output target in the order that they were input, meaning the vertex order will be maintained
基元被保证按照它们被输入的顺序被发送到流输出目标,这意味着顶点顺序将保持不变

2.5. the pixel shader

This piece of a triangle partially or fully overlapping the pixel is called a fragment.
部分或完全与像素重叠的这一段三角形称为片元。
Normally we use perspective-correct interpolation, so that the worldspace distances between pixel surface locations increase as an object recedes in the distance.
通常我们使用透视校正插值,因此像素表面位置之间的世界空间距离随着对象在距离中的后退而增加。
Other interpolation options are available, such as screen-space interpolation, where perspective projection is not taken into account.
其他插值选项也可用,例如屏幕空间插值,其中不考虑透视投影。
A pixel shader also has the unique ability to discard an incoming fragment, i.e., generate no output.
像素着色器还具有丢弃传入片段(即,不生成输出)的独特能力。
multiple render targets (MRT):The number of instructions a pixel shader can execute has grown considerably over time.This increase gave rise to the idea of multiple render targets (MRT). Instead of sending results of a pixel shader’s program to just the color and z-buffer, multiple sets of values could be generated for each fragment and saved to different buffers, each called a render target.
多渲染目标:随着时间的推移,像素着色器可以执行的指令数量大幅增加。这一增加引发了多渲染目标(MRT)的概念。不是只将像素着色器程序的结果发送到颜色和z缓冲区,而是可以为每个片段生成多组值,并将其保存到不同的缓冲区,每个缓冲区称为渲染目标。
deferred shading:A single rendering pass could generate a color image in one target, object identifiers in another, and world-space distances in a third. This ability has also given rise to a different type of rendering pipeline, called deferred shading, where visibility and shading are done in separate passes.
延迟着色:单个渲染过程可以在一个目标中生成彩色图像,在另一个目标中生成对象标识符,在第三个目标中生成世界空间距离。此功能还产生了一种不同类型的渲染管道,称为延迟着色,其中可见性和着色在单独的过程中完成。
UAV:DirectX 11 introduced a buffer type that allows write access to any location, the unordered access view (UAV).OpenGL 4.3 calls this a shader storage buffer object (SSBO).
无序访问视图:DirectX 11引入了一种允许对任何位置进行写访问的缓冲区类型,即无序访问视图(UAV)。OpenGL 4.3称之为着色器存储缓冲对象(SSBO)。
In the standard pipeline, the fragment results are sorted in the merger stage before being processed.
在标准管道中,片段结果在被处理之前在合并阶段被排序。
ROVs:Rasterizer order views (ROVs) were introduced in DirectX 11.3 to enforce an order of execution.
光栅化顺序视图:DirectX 11.3中引入了光栅化顺序视图(ROV)来强制执行顺序。

2.6.the merging stage

the merging stage is where the depths and colors of the individual fragments (generated in the pixel shader) are combined with the framebuffer. DirectX calls this stage the output merger;OpenGL refers to it as per-sample operations.
合并阶段是将各个片段(在像素着色器中生成)的深度和颜色与帧缓冲区相结合。DirectX将这个阶段称为输出合并;OpenGL称之为按样本操作。
On most traditional pipeline diagrams (including our own), this stage is where stencil-buffer and z-buffer operations occur.
在大多数传统的管道图上(包括我们自己的),这个阶段是模板缓冲和z缓冲操作发生的地方。
If the fragment is visible, another operation that takes place in this stage is color blending.
如果片段是可见的,在这个阶段发生的另一个操作是颜色混合。
early-z:To avoid waste, many GPUs perform some merge testing before the pixel shader is executed。The fragment’s z-depth (and whatever else is in use, such as the stencil buffer or scissoring) is used for testing visibility.This functionality is called early-z
为了避免浪费,许多图形处理器在执行像素着色器之前会执行一些合并测试。片段的z深度(以及其他正在使用的东西,如模板缓冲区或剪枝)用于测试可见性。这个功能被称为early-z
Color blending in particular can be set up to perform a large number of different operations. The most common are combinations of multiplication, addition, and subtraction involving the color and alpha values, but other operations are possible, such as minimum and maximum, as well as bitwise logic operations.
尤其是颜色混合可以设置为执行大量不同的操作。最常见的是涉及颜色和alpha值的乘法、加法和减法的组合,但其他操作也是可能的,例如最小值和最大值,以及按位逻辑操作。
dual source-color blending:DirectX 10 added the capability to blend two colors from the pixel shader with the framebuffer color. This capability is called dual source-color blending and cannot be used in conjunction with multiple render targets.
DirectX 10增加了将像素着色器中的两种颜色与帧缓冲区颜色混合的功能。这种功能称为双源颜色混合,不能与多个渲染目标结合使用。

2.6.the Compute Shader

One important advantage of compute shaders is that they can access data generated on the GPU. Sending data from the GPU to the CPU incurs a delay, so performance can be improved if processing and results can be kept resident on the GPU [1403]. Post-processing, where a rendered image is modified in some way, is a common use of compute shaders.
计算着色器的一个重要优势是,它们可以访问GPU上生成的数据。将数据从图形处理器发送到中央处理器会产生延迟,因此如果处理和结果能够驻留在图形处理器上,性能可以得到提高[1403]。后处理是计算着色器的常见用途,在后处理中,渲染图像会以某种方式进行修改。
Compute shaders are also useful for particle systems, mesh processing such as facial animation [134], culling [1883, 1884], image filtering [1102, 1710], improving depth precision [991], shadows [865], depth of field [764], and any other tasks where a set of GPU processors can be brought to bear.
计算着色器还可用于粒子系统、网格处理,如面部动画[134]、剔除[1883、1884]、图像过滤[1102、1710]、提高深度精度[991]、阴影[865]、景深[764]以及一组GPU处理器可以承担的任何其他任务。

Chapter 4 Transforms
A transform is an operation that takes entities such as points, vectors, or colors and converts them in some way.
变换是取点、矢量或颜色等实体并以某种方式转换它们的操作。
A linear transform is one that preserves vector addition and scalar multiplication.
线性变换是保留向量加法和标量乘法的变换。
Scaling and rotation transforms, in fact all linear transforms for three-element vectors, can be represented using a 3 × 3 matrix.
缩放和旋转变换,实际上是三元素向量的所有线性变换,可以用一个3 × 3矩阵来表示。


image.png

To prove that this is linear, the two conditions (Equations 4.1 and 4.2) need to be fulfilled.
为了证明这是线性的,需要满足两个条件(等式4.1和4.2)。

58

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,271评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,275评论 2 380
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,151评论 0 336
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,550评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,553评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,559评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,924评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,580评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,826评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,578评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,661评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,363评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,940评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,926评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,156评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,872评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,391评论 2 342

推荐阅读更多精彩内容