Jump to content
  • Advertisement
Sign in to follow this  
Zaph-0

How to set specific textures ?

This topic is 3757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have something along the lines of: sampler2D testTexture1; sampler2D testTexture2; PS_OUTPUT ps_main( PS_INPUT IN ) { PS_OUTPUT OUT; OUT.color = tex2D( testTexture1, IN.texcoord0 ); OUT.color = tex2D( testTexture2, IN.texcoord0 ) * OUT.color0; return OUT; } How do I know which texture to bind to stage 0 and 1 with settexture ?

Share this post


Link to post
Share on other sites
Advertisement
If you're using the Effect framework (highly recommended), then you don't use IDirect3DDevice9::SetTexture(). Instead, use ID3DXEffect::SetTexture().

If you're not using the Effects framework, then the HLSL compiler will automatically assign registers. The first sampler declaration will be assigned to the first sampler register, the second sampler declaration will be assigned to the second register, and so on. You can control which register to assign to by using the register(RegisterName) syntax.

More information:
http://msdn.microsoft.com/en-us/library/bb509704(VS.85).aspx

Share this post


Link to post
Share on other sites
Hi, thanks for your reply.

I have noticed the effects framework but cannot see any specific benefit to it so could you please explain to me why its highly recommended ?

I am somewhat new to the vertex/pixel shaders and all that and appreciate any advice regarding to it.

^_^

As for the assigning to the textures to various stages, you are right by that they are being assigned in the order of declaration. The problem though is that if a texture is not being used in the shader it is being optimized out and then the order is no longer correct.

But it can be fixed with something like:

sampler2D testTexture : register(s0);

where a texture is being permanently assigned to a stage, should anyone want to know who stumbles over this thread also looking for an answer...

^_^

Share this post


Link to post
Share on other sites
The effects framework handles a lot of stuff for you. You can use techniques and passes, and you don't have to deal with manually setting shaders to the device. You can set states for each technique/pass. The effects framework also allows you to query and set resources by name, eg. you can call:
myEffect->SetTexture("testTexture1", myTexture);


This can be very convenient, and it means that you don't have to bother with register allocations (the Effect framework handles it all for you).

Share this post


Link to post
Share on other sites
Thanks for the info. That looks very interesting. The assigning of the stages and all that are somewhat bothersome (and prone to error) so I think I'll give it a try...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!