Version: 2020.3

Graphics.SetRandomWriteTarget

切换到手册
public static void SetRandomWriteTarget (int index, ComputeBuffer uav, bool preserveCounterValue= false);
public static void SetRandomWriteTarget (int index, GraphicsBuffer uav, bool preserveCounterValue= false);
public static void SetRandomWriteTarget (int index, RenderTexture uav);

参数

index 着色器中随机写入目标的索引。
uav Buffer or texture to set as the write target.
preserveCounterValue 是否保持附加/使用计数器的值不变。

描述

Shader Model 4.5 级别的像素着色器设置随机写入目标。

Shader Model 4.5 及以上级别的像素着色器可以写入某些纹理和缓冲区的任意位置,在 UsingDX11GL3Features 中称为“无序访问视图 (UAV)”。设置这些“随机写”目标与设置多个渲染目标的方式相似。您可以使用设置了 enableRandomWrite 标志的 RenderTextureComputeBuffer 作为目标。

UAV 索引在不同平台之间略有差异。在 DX11 上,第一个有效的 UAV 索引是激活的渲染目标的数量。因此,单个渲染目标的常见情况是 UAV 索引将从 1 开始。使用自动转换的 HLSL 着色器的平台将匹配该行为。但是,使用手动编写的 GLSL 着色器时,索引将匹配绑定。在 PS4 上,索引始终从 1 开始,以匹配最常见的情况。

在设置 ComputeBuffer 时,preserveCounterValue 参数指示保持计数器值不变,还是将其重置为 0(默认行为)。

The targets stay set until you manually clear them with ClearRandomWriteTargets. It is best practice to call ClearRandomWriteTargets after your rendering is complete. If you do not do this, rendering issues can occur and some built-in Unity rendering passes may crash.

另请参阅:RenderTexture.enableRandomWriteComputeBufferComputeBuffer.SetCounterValueUsingDX11GL3Features

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961