Sign in to follow this  
zurekx

Using more than one texture in hLSL

Recommended Posts

My shader has a sampler for a texture. When I want to bind a texture I use g_pd3dDevice->SetTexture( 0, g_texture); Now I want to have more than one texture, so I wanna do something like g_pd3dDevice->SetTexture( 0, g_texture1); g_pd3dDevice->SetTexture( 1, g_texture2); g_pd3dDevice->SetTexture( 2, g_texture3); But how should my sampler-declarations in HLSL look? (to bind the different samplers to the different "numbers"?)

Share this post


Link to post
Share on other sites
This should help. Look at the end of each line. For instance, s1 is texture from stage 1 in SetTexture method.

uniform sampler2D texture : register(s0),
uniform sampler2D anotherTexture : register(s1)

Share this post


Link to post
Share on other sites
Quote:
Original post by zurekx
My shader has a sampler for a texture. When I want to bind a texture I use

g_pd3dDevice->SetTexture( 0, g_texture);

Now I want to have more than one texture, so I wanna do something like

g_pd3dDevice->SetTexture( 0, g_texture1);
g_pd3dDevice->SetTexture( 1, g_texture2);
g_pd3dDevice->SetTexture( 2, g_texture3);

But how should my sampler-declarations in HLSL look? (to bind the different samplers to the different "numbers"?)


Slight side question, but if you're using HLSL, why are you not using the effect framework? With the effect framework you can just have this in your shader:


texture textureBlah
sampler2D samplerBlah = sampler_state {
texture = <textureBlah>;
};


For each texture, and then when you set up the effect you can just do:


effect->SetValue("textureBlah", g_texture1, D3DX_DEFAULT);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this