PDA

View Full Version : light a portion of a polygon



dpgraves
02-20-2002, 07:05 AM
In the Unreal engine, the default light that I can place in a level lights up a certain circular section of the ground polygon and then the rest of it is still dark. Then the walls are lit with a certain intensity depending on the light's brightness and radius settings. I'd like to achieve this same affect in OpenGL but I can't figure out how. I believe I can do it with a spot light, but I either get no light at all or it lights up every object in the scene evenly. The light I place is a positional light source located at (0,50,0). I want this light to point down the y-axis. Below is the code I have for the light

GLfloat direction[3] = {0.0f,-1.0f,0.0f};
GLfloat light[4] = {1.0f,1.0f,1.0f,1.0f};
GLfloat position[4] = {0.0,50.0,0.0,1.0f};

glLightfv(GL_LIGHT0,GL_POSITION,position);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light);

glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,95.0f);
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,10.0f);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,direction);

glEnable(GL_LIGHT0);

glEnable(GL_LIGHTING);

I've tried different values for the spot exponent and cutoff.
I'm trying to do this with texturing on, and in modulate mode. Is there something I need to do with the texturing options so that only a circular section of the texture is lit up? Thanks for the help.

Bob
02-20-2002, 12:54 PM
OpenGL's lighting operates per vertex. For each vertex you pass to OpenGL, the light is calculated, and then interpolated across the primitives. If you have a spotlight shining on the middle of a quad, where all four vertices are outside the view cone of the light, all vertices will have a black (or close to black) color. This color is then interpolated, and the whole quad will be black.

To get a bright spot in the middle of the quad (in my example) you need to split the quad into several small quads, so OpenGL can perform the lighting equation in smaller intervals.

As for Unreal, I assume it don't use standard OpenGL lighting at all, but uses it's own. And I also assume it uses a form of lightmaps.

dpgraves
02-20-2002, 02:20 PM
Ok thanks. That brings up another question that I've been curious about. How can games like Unreal and Quake make use of 3d hardware acceleratation, if they're using their own code for things like lighting and texturing? For example, if I want my 3d graphics card to perform texturing I have to make calls to OpenGL which will then take care of the texturing by using the driver for the appropriate video card. But then that means I have to use OpenGL's texturing functions right?

dpgraves
02-20-2002, 02:34 PM
I think Lightmap is what Unreal uses, and I believe it would achieve the effect I want. Is there a lightmap extension to OpenGL? I'll take a look. I was also reading on this forum and per pixel lighting was mentioned. That I know would definitely achieve that effect, but Unreal couldn't have been doing per pixel lighting.

Bob
02-20-2002, 11:45 PM
Per pixel lighting techniques today does not use the standard OpenGL lighting system. It mainly uses textures to simulate light sources, in about the same way lightmaps works.

A lightmap is nothign special. It's a regular texture. The way you use it, it seems like it represent a light source.

As long as you are using a texture to simulate the light source, you are not really doing per pixel lighting, but per texel lighting.

NVIDIA's developer site (http://developer.nvidia.com/) has lots of cool stuff. Have a look there.