GPU Pro2 - 1.Terrain and Ocean Rendering with Hardware Tessellation

最近时间多了起来,准备捡起扔下了的渲染部分的知识。想拜读下GPU Pro系列并且做个笔记,不知道自己能否坚持下来,但愿可以吧。自己能力也有限,写的东西也只是自己的理解,肯定有很多理解不到位甚至错误的地方,也希望如果哪位大神看到了可以指正。关于tessellation,这篇博客介绍的很好https://blog.csdn.net/weixin_43675955/article/details/85005229

如果想让场景更真实,你可能需要细节更高,面数更多的模型,但是这样会使得cpu计算增加,运行变慢。

The best solution for tessellation is the recently developed tessellator stage in DirectX 11. This stage, together with the hull and the domain shader, allows the programmer to tessellate very quickly into the GPU. With this method you can send low-level detail meshes to the GPU and generate the missing geometry to the GPU depending on the camera distance, angle, or whatever you want. 

Tessellation(细分曲面)技术是将低模细节度低的模型输入至gpu中,在DirectX11之后,在hull 和 domain shader中可以通过tessellation快速的增加细节来增强表现力,却又不需要损耗cpu的性能。

 

 

通过DirectX 11中的渲染流水线可以看出,在Vertex Shader和 Geometry Shader之间插入了 Hull Shader Stage ,Tessellator Stage 和 Domain Shader Stage三个阶段,用于处理Tessellation。

Hull Shader Stage

Hull shader 的 输入比较特殊,叫做 contral point patch list。常规情况下,vertex shader的输出是顶点, 但是如果要用硬件曲面细分,那么顶点着色器输出就不再是顶点,而是control point的patch,一个patch包含多个control point,最多可以包含32个。vertex shader输出patch给HS用。

Hull shader 的输出包含两部分,一部分是control points(可以在Hull shader阶段进行修改),另一部分是一些常量,用于后续的tessellator stage 和 domain shader stage。为了计算这两部分输出,在该阶段需要有两个函数。

第一个函数叫做Constant Hull Shader,这个函数executed for every patch,也就是以patch为单位执行,在这个函数里,设置了tessellation的一些参数。

由示例代码可以看出,该函数的输入InputPatch是一个模板类,对应的是顶点着色器的输出,如果这里要用曲面细分的话,就不能在VS中乘以世界和摄像机投影矩阵(这是因为在tessellation中新加入了细节,新生成了顶点,如果在vertex shader中就做完了这些操作,新生成的顶点咋办呐),而是要留到细分结束后再变换(如果有几何着色器的话就留到几何着色器阶段再变换)。然后这里可以用SV_PrimitiveID获取Primitive的id。这里可以把细分等级和离摄像机的远近、屏幕覆盖范围、朝向、粗糙度等挂钩,而不是写一个定的值,可以起到优化的效果。

该函数的输出有两个值,分别为SV_TessFactor和SV_InsideTessFactor,前者是边的细分等级,后者是面片中心的细分等级。前者有几条边就要输出几个,分别对应每条边的参数,后者则要输出两个,分别对应的是u和v方向。

struct PatchTess
{
float EdgeTess[4] : SV_TessFactor;
float InsideTess[2] : SV_InsideTessFactor;
// Additional info you want associated per patch.
};
PatchTess ConstantHS(InputPatch<VertexOut, 4> patch,
uint patchID : SV_PrimitiveID)
{
PatchTess pt;
// Uniformly tessellate the patch 3 times.
pt.EdgeTess[0] = 3; // Left edge
pt.EdgeTess[1] = 3; // Top edge
pt.EdgeTess[2] = 3; // Right edge
pt.EdgeTess[3] = 3; // Bottom edge
pt.InsideTess[0] = 3; // u-axis (columns)
pt.InsideTess[1] = 3; // v-axis (rows)
return pt;
}

第二个函数叫做Control Point Hull Shader,这个部分是每个control point都调用一次,因此和顶点着色器类似,只不过对象是control point,在这个阶段我们可以改变曲面的表达形式,比如把输入的三角面(三个control point)变成由包含十个control point的patch控制的贝塞尔曲线输出,等等。
Control Point HS要定义不少属性,其中domain是patch type,可选的有tri,quad或者isoline。
partitioining是细分模式,integer的细分等级会突变,而fractional_odd或者fractional_even的细分等级会渐变,顶点会逐渐移动直到消失,而不会突然pop出来或者消失。
outputtopology输出的三角面的winding order,有triangle_cw,triangle_ccw,line这三个选项
outputcontrolpoints是输出顶点的数量,也就是hs的执行次数,可以用SV_OutputControlPointID获取当前Control Point的ID。
patchconstantfunc则是constantHS的名字
maxtessfactor是最大细分数量,dx11最高支持到64,这里可以手动设置得更低。
 

