Is there a vertex/fragment program(s) which implement FULL lighting equation, no just diffuse lighting?

[This message has been edited by EnemyOfTheStateMachine (edited 01-06-2004).]

[This message has been edited by EnemyOfTheStateMachine (edited 01-06-2004).]

V-man

01-06-2004, 07:39 AM

I have done it for point and directional lights in vp: http://www.geocities.com/vmelkon/verybasicvp.html

(the site seems to be down. Says too many visitors)

I've also done in fp, but haven't uploaded it.
Also did it for spot lights in fp. It looks a few million times better in fp.

Ostsol

01-06-2004, 08:44 AM

Yeah, it's not especially difficult. Once you figure out how to get the light positions and eye position properly transformed, it's just a matter of turning the equation into code -- which isn't all all hard, especially in GLSL.

jwatte

01-06-2004, 02:07 PM

Note that the full lighting equation (with specular) is one of the samples in the ARB_ program specifications.

Also, the math itself is defined in the OpenGL specification, and written out in in the red book. Writing the code is an excercise in typing, mostly. Especially if you do it in Cg and compile to ARB_ assembly :-)

Note that you need a (slightly) different program for each light type: point light, spot light and directional light. Some of them can sometimes be merged using cute tricks, but it's more robust if you use different programs specialized for each kind.

V-man

01-06-2004, 07:41 PM

I think I'm not computing attenuation in there. So you may need to plug in a few extra instructions.

With NV_vp2, it's possible to code all light types in a single program.

Also, if you want to implement the whole GL lighting in fp, then you can do at most 2 lights per pass because of instruction limitations on ATI. 2 point lights with no attenuation that is.

harsman

01-09-2004, 04:46 AM

If you really need the FULL OpenGL lighting equation you also need to handle two sided lighting correctly. Besides the asembly extension spec there's also cod3e for this in the GLSL spec if I remember correctly.

titan

01-10-2004, 09:29 AM

Originally posted by EnemyOfTheStateMachine:
Is there a vertex/fragment program(s) which implement FULL lighting equation, no just diffuse lighting?

As others have said there are examples out there. However you will not be able to have a vertex program fully emulate the standard OpenGL lighitng model since you can't do something like this yet:
for(i = 0; i < 8; i++)
{
switch(light[i].type)
{
case directional:
...
break;
case point:
...
break;
case spot:
...
break;
}
}

I haven't been following the rumours very well. When do the rumours claim we'll be able to do something like this? Next generation?

SirKnight

01-10-2004, 01:48 PM

I admit I havn't used NV_vp2 yet but I think that by using this extension, that code there can be done by replacing the switch and case with ifs.

EDIT: Um yeah I forgot to mention that I'm talking about using Cg with the profile that spits out NV_vp2 code. Not by typing ifs in a NV_vp2 program directly, as the compiler would go bananas. http://www.opengl.org/discussion_boards/ubb/smile.gif

-SirKnight

[This message has been edited by SirKnight (edited 01-10-2004).]

jwatte

01-10-2004, 01:54 PM

Titan,

To "fully" handle the pipeline, you have to split the shader in two for front- and back-facing lighting (if you use two-sided). You can then just assemble the vertex program (and/or fragment program) using text snippets that are written to handle point, spot and directional lights, for all enabled lights.

Thus, it IS possible, although depending on the quality you want to use per light (iterate on root finding, etc) you may run out of shader instructions on some cards.