在 HLSL 中修改全局 texture3d 变量

Modify global texture3d variable in HLSL

我将如何着手制作一个我可以在几何着色器 (HLSL) 中修改的全局 texture3d 变量?

尺寸为 64x64x64。

我会在第一个 renderpass 中填充一次,然后在第二个 renderpass 中使用它。

感谢任何帮助。最好使用 D10.

编辑:

我正在按照此 https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch01.html 指南制作行进立方体地形着色器(参见第 1.4 段)。我完成了几何着色器,只是我没有法线,指南建议我可以通过将数据存储在 texture3D 中来创建它们,但我不知道如何将数据放入 texture3D 中。 (向导使用的是DX10)

您可能正在考虑计算着色器。在这种情况下,您可以在计算着色器中将纹理声明为 RWTexture3D,然后在渲染通道中将其采样为 Texture3D。互联网上有很多 resources/tutorials/examples 计算着色器可以帮助您入门。

您不能在 D3D11 中使用几何着色器修改纹理。 geometry shader 唯一能做的就是生成原语。但是,正如@Adam Miles 的回答所述,可以在 D3D11.1 的几何着色器中编写 RWTexture3D。虽然这是可行的,但除非您还使用几何着色器生成基元,否则在计算着色器中执行此操作可能最有意义。

如果您通过 D3D11 API 在 D3D 10.x 中工作,您仍然可以使用 compute shaders, although you cannot use an RWTexture3D type. You would have to view it as an RWByteAddressBuffer, and index it yourself which would be slightly awkward. You don't necessarily need to generate texture data within a shader, you can write into the texture with the CPU, by mapping it and writing the data directly. See ID3D10Texture3D::Map 获取更多信息。

如果您愿意支持 Direct3D 11.1 卡及更高版本,您可以使用 RWTexture3D 实现您所要求的,这与其他答案相反。

您可以自由地将 64x64x64 RWTexture3D 绑定到几何着色器阶段,并以与在计算着色器中相同的方式写入它。

请参阅 Use UAVs at every pipeline stage 了解现在的可能性。