struct HullOut
{
	float3 PosL : POSITION;
};
[domain(“quad”)]
[partitioning(“integer”)]
[outputtopology(“triangle_cw”)]
[outputcontrolpoints(4)]
[patchconstantfunc(“ConstantHS”)]
[maxtessfactor(64.0f)]
HullOut HS(InputPatch<VertexOut, 4> p,
uint i : SV_OutputControlPointID,
uint patchId : SV_PrimitiveID)
{
	HullOut hout;
	hout.PosL = p[i].PosL;
	return hout;
}

The Tessellation Stage

Hull shader结束之后就是细分阶段,该阶段由硬件完成,不可编程,通过Hull shader中设置的参数,该阶段会新生成顶点,但是得出的只是顶点的uv,实际的位置等信息是在之后的domain shadr中进行计算。

在这里,可以理解下之前设置的参数,SV_TessFactor和SV_InsideTessFactor。

对于四边形图元,边的顺序是左上右下顺时针。如下图中的第一个图:每个边的参数都为4,也就是说每个边等分成了四份。中心的参数为(4,4),也就是中心也等分成了4份。

再如下图中的第三个图:左边和上边参数为2,则二等分,右边和下边为4则是4等分。中心参数为2和4,分别对应u方向和v方向,所以中心部分横向(u方向)二等分,纵向(v方向)四等分。

对于三角形图元,细分操作同,只不过中心参数只有一个,中心的操作是在每个三角形定点到中心的延长线方向进行。

Domain Shader Stage

In the domain shader we have to reconstruct every final vertex and we have to calculate the position, normal, and texture coordinates. This is the part where the difference between terrain and ocean rendering is more important.

该阶段的输入是细分好了的曲面,在该阶段我们要做的是根据uv来算出顶点的位置,法线和真正的纹理坐标。然后如果没有几何着色器的话,我们需要在这个阶段把顶点变换到屏幕坐标里。
这里说的给定uv是针对四边面,如果用的是三个control point的patch,那么这里给定的是质心坐标系下的uvw。

Terrain&Ocean

说实话,后边这些没有太看懂。。还望各位大佬指导,大体总结几个点吧:

1.对于tessellation新生成的顶点,x和z方向的坐标可以通过patch中已有顶点的位置用插值方式得到。对于Terrain,y方向的坐标可以通过高度图和法线图得到已有顶点的高度参数后进行插值,对于Ocean,y坐标可以通过波浪函数计算得到。

