directx - DirectX 中的 Texture3D 数组?

标签 directx hlsl

HLSL中有Texture2DArray,但是对于HLSL/DirectX中的Texture3D数组有什么解决方法吗?

最佳答案

DirectX11 和 DirectX12 中都有一些选项。

DirectX11 有更多限制。

您可以按照以下方式在 HLSL 中声明纹理数组:

Texture3D textures[3] : register(t0);

请注意,它本身并不是真正的数组,它实际上相当于:

Texture3D texture0 : register(t0);
Texture3D texture1 : register(t1);
Texture3D texture2 : register(t2);

所以你仍然需要绑定(bind)3个纹理。

另请注意,您的数组大小必须在着色器中设置,不能有不同的数字。

此外,动态索引也是不允许的,因此这无效,例如:

int3 myvoxel = //something

int index = 0;
if (voxel.x > 5)
{
    index = 1;
}
return textures[index].Load(int4(voxel, 0));

以下内容也不起作用:

cbuffer cbIndex : register(b0)
{
    uint index;
}

return textures[index].Load(int4(voxel, 0));

在 DirectX12 中,此限制较少。

您仍然需要在描述符表中的连续位置设置 3 个纹理 View ,但是:

您可以进行动态索引,这样上面的两个示例都可以工作。

您还可以声明无界数组,因此您如上所述需要确保所有卷在描述符表中是连续的。

Texture3D textures[] : register(t0);

关于directx - DirectX 中的 Texture3D 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72817955/

相关文章:

c++ - Direct2D 保存渲染结果

c++ - 如何一起使用顶点、法线和纹理索引?

casting - 当我有一个 uint32 (R32) 纹理并在着色器中从中采样/获取时会发生什么?

hlsl - DXR : How to identify the geometry instance of the bottom level AS inside the closest hit shader

c# - 将屏幕纹理存储在 HLSL 纹理变量 (XNA) 中

c# - HLSL 计算 - 按顺序处理像素?

c++ - DirectX 托管池

c++ - DirectX 11 每面数据

c# - 拦截和取消 DirectX 游戏的按键事件

c# - XNA 4.0 + DirectX 9?