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)328.8K
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 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 BillWoodruff 108
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web02 | 2.8.141220.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