Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL GLSL
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
uniform vec3 lights[8];
then I loop over it in the program, for example:
vec3 color=0;
for (i=0;i<8;++i)
{
 color=color+lights[i];
}
and it doesn't work properly.
 
I've noticed that even
int j=0; vec3 v=lighs[j];
doesn't work ok, while:
vec3 v=lights[0]; 
works fine.
 
What should I do?
 

*It's a runtime error- The results are not correct
Posted 1-Feb-12 7:34am
Edited 1-Feb-12 12:09pm
(no name)325.7K
v3
Comments
Maximilien at 1-Feb-12 14:15pm
   
compilation error or runtime error ?
Fredrik Bornander at 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 at 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)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 1 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100