Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm writing a Phong shader with multiple lights. I send a uniform array to both vertex and fragment shaders. Let's say one of the arrays is
C++
uniform vec3 lights[8];

then I loop over it in the program, for example:
C++
vec3 color=0;
for (i=0;i<8;++i)
{
 color=color+lights[i];
}

and it doesn't work properly.

I've noticed that even
C++
int j=0; vec3 v=lighs[j];

doesn't work ok, while:
C++
vec3 v=lights[0]; 

works fine.

What should I do?


*It's a runtime error- The results are not correct
Posted
Updated 1-Feb-12 11:09am
v3
Comments
Maximilien 1-Feb-12 14:15pm    
compilation error or runtime error ?
Fredrik Bornander 7-Feb-12 12:35pm    
I don't think you can just add lights like that.
For example if you have two lights A and B and both have value (1.0f, 1.0f, 1.0f), if you add them the sum would be (2.0f, 2.0f, 2.0f) but the range should be capped at [0.0f..1.0f], shouldn't it?
Or are you making sure that the sum is never greater than one?
stigersh 13-Feb-12 18:58pm    
Well I manage that, it's just not the point. Therefore I've simplified the code here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900