Sign in to follow this  
Daniel Wilson

CG question, How to access an array element in for loop?

Recommended Posts

Daniel Wilson    159
Hi folks, I have a cg shader in which I have the following loop:
[CODE]
float currentLayer = 0;
float4 myVec;
const float4x4 myMatrix=
(2.6, 1.6, 1.6, 0,
6.6, 3.6, 2.6, 0,
1.5, 1.5, 2.5, 0,
0, 0, 0, 1);

for(int i = 0; i < num_samples; i++)
{
currentLayer = FindLayer(depthM, umvm, sstm); //This results in an value between 1 and 4

myVec= myMatrix[currentLayer];
//..
//..
//..much more code...
}
[/CODE]

This throws up the error:
[CODE](395) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable[/CODE]
I am using ps_3_0, but what I'm actually trying to do should be possible in earlier profiles I think I am just doing it wrong.
So my noob question is how might I get the vector I need based on the current layer number that my FindLayer() function returns, all inside a for loop. The error seems to suggest I can only say myVec = myMatrix[i], which I don't need to do!

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