Texture2D.Load在HLSL片段着色器中起作用,但在顶点着色器中不起作用

时间:2018-10-19 14:25:26

标签: textures hlsl vertex-shader

文档声称它在vs_4_0和更高版本[link中受支持(我在使用vs_5_0),但是所有值都返回(0,0,0,0)。我有什么想念的吗?

Texture2D view0 : register(t0);

SamplerState MeshTextureSampler: register(s0) {
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;
};

cbuffer InputData : register(b0) {
    uint width;
    uint height;
}

struct VertexInputType {
    float4 position : POSITION;
    float4 color : COLOR;
    float2 tex : TEXCOORD0;
};

struct VertexOutputType {
    float4 position : SV_POSITION;
    float4 color : COLOR;
    float2 tex : TEXCOORD0;
};

VertexOutputType VShader(VertexInputType input) {
    VertexOutputType output;
    output.position = input.position;
    output.tex = input.tex;
    output.color = view0.Load(int3(output.tex.x * width, output.tex.y * height, 0));

    return output;
}

float4 PShader(VertexOutputType input) : SV_TARGET
{
    //DOES NOT WORK
    return input.color; 

    //WORKS
    return float4(view0.Load(int3(input.tex.x * width, input.tex.y * height, 0)).rgb, 1); 
}

0 个答案:

没有答案