PDA

View Full Version : Indexing of an array in cg


k.arts
07-04-2005, 06:00 PM
Hi there!
I am trying the following in cg:

float Max[10];
float Index = OtherValue*255.0f;
Max[Index] = Val;

I know, that Index is in range (Val between 0-9), but sadly the compiler doesn't know this... Thus he gives me an error. I tried to do also the following:
float Max[10];
float Index = OtherValue*255.0f;
Max[clamp(Index,0,9)] = Val;
That didn't work either, because clamping seems to be not allowed when indexing.
Is there any solution? I tried with the vp30, vp40 and of course with arbvp1 shaderprofile.
Thanks a lot
k.arts

gga
07-05-2005, 01:33 AM
You are incorrectly trying to use a float to index an array. Use an int.

k.arts
07-05-2005, 10:17 AM
Thanks for that!
I have casted that clamp to int, but it didn't work either. The cgc compiler (I now have a pre compiler step in visual studio, very helpful!) told me that my expression was too complex. So I think, this problem can't be fixed... Hopefully with the next compiler version provided by nVidia. For now, I have made it another way, bit more complicated and slower ;(

k.arts

CGTalk Moderation
07-05-2005, 10:17 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.