PDA

View Full Version : Multiple lights with vertex shaders



bostrov
08-04-2003, 11:09 AM
Quick question for you guys - say I've got a vertex program that's relativly complex and I want to compute values for up to eight lights that may be contribute to vertex lighting. I don't want to duplicate the same code eight times in the vertex program (and if fact that would run up on the instruction limit anyway for a typical 1.0 shader) - and of course we don't have branching or the equivilant of for loops or anything, so what do I do? How do you guys handle multiple enabled lights for a single vertex program?

Tom78
08-04-2003, 12:29 PM
Hmm, i think you should try to do it multipass. Make as many lights as possible in the first pass and then make the rest in the second (or third if the hardware is older). Is your shading model so complicated or why don't you want to duplicate the code ?

cu
Tom

bostrov
08-04-2003, 06:53 PM
The lighting model is exceptionally complicated - I'm right at the limit of the number of instructions in a 1.0 shader as it is..

jwatte
08-04-2003, 10:45 PM
It is not possible to duplicate the full OpenGL 1.1 lighting model in a version 1 vertex shader. Especially not if you do double-sided, etc.

One thing I've heard done is to bake all your ambient/diffuse lights into a single second-order spherical harmonic for irradiance, and compute that per-vertex. Then add specular using traditional computation; this might fit for 8 lights.