从HLSL着色器按名称反射纹理寄存器

生存机器

我知道如何反映常量缓冲区,但是如何反映纹理?这是我的着色器:

cbuffer buffer : register(b0)
{
    column_major matrix viewProjectionMatrix;
    column_major matrix modelMatrix;
    float4 texScaleOffset;
    float4 tint;
}

struct VS_INPUT
{
    float4 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};

struct PS_INPUT
{
    float4 Pos : SV_POSITION;
    float2 Tex : TEXCOORD0;
};

PS_INPUT VS( VS_INPUT input )
{
    PS_INPUT output = (PS_INPUT)0;
    output.Pos = mul( viewProjectionMatrix, mul( modelMatrix, input.Pos ) );
    output.Tex = input.Tex * texScaleOffset.xy + texScaleOffset.zw;

    return output;
}

Texture2D textureMap : register(t0);
SamplerState SampleType : register(s0);

float4 PS( PS_INPUT input ) : SV_Target
{
    return textureMap.Sample( SampleType, input.Tex );
}

那么,如果我知道它的名称(“ textureMap”),如何从C ++查询TextureMap的注册号?我的用例是一个引擎,该引擎允许用户编写自己的着色器,因此我无法对任何值进行硬编码。

亚当·迈尔斯

与反映常量缓冲区的方式非常相似:

ID3D11ShaderReflection* reflectionInterface;
D3DReflect(bytecode, bytecodeLength, IID_ID3D11ShaderReflection, (void**)&reflectionInterface);

D3D11_SHADER_INPUT_BIND_DESC bindDesc;
reflectionInterface->GetResourceBindingDescByName("textureMap", &bindDesc);

bindDesc.BindPoint是纹理绑定到的插槽的索引。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章