Jump to content
  • Advertisement
Sign in to follow this  
kulik

GLSL multiple lights

This topic is 4761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am now trying to code a complex lightmodel shader to handle all types of lights in my engine. I want to support unlimited amount of lights. Lights *will* be additive, so a loop inside the shader should do the job. The problem is: how to transfer the light parameters from C++ into GLSL. I know I could do it with mat4 and decode it somehow inside the shader, this solution is ugly and limited though ... Can I use some "elegant" way of doing that? btw: I know about gl_LightSources array, but that is limited and kinda unextendable. [Edited by - kulik on October 5, 2005 11:11:43 AM]

Share this post


Link to post
Share on other sites
Advertisement
Unless you're programming for Geforce 6800 and similar cards(ps3.0) that support true branching and texture/memory lookups in vertex shaders, you can't do it, not in a way that is practically usefull anyway. In any other card, a loop is not real, GLSL just duplicates the loop body many times. Ang generally, most cards don't have the possibility to transfer the control from one instruction to another, they execute the whole program from beginning to the end. If you write:

for (int i=0;i<5;++i)
{
value=value+gl_LightSource.diffuse;
}

It will be translated(before compilation) into:

value=value+gl_LightSource[0].diffuse;
value=value+gl_LightSource[1].diffuse;
value=value+gl_LightSource[2].diffuse;
value=value+gl_LightSource[3].diffuse;
value=value+gl_LightSource[4].diffuse;

So you see the compiler must even know the number of the loops before compilation(it can't be dynamic) and after a number of lights, you will exceed the instruction limit. Also, if you try to handle all light types inside the shader, all calculations(for directional, spot,point lights...) will take place.
For example:

if (pointlight) col=dot(V-L,N);else col=dot(V,N);

In this case, both "col=dot(V-L,N)" and "col=dot(V,N)" will be executed and the results will be stored in temporary registers, and at the end col will be assigned the correct value by masking or something like that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!