index | 着色器中随机写入目标的索引。 |
uav | Buffer or texture to set as the write target. |
preserveCounterValue | 是否保持附加/使用计数器的值不变。 |
为 Shader Model 4.5 级别的像素着色器设置随机写入目标。
Shader Model 4.5 及以上级别的像素着色器可以写入某些纹理和缓冲区的任意位置,在 UsingDX11GL3Features 中称为“无序访问视图 (UAV)”。设置这些“随机写”目标与设置多个渲染目标的方式相似。您可以使用设置了 enableRandomWrite
标志的 RenderTexture 或 ComputeBuffer 作为目标。
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.enableRandomWrite、ComputeBuffer、ComputeBuffer.SetCounterValue、UsingDX11GL3Features。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.