您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 雨の日曜日 于 2021-10-2 14:57 编辑
written by:MaxwellGeng
When there are certain requirements for picture complexity, art is often implemented by Dec. at present, there are two methods to implement Dec. one is to use procedural virtual texture in conjunction with the GPU driven rendering pipeline mentioned earlier, and directly add Dec to Pvt. However, using pure gpurp + PVT is actually an extreme rendering method, For example, only one material can be used globally, and the whole terrain depends on one drawcall. On the one hand, this has great restrictions on art and is not conducive to the construction of multiple lighting models. On the other hand, the consumption of GPU end can not be underestimated, which is not suitable for us who have caused serious GPU bound due to stacking high-definition effects, Therefore, we will use a more ingenious way to complete it.
在对画面复杂度有一定要求的情况下,美术常常使用Decal来实现,目前实现Decal有两种方法,一种是使用Procedural Virtual Texture配合之前讲过的GPU Driven Rendering Pipeline,直接将decal添加到PVT中即可,但是使用纯粹的GPURP + PVT实际上是一个比较极端的渲染方法,譬如全局只能使用同一个材质,整个地形依靠一个Drawcall完成,这样做一方面对美术的限制极大,不利于多种光照模型的搭建,另一方面其带来的GPU端的消耗也不容小觑,这对于已经因为堆砌高清特效而产生严重GPU Bound的我们来说并不合适,因此我们将会使用更加取巧的办法完成。
According to the cluster light culling mentioned earlier, the calculation method of light is to cut the screen into three-dimensional voxel blocks according to the horizontal and vertical axes of the screen, and store the light in three-dimensional space. This idea is very suitable for developing forward rendering that can support a variety of lighting models. Considering the level of the readers of this article, there is really no need to explain the specific difference between forward and deferred. Here we use a half forward and half deferred calculation method, that is, we directly calculate the direct illumination in the object's shader and output gbuffer for subsequent Ao, IBL, SSR, iradiance volume and other special effects. In this way, you can not only enjoy the benefits brought by various lighting models of the forward pipeline, but also enjoy the benefits of post-processing effects relying on gbuffer. At the same time, you can save the deferred lighting pass, that is, the next layer of overdraw, which further reduces the consumption of GPU. The disadvantage is that if you insist on using multiple shaders, it basically means saying goodbye to pure cluster rendering, that is, the rendering of the main screen returns to the traditional CPU pipeline again, but the shadowmap still insists on cluster rendering, so the drawcall is still controlled in a more controllable range.
根据之前讲过的Cluster light culling,灯光的计算方式是把屏幕根据屏幕的横竖与纵轴切割成3D体素方块,并将灯光存储到3D空间中,这种思路非常适合开发能够支持多种光照模型的Forward rendering。考虑到本篇文章的读者自身水平,这里着实没必要解释forward与deferred的具体区别。而我们这里使用的则是一个半前半后计算方式,即直 接 在物 体的sha der中运算直接光照,并输出Gbu ffer供后续的AO\SSR等特效使用。这样既可以享受到Forward管线的多种光照模型带来的好处,也可以享受到依赖GBuffer的后处理特效的好处,其乐无穷,同时可以省下Deferred Lighting Pass,也就是省下一层overdraw,进一步降低了GPU的消耗。缺点就是如果坚持使用多种shader,就基本意味着和完全的cluster rendering说再见了,即主屏幕的渲染再次回归传统CPU Pipeline,但是Shadowmap的绘制依然坚持Cluster Rendering,所以Drawcall还是控制在一个比较可控的范围。
After finishing the basic implementation idea of forward +, we will enter the theme of the article, the implementation of Dec. first, let's take a look at the introduction of deferred Dec in the illusory engine:
The performance of Dec is "placed in one area, which affects the map display effect", which is similar to lighting calculation, so we will calculate the distribution of Dec by calculating lighting:
https://docs.unrealengine.com/en ... Examples/Decals/1_1
说完了Forward+ 的基本实现思想,我们就进入文章的主题,Decal的实现,首先来看一下虚幻引擎中Deferred Decal的介绍:
https://docs.unrealengine.com/en ... Examples/Decals/1_1
Decal的表现是“放在一块区域,影响贴图显示效果”,这一点和光照计算有异曲同工之妙,所以我们将用计算光照的方法计算一下Decal的分布:
This code first multiplexes the data used in cluster lighting to obtain the coordinates of six planes to form a pyramid. Compare this pyramid with all Dec bounding boxes, select the qualified ones and store them in structuredbuffer after dimensionality reduction. The queue length is stored in the first position of each block, and the index information is officially stored from the second position, Therefore, in the shader, you can use the UV and linear depth of the current pixel to get the queue of Dec that the current pixel may receive:
这段代码首先把Cluster Lighting中用到的数据复用,也就获得了6张平面的坐标,构成一个棱台,将此棱台与所有的Decal Bounding Box进行比对,选出符合条件的并降维后存入StructuredBuffer,每一块的第一个位置储存队列长度,从第二个位置正式储存索引信息,因此在Shader中即可使用当前像素所在的UV和线性深度,得到当前像素点可能接收到的Decal的队列:
The data obtained in this way is the position information, map information, etc. of each decimal. Because it is a single pass forward, only one decimal atlas texture is allowed in the whole image. A large map can be used for atlas. Here, a texture array is directly used for convenience. Therefore, we store the texture index of each decimal in decldata:
这样获得的data就是每个Decal的位置信息,贴图信息等。因为是Single Pass Forward,因此全图只允许有一个Decal atlas texture,可以使用一张大贴图做Atlas,这里为了方便就直接用了一张Texture Array,因此我们在DecalData中存储了每个Decal的texture Index:
Then the complete decimal read will be as follows:
那么完整的Decal读取将会是这样:
Here, only one color map is used as albedo and one normal map in rghalf format. After the two maps are mixed and output, they can be integrated into forward pass. Create a cube in the scene. Since the drawing interface of gizmos is not found in unity2019, the translucent square is used here for the time being:
这里只使用了一张色彩贴图用作Albedo,一张RGHalf格式的法线贴图,将这两张贴图混合后输出,就可以融入到Forward Pass中了。在场景中建立一个Cube,由于Unity2019暂时没找到Gizmos的绘制接口,所以这里暂时使用半透明方块表示:
The square should be as thin as possible and close to the wall, because the accuracy of cluster culling based on screen space is limited. If the decimal is too thick, it may increase additional computation, which is not cost-effective. After the setup, generate a unified atlas with scripts, including normal and albedo:
方块应该尽可能的薄,紧贴墙面,因为基于屏幕空间的Cluster Culling精度有限,如果Decal过厚可能会增加额外的运算量,很不划算。在搭建完毕后,用脚本生成统一的Atlas,包括Normal,Albedo:
The implementation of Dec is basically over here. As an independent rendering event, Dec occurs after lighting operation and before main screen rendering, so the data prepared for calculation can be directly used in main screen rendering. The final effect is as follows:
Decal的实现到这里就基本结束了,作为一个独立的渲染事件,Decal发生在光照运算之后,主屏幕绘制之前,所以其计算准备的数据可以直接在主屏幕绘制中使用,最终效果如下:
Here, the implementation of Dec is basically completed. Recently, due to busy putting this set of rendering pipeline into production and development, the work is very hasty, and deficiencies are inevitable. Please forgive me.
到这里,Decal的实现就基本完成了。最近由于忙着将这套渲染管线投入生产开发,工作十分仓促,不足之处在所难免,请各位读者见谅。
|