无法在DX11中为着色器设置两个纹理

时间:2019-04-21 22:25:08

标签: c++ hlsl

我想为着色器设置两个纹理,但是当我采样第二个时,我得到了第一个的颜色。纹理有各种大小,所以我不能使用数组。怎么了?

    //-- fill and set interface dynamic texture

    D3D11_MAPPED_SUBRESOURCE msr;
    devcon->Map(Interface_DynamicTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &msr);
    memcpy(msr.pData, ibb, ibw*ibh*4);
    devcon->Unmap(Interface_DynamicTexture, 0);

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

    //-- set 3d render target as textures

    devcon->PSSetShaderResources(1, 1, &Render_SRV);

    //-- render to back buffer

    devcon->VSSetShader(PostProcess_VertexShader, 0, 0);
    devcon->PSSetShader(PostProcess_PixelShader, 0, 0);

    devcon->IASetInputLayout(ScreenPlane_Layout);
    UINT stride = sizeof(ScreenPlane_Vertex);
    UINT offset = 0;
    devcon->IASetVertexBuffers(0, 1, &ScreenPlane_Buffer, &stride, &offset);
    devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    devcon->OMSetBlendState(Interface_BlendState, 0, 0xffffffff);
    devcon->OMSetRenderTargets(1, &BackBuffer_Target, NULL);
    devcon->ClearRenderTargetView(BackBuffer_Target, D3DXCOLOR(0.0f, 0.0f, 0.4f, 1.0f));
    devcon->Draw(6, 0);

    swapchain->Present(options.graphics.vsync, 0);
Texture2D interf;
Texture2D color;

SamplerState SampleType
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;
};

struct IN
{
    float4 unsigned_short2: SV_POSITION;
    float2 tex: TEXCOORD0;
};

float4 main(IN i): SV_TARGET
{
    return color.Sample(SampleType, i.tex);
}

我尝试过:register(tXX);,但是没有用。

0 个答案:

没有答案