Click here to Skip to main content
11,923,046 members (62,490 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ OpenGL GLSL
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)
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
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151125.3 | Last Updated 1 Feb 2012
Copyright © CodeProject, 1999-2015
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