Skip to main content
gamedev.net
🔒 Locked

HLSL array indexing problem

Started by Tigran Jun 21, 2010 at 11:36 AM 3 replies 1.3k views
Original Post
Tigran
Tigran
Hi Guys,

I've got a mesh that has two DWORDS as vertex data.
The second DWORD isn't relevant here (it's just a color, don't have a problem with that)
The first DWORD is a UBYTE4.
The first 3 Bytes of the DWORD are the x y z positions and the forth one is a special ID.

This ID is supposed to decide a few properties of the vertex.
For example the color.

So I have a uniform extern float4 gCoverColors[256] declared and filled.

Now the part where the stuff go wrong:
OutputVS CubeVS(float4 posL : POSITION0, float4 LightColor : COLOR0){		OutputVS outVS = (OutputVS)0;	outVS.color 	= gCoverColors[posL.w]; // Also tried floor(posL.w), posL.a, posL[3]        ...        return outVS;}


When I run this, I don't get any output.
But when I manually put gCoverColors[0] for example, It works correctly.

What is the problem and how can I fix it? I'm using VS 2.0
I've also tried to replace posL.w with values like posL.x and some others (from the second DWORD) and none workes although I know for sure that posL.x for example does have a valid value (since it is also being used for the position, which works just fine)


Thanks in advance,
Tigran
MJP
MJP
Have you debugged your shader in PIX, or inspected the contents of your vertex buffer to make sure they're what you expect them to be?

Also, keep in mind that the xyzw components of a UBYTE4 will be normalized to the [0,1] range in the shader (AKA, they will be divided by 255).
Tigran
Tigran
I think you mean the UBYTE4N, that one is in the range of 0-1

Using PIX, all the information in the vertexes were correct.
But when I use that line outVS.color = gCoverColors[posL.w];
It doesn't show any mesh information in pix
when I use outVS.color = gCoverColors[0];
It shows everything normally.
Tigran
Tigran
*bump*
scope
scope
Hey man, i see you're implementing the instancing.

I'm afraid i can't help either, but have you tried making it work using floats for the position? Maybe post more of your shader code and your vertex declaration and all of that.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.