Click here to Skip to main content
13,143,185 members (54,724 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 6:34am
Updated 1-Feb-12 11:09am
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 |
Web02 | 2.8.170915.1 | Last Updated 1 Feb 2012
Copyright © CodeProject, 1999-2017
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