Jump to content
  • Advertisement
Sign in to follow this  

Vertex Texture question

This topic is 2652 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 a little question about Vertex Textures in DX9 (Note: I am not using .fx files).
In my project I have a pixel shader ps.psh and a vertex shader vs.vsh. Both use a texture (sampler myTex).

In order to set both textures I use this code to get the corresponding sampler register:

D3DXHANDLE handle;
if( handle = g_pConstantTableVS->GetConstantByName( NULL, "myTex" ) ) {
UINT count;

g_pConstantTableVS->GetConstantDesc( handle, &constDesc, &count );

if( constDesc.RegisterSet == D3DXRS_SAMPLER )
g_pd3dDevice->SetTexture( constDesc.RegisterIndex, g_pTexture );

The problem is: Both "myTex" for the VS and PS have register index 0! What happens, if I now call g_pd3dDevice->SetTexture(0, g_pTexture );
? Do I set the texture for both VS and PS? How can I explicitely set the textures for the VS and the PS?

Share this post

Link to post
Share on other sites
Hi !
just add in your shader :

const uniform sampler2D colorMap : register( s[0] ) ;
const uniform sampler2D normalMap : register( s[1] );

with a setTexture to 0 for the first instruction et 1 for the second one.
PS : colorMap and normalMap are examples here.

Share this post

Link to post
Share on other sites
Uhm, actually I do not want to use the register keyword. And why the square brackets? Is this a special syntax to mark "vertex texture samplers"?

I don't understand how this should work. How should DX9 know what I mean with device->setTexture(0, foo); 0 could reference the first sampler in my pixel shader or the first sampler in my vertex shader!

Share this post

Link to post
Share on other sites
Thanks MJP! Yes, I also found this site, but it wasn't very helpful for me. Sometimes it bugs me that they just can't give a simple example.

Ok, so when I query the registerIndex from a Vertex Shader constant table the index are (kinda) offsets that have to be added to D3DVERTEXTEXTURESAMPLER0, aren't they? For example if I have a vertex shader like this:

sampler myTex;
sampler myTex2;

then I would set them this way:

device->setTexture(D3DVERTEXTEXTURESAMPLER0 + constDescOfMyTex.registerIndex); // constDescOfMyTex.registerIndex is probably 0?
device->setTexture(D3DVERTEXTEXTURESAMPLER0 + constDescOfMyTex2.registerIndex); // constDescOfMyTex.registerIndex is probably 1?

Is this correct?

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!