2.很重要的一点是使用一些技术来计算tessellation factor,也就是tessellation的参数。比如对于某条边,它必然属于两个patch,要确保在这两个patch中该边的参数一致。再比如通过mipmap参数计算tessellation参数,距离摄像机越近的,tessellation参数越大,距离摄像机越远的地方,tessellation参数越小。

 

 


 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Wolfgang Engel’s GPU Pro 360 Guide to Geometry Manipulation gathers all the cutting-edge information from his previous seven GPU Pro volumes into a convenient single source anthology that covers geometry manipulation in computer graphics. This volume is complete with 19 articles by leading programmers that focus on the ability of graphics processing units to process and generate geometry in exciting ways. GPU Pro 360 Guide to Geometry Manipulation is comprised of ready-to-use ideas and efficient procedures that can help solve many computer graphics programming challenges that may arise. “Geometry manipulation” focuses on the ability of graphics processor units (GPUs) to process and generate geometry in exciting and interesting ways. Tamy Boubekeur covers Phong Tesselation in the chapter “As Simple as Possible Tessellation for Interactive Applications.” This operator is simpler than GPU subdivision surfaces and their approximations but succeeds at hiding standard “polygonization” artifacts often encountered on mesh silhouettes and interior contours. Phong Tessellation can be implemented on today’s GPU using either uniform or adaptive instanced tessellation (vertex shader), or on the geometry shader for low tessellation rates. The chapter “Rule-Based Geometry Synthesis in Real-Time” by Mil&acute;an Magdics and Gergely Kl&acute;ar presents a framework for synthesizing and rendering geometry described by a rule-based representation in real time. The representation is evaluated completely on the GPU; thus, the geometry synthesis can be very fast and there is no need to copy data between the CPU and the graphics card. By applying frustum culling and rule selection based on the distance from the camera during the synthesis, only what is required for rendering with dynamic level of detail is generated. Graham Hemingway describes in the chapter “GPU-based NURBS Geometry Evaluation and Rendering” a method for using the GPU to calculate NURBS geometry. Compared to evaluation on the CPU, this method yields significant performance improvements without drawbacks in precision or flexibility. “Polygonal-Functional Hybrids for Computer Animation and Games,” by Denis Kravtsov et al., describes how to represent geometry with functions to overcome some of the challenges with polygons like produce animations involving dramatic change of the shape of the model and creating complex shapes with changing topology. They also cover the integration of existing polygonal models and functional representations. The chapter “Terrain and Ocean Rendering” looks at the tessellation related stages of DirectX 11, explains a simple implementation of terrain rendering, and implements the techniques from the ShaderX6 article “Procedural Ocean Effects” by L&acute;aszl&acute;o Sz&acute;ecsi and Khashayar Arman. Jorge Jimenez, Jose I. Echevarria, Christopher Oat, and Diego Gutierrez present a method to add expressive and animated wrinkles to characters in the chapter “Practical and Realistic Facial Wrinkles Animation.” Their system allows the animator to independently blend multiple wrinkle maps across regions of a character’s face. When combined with traditional blend-target morphing for facial animation, this technique can produce very compelling results that enable virtual characters to be much more expressive in both their actions and dialog. The chapter “Procedural Content Generation on the GPU,” by Aleksander Netzel and Pawel Rohleder, demonstrates the generating and rendering of infinite and deterministic heightmap-based terrain utilizing fractal Brownian noise calculated in real time on the GPU. Additionally it proposes a random tree distribution scheme that exploits previously generated terrain information. The authors use spectral synthesis to accumulate several layers of approximated fractal Brownian motion. They also show how to simulate erosion in real time. The chapter “Vertex Shader Tessellation” by Holger Gruen presents a method to implement tessellation using only the vertex shader. It requires DirectX 10 and above to work. This method does not require any data in addition to the already available vertex data, in contrast to older techniques that were called “Instanced Tessellation.” It relies solely on the delivery of SV_VertexID and uses the original vertex and index buffers as input shader resources. In “Optimized Stadium Crowd Rendering,” Alan Chambers describes in detail the design and methods used to reproduce a 80,000-seat stadium. This method was used in the game Rugby Challenge on XBOX 360, PS3, and PC. Chambers reveals several tricks used to achieve colored “writing” in the stands, ambient occlusion that darkens the upper echelons, and variable crowd density that can be controlled live in-game. “Geometric Antialiasing Methods” is about replacing hardware multisample antialiasing (MSAA) with a software method that works in the postprocessing pipeline, which has been very popular since a multisample antialiasing (MLAA) solution on the GPU was presented in GPU Pro2. Persson discusses two antialiasing methods that are driven by additional geometric data generated in the geometry shader or stored upfront in a dedicated geometry buffer that might be part of the G-Buffer. The chapter “GPU Terrain Subdivision and Tessellation” presents a GPUbased algorithm to perform real-time terrain subdivision and rendering of vast detailed landscapes without preprocessing data on the CPU. It also achieves smooth level of detail transitions from any viewpoint. “Introducing the Programmable Vertex Pulling Rendering Pipeline” discusses one of the bigger challenges in game development targeting PC platforms: the GPU driver overhead. By moving more tasks onto the quickly evolving GPUs, the number of draw calls per frame can be increased. The chapter gives also an in-depth view on the latest AMD GPUs. “A WebGL Globe Rendering Pipeline” describes a globe rendering pipeline that integrates hierarchical levels of detail (HLOD) algorithms used to manage high resolution imagery streamed from standard map servers, such as Esri or OpenStreetMap. The chapter “Dynamic GPU Terrain” by David Pangerl presents a GPU-based algorithm to dynamically modify terrain topology and synchronize the changes with a physics simulation. The next chapter, “Bandwidth-Efficient Procedural Meshes in the GPU via Tessellation” by Gustavo Bastos Nunes and Jo˜ao Lucas Guberman Raza, covers the procedural generation of highly detailed meshes with the help of the hardware tessellator while integrating a geomorphic-enabled level-of-detail (LOD) scheme. “Real-Time Deformation of Subdivision Surfaces on Object Collisions” by Henry Sch¨afer, Matthias Nießner, Benjamin Keinert, and Marc Stamminger shows how to mimic residuals such as scratches or impacts with soft materials like snow or sand by enabling automated fine-scale surface deformations resulting from object collisions. This is achieved by using dynamic displacement maps on the GPU. “Realistic Volumetric Explosions in Games” by Alex Dunn covers a singlepass volumetric explosion effect with the help of ray marching, sphere tracing, and the hardware tessellation pipeline to generate a volumetric sphere. The chapter by Anton Kai Michels and Peter Sikachev describes the procedural snow deformation rendering in Rise of the Tomb Raider. Their deferred deformation is used to render trails with depression at the center and elevation on the edges, allowing gradual refilling of the snow tracks, but it can also easily be extended to handle other procedural interactions with the environment. The technique is scalable and memory friendly and provides centimeter-accurate deformations. It decouples the deformation logic from the geometry that is actually affected and thus can handle dozens of NPCs and works on any type of terrain. The last chapter in this book deals with Catmull-Clark subdivision surfaces widely used in film production and more recently also in video games because of their intuitive authoring and surfaces with nice properties. They are defined by bicubic B-spline patches obtained from a recursively subdivided control mesh of arbitrary topology. Wade Brainerd describes a real-time method for rendering such subdivision surfaces, which has been used for the key assets in Call of Duty on the Playstation 4 and runs at FullHD at 60 frames per second.
