Unsigned int in vertex shader

Started by
1 comment, last by -Tau- 9 years, 7 months ago

I'm trying to pass unsigned int number to vertex shader, but the shader acts like it gets only the first byte of that number.

Vertex structure:

struct HMMULTITEX
{
D3DXVECTOR3 pos;
D3DXVECTOR3 norm;
D3DXVECTOR2 tex;
UINT texID;
};

Vertex declaration

D3DVERTEXELEMENT9 aVertDecl[] =

{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 32, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
D3DDECL_END()
};

HLSL code:


unsigned int vTexHeight : TEXCOORD1
out float oTH[8] : TEXCOORD3

unsigned int retnum=vTexHeight % 0x10;
oTH[0]=(retnum/15.0f);
	
retnum=vTexHeight/0x10;
retnum=retnum % 0x10;
oTH[1]=(retnum/15.0f);

retnum=vTexHeight/0x100;
retnum=retnum % 0x10;
oTH[2]=(retnum/15.0f);

retnum=vTexHeight/0x1000;
retnum=retnum % 0x10;
oTH[3]=(retnum/15.0f);

...oTH[7]

Problem: Only oTH[0] and oTH[1] works, all other ale allways 0. It looks like vertex shader gets only the first byte of vTexHeight.
Everything above 0xff is ignored.
How can i pass unsigned int to vertex shader? Why is current vertex shader ignoring anything above the first byte?

Advertisement

D3DDECLTYPE_UBYTE4 is a declaration for a four-component variable of unsigned bytes. When the vertex is passed to the shader, that's what the four bytes comprising texID are interpreted as. Your vertex structure is just storage for values. The vertex declaration determines how those values are to be interpreted when they're passed to the shader.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Thanks for the tip, i changed D3DDECLTYPE_UBYTE4 to D3DDECLTYPE_D3DCOLOR and unsigned int vTexHeight to float4 vTexHeight. Now i get bytes with

int u1=(int)(vTexHeight.b*255);
int u2=(int)(vTexHeight.g*255);
int u3=(int)(vTexHeight.r*255);
int u4=(int)(vTexHeight.a*255);

This topic is closed to new replies.

Advertisement