View Full Version : Vertex Program for n input values

12-17-2002, 11:55 AM
Just working on a vertex program based lighting system. I'm just wondering how to support multiple lights since the GL_VERTEX_PROGRAM_ARB doesn't support looping (as far as i know). I can easily pass several points to the vertex program indicating light locations, but how would i iterate through these lights. If it where a fixed number of lights that I know when writing the vertex program I could just cut and paste the code for each light and accumulate it in the result, but I can't assume that the number of lights is known at write time. I also realize that the specs for GL_VERTEX_PROGRAM_ARB specify: " Vertex programs execute a finite fixed sequence of instructions with no branching or looping." But their must be a way to handle an unknown amount of imput at run time. Thanks for any help or suggestions

12-17-2002, 12:41 PM
NV_vertex_program2 supports looping...

- Matt

12-17-2002, 11:13 PM

before falling to proprietary extensions, here is another way. You sure don't know how many lights there will be at write time but as u know your vertex program is just a string.
You can do your "cut and paste" in your program.
That just means uploading your vertex program each time your number of lights change.

Just to be sure i'm clear just do :
char part1[] = "blah blah";
char eachlight[] = "blah light_id blah";
char end[] = "blah";

you can then do a search/replace of light_id by the one you use and insert the code of eachlight in a loop.
Whether u use one program and change it or create a few programs if your number of lights are changing realy often is up to your app.

12-18-2002, 03:34 AM
Thanks for the replies, is there a large performance hit for uploading new vertex program?

12-18-2002, 04:41 AM
Originally posted by Walrus:
Thanks for the replies, is there a large performance hit for uploading new vertex program?

Don't really know but for one per frame i didn't see any impact