遮挡剔除
Object culling allows you not to render objects which are not presented in the viewing frustum. The particular cases of occlusion culling are the following:对象剔除允许您不渲染在视锥中未显示的对象。遮挡剔除的特殊情况如下:
- Occluders: box, mesh. Occluders: box, mesh.
- Hardware occlusion queries for objects with heavy shaders. 具有浓密着色器的对象的硬件遮挡查询。
Occluders封堵器#
Occluders allow culling geometry that isn't visible behind them. There are 2 types of occluders:遮挡物允许剔除隐藏在其后面的几何图形。封堵器有2种类型:
The type of occluder to be used is defined by geometry to be culled.要使用的封堵器类型由要剔除的几何定义。
Occluders can be very effective in case of complex environments where there are many objects that occlude each other and are costly to render (they have a lot of polygons and/or heavy shaders).在复杂的环境中,当许多物体相互遮挡并且渲染成本很高(它们有很多多边形和/或较重的着色器)时,遮挡器可能会非常有效。
Before using occluders, check the following:在使用封堵器之前,请检查以下内容:
- Rendering of occluders is enabled: in the Menu Bar, Rendering -> Occlusion Culling -> Occluders is toggled on.启用遮挡物渲染:在菜单栏中,启用了Rendering -> Occlusion Culling -> Occluders。
- Rendering of shadows from the occluded objects is disabled: in the Menu Bar, choose Windows -> Settings -> Occlusion Culling and toggle Shadows Culling on.
You can leave shadows rendering enabled, if necessary.禁用了遮挡对象的阴影渲染:在菜单栏中,选择Windows -> Settings -> Occlusion Culling并启用Shadows Culling。You can leave shadows rendering enabled, if necessary.You can leave shadows rendering enabled, if necessary.You can leave shadows rendering enabled, if necessary.如有必要,可以启用阴影渲染。
Usage of occluders is shown in the Content Optimization video tutorial. Usage of occluders is shown in the Content Optimization video tutorial.
Using a Box-Shaped Occluder使用盒形封堵器#
The occluder is a box shape that culls objects' surfaces, bounds of which aren't visible behind it. This is the simplest type of occluders that should be used together with box-shaped objects that block off other objects. For example, you can add an occluder the shape of which coincides with the bounds of a building to avoid rendering of objects behind this building. occluder是一个框形形状,用于剔除对象的表面,其后部的边界不可见。这是最简单的封堵器,应与阻挡其他物体的箱形物体一起使用。例如,您可以添加一个遮挡物,遮挡物的形状与建筑物的边界重合,以避免在该建筑物后面渲染对象。
To create a box-shaped occluder, perform the following:要创建盒形封堵器,请执行以下操作:
- In the Menu Bar, choose Create -> Optimization -> Occluder and add the occluder as a child to the node that should occlude other objects.在菜单栏中,选择Create -> Optimization -> Occluder并将遮挡物作为子项添加到应该遮挡其他对象的节点上。
- In the Common section of the Node tab in the Parameters window, set the position of the occluder to the parent one. 在Parameters窗口的Node选项卡的Common部分中,将遮挡物的位置设置为父遮挡物的位置。
- In the World Occluder section of the Node tab, click Edit Size to enable the editing mode for the occluder. Resize the occluder by using the colored rectangles on the occluder box sides so that it coincides with the parent node size.
You can also use the Size parameter to set the size along the axes.在Node选项卡的World Occluder部分中,单击Edit Size以启用封堵器的编辑模式。通过使用阻塞器框两侧的彩色矩形来调整阻塞器的大小,使其与父节点大小一致。
- Specify the Distance between the camera and the occluder, at which the occluder doesn't occlude anything and, therefore, should be disabled to avoid negative impact on the performance. 在摄像机和遮挡件之间指定Distance,在该位置遮挡件不会遮挡任何东西,因此应将其禁用以避免对性能造成负面影响。
To check how the occluder works, disable the parent node and then try to toggle the occluder on and off:要检查阻塞器如何工作,请禁用父节点,然后尝试打开和关闭阻塞器。
By default, the front faces of the occluder are used to cull objects. However, if the camera is inside the occluder (e.g. inside the building), occlusion culling won't be performed. To avoid such situation, enable the Back Face parameter in the World Occluder section of the Node tab. 默认情况下,封堵器的正面用于剔除对象。但是,如果摄像机位于遮挡物内部(例如建筑物内部),则不会执行遮挡剔除。为避免这种情况,请在NodeBack Face选项卡的World Occluder部分中启用参数。
Using a Mesh-Based Occluder使用基于网格的遮挡物#
The occluder mesh is based on an arbitrary mesh that culls objects' surfaces, bounds of which aren't visible behind it. The occluder mesh is used together with the geometry that cannot be approximated with a box. occluder网格 是基于任意网格的,该网格对对象的表面进行剔除,其边界在后面不可见它。封堵器网格与无法用框近似的几何一起使用。
To create a mesh-based occluder, perform the following:
Prepare a low-poly mesh to be used for the occluder.
- Prepare a low-poly mesh to be used for the occluder.
It isn't recommended to use the same detailed mesh that is used for the node that should occlude other objects: the mesh for the occluder should be as simple as possible to avoid performance loss.准备要用于封堵器的低多边形网格。It isn't recommended to use the same detailed mesh that is used for the node that should occlude other objects: the mesh for the occluder should be as simple as possible to avoid performance loss.It isn't recommended to use the same detailed mesh that is used for the node that should occlude other objects: the mesh for the occluder should be as simple as possible to avoid performance loss.It isn't recommended to use the same detailed mesh that is used for the node that should occlude other objects: the mesh for the occluder should be as simple as possible to avoid performance loss.不建议使用与应该阻塞其他对象的节点相同的详细网格:阻塞器的网格应尽可能简单,以避免性能损失。
- In the Menu Bar, choose Create -> Optimization -> Occluder Mesh and specify the prepared mesh.
You can load a new mesh for the occluder at any time.在菜单栏中,选择Create -> Optimization -> Occluder Mesh并指定准备的网格。You can load a new mesh for the occluder at any time.You can load a new mesh for the occluder at any time.You can load a new mesh for the occluder at any time.您可以随时为咬合器加载新的网格物体。
- Add the occluder as a child to the node that should occlude other objects.将阻塞器作为子对象添加到应该阻塞其他对象的节点上。
- In the Common section of the Node tab in the Parameters window, set the position of the occluder to the parent one. 在Parameters窗口的Node选项卡的Common部分中,将遮挡物的位置设置为父遮挡物的位置。
- Specify the Distance between the camera and the occluder, at which the occluder doesn't occlude anything and, therefore, should be disabled to avoid negative impact on the performance. 在摄像机和遮挡件之间指定Distance,在该位置遮挡件不会遮挡任何东西,因此应将其禁用以避免对性能造成负面影响。
Hardware Occlusion Queries硬件遮挡查询#
One more option to cull geometry that is not visible in the camera viewport is to use a hardware occlusion query. It allows skipping rendering of objects, the bounding boxes of which are covered by another solid geometry. As a result, the number of rendered polygons is reduced and the performance grows.剔除在摄影机视口中不可见的几何的另一种选择是使用硬件遮挡查询。它允许跳过对象的渲染,这些对象的边界框被另一个实体几何覆盖。结果,减少了渲染多边形的数量,并提高了性能。
To run the hardware occlusion test for the scene before sending data to the GPU, toggle the Rendering -> Occlusion Culling -> Occlusion Query flag on in the Menu Bar.要在将数据发送到GPU之前对场景进行硬件遮挡测试,请在菜单栏中打开Rendering -> Occlusion Culling -> Occlusion Query标志。
To run the hardware occlusion test, perform the following:要运行硬件遮挡测试,请执行以下操作:
- In the Menu Bar, toggle the Rendering -> Occlusion Culling -> Occlusion Query flag on to enable testing for the scene before sending data to the GPU. 在菜单栏中,将Rendering -> Occlusion Culling -> Occlusion Query标志打开,以启用对场景的测试,然后再将数据发送到GPU。
- For all objects, that should be culled, enable the Culled by Occlusion Query flag in the Node tab of the Parameters window.
Only nodes with this flag set are tested on the hardware occlusion culling.对于所有应该剔除的对象,在ParametersCulled by Occlusion Query窗口的Node选项卡中启用标志。Only nodes with this flag set are tested on the hardware occlusion culling.Only nodes with this flag set are tested on the hardware occlusion culling.Only nodes with this flag set are tested on the hardware occlusion culling.仅对设置了此标志的节点进行硬件遮挡剔除测试。
When culling is enabled for the object, an occlusion query box is rendered for it.为对象启用剔除后,将为其呈现遮挡查询框。
The occlusion query box coincides with the size of the object's bounding box. When this box is overlapped (i.e. it isn't in the camera viewport), it is highlighted red, which means the occlusion test is not passed and the mesh will not be drawn.遮挡查询框与对象边界框的大小一致。当此框重叠时(即不在相机视口中),将突出显示红色,这意味着未通过遮挡测试并且将不会绘制网格。
Occlusion query test passed遮挡查询测试通过 |
Occlusion query test failed, material ball isn't rendered遮挡查询测试失败,未显示实物球 |
You can check the effect of this technique by enabling the second wireframe mode to see all triangles in the scene. Type render_show_triangles 2 in the console and check the way the occluded polygons act.您可以通过启用第二个线框模式以查看场景中的所有三角形来检查此技术的效果。在控制台中输入 render_show_triangles 2 并检查遮挡的多边形的作用方式。
An example of using hardware occlusion queries is also available in the Content Optimization video tutorial.“内容优化”视频教程中也提供了使用硬件遮挡查询的示例。内容优化 视频教程.