DirectX 11,将多个纹理发送到着色器 [英] Directx 11, send multiple textures to shader

查看:159
本文介绍了DirectX 11,将多个纹理发送到着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码,我可以将一个纹理发送到着色器:

using this code I can send one texture to the shader:

 devcon->PSSetShaderResources(0, 1, &pTexture); 

我当然通过以下方式制作了pTexture:D3DX11CreateShaderResourceViewFromFile

Of course i made the pTexture by: D3DX11CreateShaderResourceViewFromFile

着色器:
Texture2D Texture;

Shader: Texture2D Texture;

return color * Texture.Sample(ss, texcoord);

我目前仅向着色器发送一个纹理,但是我想发送多个纹理,

I'm currently only sending one texture to the shader, but I would like to send multiple textures, how is this possible?

谢谢。

推荐答案

通过使用纹理数组。当您填写 D3D11_TEXTURE2D_DESC 查看 ArraySize 成员。此说明结构是传递给 ID3D11Device :: CreateTexture2D 。然后在着色器中使用第3个texcoord采样索引,该索引指示要引用的数组中的2D纹理。

By using Texture Arrays. When you fill out your D3D11_TEXTURE2D_DESC look at the ArraySize member. This desc struct is the one that gets passed to ID3D11Device::CreateTexture2D. Then in your shader you use a 3rd texcoord sampling index which indicates which 2D texture in the array you are referring to.

更新: 我刚刚意识到您可能正在谈论通过多个调用(即针对不同的地理区域)进行此操作,在这种情况下,您将更新着色器的纹理资源视图。如果您使用的是效果框架,则可以使用 ID3DX11EffectShaderResourceVariable: :SetResource ,或者使用 PSSetShaderResources 重新绑定新纹理。但是,如果尝试在多个纹理之间进行混合,则应使用纹理数组。

Update: I just realised you might be talking about doing it over multiple calls (i.e. for different geo), in which case you update the shader's texture resource view. If you are using the effects framework you can use ID3DX11EffectShaderResourceVariable::SetResource, or alternatively rebind a new texture using PSSetShaderResources. However, if you are trying to blend between multiple textures, then you should use texture arrays.

您可能还希望研究3D纹理,这提供了一种自然的方法通过texcoord中的第3个元素在数组的相邻纹理之间进行插值(而2D数组将自动钳位到最接近的整数)。请参阅HLSL 示例 备注

You may also want to look into 3D textures, which provide a natural way to interpolate between adjacent textures in the array (whereas 2D arrays are automatically clamped to the nearest integer) via the 3rd element in the texcoord. See the HLSL sample remarks.

这篇关于DirectX 11,将多个纹理发送到着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