简体   繁体   中英

Bind Texture2D and TextureCube

I need to pass both a Texture2D and a TextureCube to my pixel shader at the same time.

I was previously sending an array of texture's but found that I was not able to send a textureCube as well as this.

This question mentions something called binding but I am unable to find any more information on this and was wondering if someone might be able to point me in direction of a solution for this problem.

Thank you.

Edit---- After attempting to implement Caesar's suggestion the following code causes an error. First-chance exception when the shader is attempted to be read, the problem line is simply

Texture2D texture04 : register( t0 );

Which causes a crash after this:

D3DX11CompileFromFile("Data/Shaders/Effects.fx", 0, 0, "VS", "vs_4_0", 0, 0, 0, &VS_Buffer, 0, 0);
D3DX11CompileFromFile("Data/Shaders/Effects.fx", 0, 0, "PS", "ps_4_0", 0, 0, 0, &PS_Buffer, 0, 0);
d3dDevice_->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), NULL, &VS);

ReEdit---- Rewrote the exact code...worked this time, no idea why. Thank you very much.

You can register multiple textures in your shader file like so

Texture2D texture04 : register( t0 );    
TextureCube myCubeMap : register( t1 );

The t0 and t1 specify the registry number, and so you use that number as the first parameter for the PSSetShaderResources

When you want to set t0 in your C++ Code you do it like so

pImmediateContext->PSSetShaderResources( 0, 1, &(texture) );

And when you want to set t1 you do it like so

pImmediateContext->PSSetShaderResources( 1, 1, &(texture) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM