Dinamic lights

I’m writing a demo which will use dinamic lights. I read that u should use binormals and tangent(used for bump mapping too) from the faces to do that in the right way. What’s the better way to store the vertexes and faces (the structs/classes)?
i’m thinking this way:
class cVECTOR3D
{
float x,y,z;
};

class cFACE
{
cVECTOR3D verts[3]; //or
int verts[3]; //to eliminate
//doubled entries
int tex_coord[2];

cVECTOR3D normal;
cVECTOR3D binormal;
cVECTOR3D tangent;
};
Can i use binormal and tangent to calculate both dinamic lights and bump mapping? Is those structs rights or is it missing something?
Thanx (and sorry about my english)

1. You don´t need binormals and tangents for dynamic lighting, only for bump-mapping.

2. You should add a float for the plane-equation of that triangle, to be able to do backface-culling.

Jan.

But when using 2d textures, how do i calculate the S and T coordinates from the dinamic light without binormal and tangent?

First you create a 3D lighting texture.

Then you put your base texture into Texture Unit 0 and your 3D lightmap into Texture Unit 1.

Put into the texcoords of TU 0 your usual texcoords and into the texcoords of TU 1 you put the vertex-position (so you need 3 texcoords on TU 1).

The activate TU 1 and call:

glMatrixMode (GL_TEXTURE);
glMatrixMode (GL_MODELVIEW);

That´s it. With this setup you can perform dynamic lighting (without bumpmapping). When doing bumpmapping, it gets a bit harder. For bumpmapping vertex-shaders come in VERY handy + you need to use register combiners or fragment programs (nVidia vs. ATI).

http://www.ronfrazier.net/apparition/

(under “Research Project”). It´s quite helpful.

Hope that helps you.
Jan.

EDIT:

With this line i´m not so sure:

It could be, that you first have to transfom and than to scale (but i don´t think so) and it could be, that you don´t need to negate the Lightposition in the transformation. But i think it´s shown correctly in the article i mentioned.

[This message has been edited by Jan2000 (edited 08-05-2003).]

Thanx Jan…i helps me, but the problem is that i wanna do it with only 2d textures for lighting … and other question: if my texture units were full, can i do the lighting (with 3d texture) in a different pass, using blend?

I used a 3d texture for lighting (instead of 2 textures), but in a radeon 7500 (that is supposed to support it), it runs very slowly…but i saw a demo (but with directx) that runs at mid-speed…is 3d textures done by software in radeon 7500? or could it be another error im doing?

sorry…i found out that using GL_CLAMP_TO_EDGE was the problem…now im using only GL_CLAMP and it works fine…

However i think in the article i mentioned, he does use a 1D and a 2D texture instead of a 3D texture. Both solutions should be equally fast, but both have their drawbacks:
A 3D texture uses a LOT of memory, so you cannot use a very highres texture (i would say more than 128128128 is insane), BUT you only need on texture-unit (which can be very important).
With the other approach you can use much higher resolutions, so the light quality will be better, but on cards with only 2 or 4 texture-units, you will pull your hair out, when you want to do some more advanced stuff and need that one additional texture-unit!

And yes, you can do several passes for lighting and stuff. This is how i do it:

1. z-only pass

then for every light

1. diffuse, bumpmapped, attentuated light
stored in alpha channel

2. base-texture blended with the alpha-channel (plus some other effects)

3. specular lighting, attentuated by the value which is stored in the alpha-channel

Actually my bumpmapped specular lighting is not physically correct. However it is high-quality “specular” lighting and looks pretty good. Real bumpmapped specular lighting is not possible without fragment programs (i have a Geforce 4). At least not high-quality bumpmapped specular lighting (and don´t tell me about texture-shaders and stuff, i tried it all!)

I think it´s strange that GL_CLAMP_TO_EDGE is a slowdown on a Radeon. I use clamp-to-edge and it doesn´t slow down a bit. But with GL_CLAMP it should just work fine. But make sure that your texture-border color is always set to black, or you might get artifacts.

If it helps you: “Game Programming Gems 1” has an article about attentuation maps (1D + 2D textures) and explains how to use them in OpenGL for dynamic lighting.

Dynamic lighting is real fun, but it´s not easy to optimize. Get used to framerates of 20 or 30 FPS.