Sign in to follow this  
schupf

Vertex Texture question

Recommended Posts

Hello,

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:
[code]
D3DXHANDLE handle;
if( handle = g_pConstantTableVS->GetConstantByName( NULL, "myTex" ) ) {
D3DXCONSTANT_DESC constDesc;
UINT count;

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

if( constDesc.RegisterSet == D3DXRS_SAMPLER )
g_pd3dDevice->SetTexture( constDesc.RegisterIndex, g_pTexture );
}[/code]
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 :

[code]

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


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
You set vertex shader textures by passing D3DVERTEXTEXTURESAMPLER0 - D3DVERTEXTEXTURESAMPLE3 to SetTexture. So in your case you can pass D3DVERTEXTEXTURESAMPLER0 + constDesc.RegisterIndex.

Relevent documentation is here: [url="http://msdn.microsoft.com/en-us/library/bb206339%28v=vs.85%29.aspx"]http://msdn.microsoft.com/en-us/library/bb206339%28v=vs.85%29.aspx[/url]

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:
[code]
sampler myTex;
sampler myTex2;
[/code]
then I would set them this way:
[code]
device->setTexture(D3DVERTEXTEXTURESAMPLER0 + constDescOfMyTex.registerIndex); // constDescOfMyTex.registerIndex is probably 0?
device->setTexture(D3DVERTEXTEXTURESAMPLER0 + constDescOfMyTex2.registerIndex); // constDescOfMyTex.registerIndex is probably 1?
[/code]
Is this correct?

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