渲染贴花

使用 Pipeline State 渲染通道在 3D 对象表面上渲染贴花,而不会产生 Z-fighting。您可以设置要应用于由 Pipeline State 渲染通道渲染的元素的多边形深度偏移。

要渲染贴花:

  1. 创建您要在其表面渲染贴花的 3D 内容。

    例如:在 Node Tree 中创建一个 Plane 节点。

    ../../_images/wall-plane-in-node-tree.png ../../_images/wall-in-preview.png
  2. 创建要作为贴花渲染的内容。

    例如:在您在上一步中创建的 Plane 节点中创建一个 Plane 节点,将其命名为 Decal,并设置为显示纹理。

    在 Preview 中,您可以看到节点之间的深度冲突。

    ../../_images/decal-in-node-tree.png ../../_images/decal-properties.png ../../_images/decal-z-fighting.png
  3. 标记您想要渲染为贴花的节点。请参阅 标记节点。

    例如,将 Decal 节点标记为标签 Decal。

  4. 创建一个 Tag Filter 来选择您想要渲染为贴花的节点,以及另一个 Tag Filter 来选择除您想要渲染为贴花的节点之外的所有节点。请参阅 使用 Tag Filter。

    ../../_images/decal-tag-filter.png ../../_images/wall-tag-filter.png
  5. 使用渲染通道来渲染您的内容和贴花,以避免 z-fighting。

    例如,要修改并使用 Default 渲染通道预设来渲染内容和贴花:

    1. 在 Library 中 按 Alt 并右键单击 Rendering,并选择 Default 渲染通道预设。请参阅 使用 Kanzi Studio 渲染通道预设。

      ../../_images/create-default-render-pass.png
    2. 要使用 Default 渲染通道预设件,请选择包含您要渲染的 3D 内容和贴花的 Viewport 2D 节点,并在 Properties 中将 Render Pass Prefab 属性设置为 Default 渲染通道。

      ../../_images/decal-viewport-2d.png ../../_images/render-pass-prefab-set-to-default-render-pass.png
    3. 在 Library 中的 Default 渲染通道预设件中选择 Draw Objects Opaque 渲染通道,并在 Properties 中将 Objects Source 属性设置为选取除要渲染为贴花的节点之外的所有节点的 Tag Filter。

      您将此 Draw Objects 渲染通道设置为渲染 Viewport 2D 节点中除贴花节点之外的所有节点。

      ../../_images/draw-objects-opaque-in-library.png ../../_images/draw-wall-properties.png
    4. 在 Default 渲染通道预设件中选择 Draw Objects Transparent 渲染通道,并在 Properties 中将 Objects Source 属性设置为选取要渲染为贴花的节点的 Tag Filter。

      您将此 Draw Objects 渲染通道设置为仅渲染贴花节点。

      ../../_images/draw-objects-transparent-in-library.png ../../_images/draw-decal-properties.png
    5. 在 Default 渲染通道 > Gather Lights 渲染通道中创建一个 Pipeline State 渲染通道,并将渲染贴花节点的 Draw Objects 渲染通道拖到该 Pipeline State 渲染通道。

      ../../_images/pipeline-state-render-pass-for-decal.png ../../_images/drag-draw-decal.png
    6. 选择 Pipeline State 渲染通道,并在 Properties 中添加 Polygon Depth Offset 属性,并将其字段设置为可提供所需渲染结果的值:

      • Derivate Multiplier 设置每个像素深度变化导数的乘数。

      • Constant Multiplier 乘以深度的最小可测量单位,具体取决于目标平台。

      Kanzi 通常会将具有负深度偏移的多边形显示得更靠近摄像机。

      ../../_images/pipeline-state-render-pass-in-library.png ../../_images/polygon-depth-offset-property.png ../../_images/decal-in-preview.png

另请参阅

渲染 (Rendering)

使用网格

使用标签

使用 Tag Filter

使用 Kanzi Studio 渲染通道预设