cd C:\Program Files\FlightGear fgfs --fg-root=C:\Program Files\FlightGear\data --aircraft=ufo --in-air --fdm=null --telnet=5501 --telnet=5502 --telnet=5503 --disable-ai-traffic --disable-real-weather-fetch --disable-random-objects --disable-terrasync --disable-clouds --disable-sound --disable-panel --disable-hud --disable-specular-highlight --timeofday=noon --prop:/sim/rendering/multi-sample-buffers=1 --prop:/sim/rendering/multi-samples=2 --prop:/sim/rendering/draw-mask-clouds=false --prop:/sim/rendering/draw-mask-terrain=true --prop:/sim/rendering/draw-mask-objects=true --prop:/sim/rendering/draw-mask-lights=true --prop:/sim/rendering/draw-mask-internal=true --prop:/sim/rendering/draw-mask-cockpit=true --prop:/sim/rendering/draw-mask-effects=true --prop:/sim/rendering/draw-mask-overlay=true --prop:/sim/rendering/draw-mask-world=true --prop:/sim/rendering/draw-mask-panel=true --prop:/sim/rendering/draw-mask-vr=true --prop:/sim/rendering/draw-mask-2d=true --prop:/sim/rendering/draw-mask-3d=true --prop:/sim/rendering/draw-mask-sky=true --prop:/sim/rendering/draw-mask-shadows=true --prop:/sim/rendering/draw-mask-cabin=true --prop:/sim/rendering/draw-mask-weather=true --prop:/sim/rendering/draw-mask-stereo=true --prop:/sim/rendering/draw-mask-internal-cockpit=true --prop:/sim/rendering/draw-mask-internal-windows=true --prop:/sim/rendering/draw-mask-internal-instruments=true --prop:/sim/rendering/draw-mask-internal-overlay=true --prop:/sim/rendering/draw-mask-internal-effects=true --prop:/sim/rendering/draw-mask-internal-lights=true --prop:/sim/rendering/draw-mask-internal-world=true --prop:/sim/rendering/draw-mask-internal-panel=true --prop:/sim/rendering/draw-mask-internal-3d=true --prop:/sim/rendering/draw-mask-internal-sky=true --prop:/sim/rendering/draw-mask-internal-cabin=true --prop:/sim/rendering/draw-mask-internal-weather=true --prop:/sim/rendering/draw-mask-internal-stereo=true --prop:/sim/rendering/draw-mask-internal-shadow=true --prop:/sim/rendering/draw-mask-internal-stall=true --prop:/sim/rendering/draw-mask-internal-aoa=true --prop:/sim/rendering/draw-mask-internal-thermal=false --prop:/sim/rendering/draw-mask-internal-ice=false --prop:/sim/rendering/draw-mask-internal-glass=true --prop:/sim/rendering/draw-mask-internal-dead=true --prop:/sim/rendering/draw-mask-internal-reflection=true程序显示错误unknown command-line option: enable-hud-2d怎么解决
最新发布
05-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值