Light mapping in OpenGL

Started by
8 comments, last by Dark Druid 23 years, 3 months ago
I am trying to implement light simple light mapping with OpenGL, but I can''t seem to figure out exactly how to do it. What I am doing now is: Change DepthFunc to GL_LEQUAL and draw a polygon over athe previous, this DOES work, but I get some graphics glitches and it doesn''t seem to be the best way. What is THE way to do light mapping over existing polygons without resorting to the Multitexturing EXT, I have a feeling it involves the stencil bufer somehow... I know how to do the blending and all, I just want to be able to do the rendering correctly... Just to give you an idea what I am trying to accomplish: I am currently adding illumination maps to simulate lights on a rotating space station (obsured side will have lights and give it a cool look, plus you will actually be able to tell smething IS there instead of a dark spot when you are behind it...) Any insight would be greatly appreciated, Thanks!
Advertisement
check the multitexture extension on my site. it does lightmapping with
A/ multitexturing in 1 pass
B/ without multitexturing but with 2 passes

http://members.xoom.com/myBollux
Thanks for your help, but it doesn''t help me much since you are not drawing using the depth buffer, and you just have to draw in the right order...

I also can''t use the multitexture EXT since I want to place my light maps over simple untextured polygons.

I have been trying to use glDepthMask() to prevent overlapping of polygons, but I still get the same glitch!

I need to be able to put in place the light mapping sequence for a complex depth sorted environment (without using multitexturing, for now), if you can help me with that, it would be greatly appreciated.
i am using the depth buffer
OK another way
draw first one polygon.
then
enable glBlendFunc(GL_SRC_SOURCE, GL_ONE_MINUS_SRC_SOURCE);
draw the second polygon (which is black and has an alpha channel 0 for no shadow 1 to total blackness)

http://members.xoom.com/myBollux
yes, I know all that...

It''s what I am doing, the problem is that I get some grphic glitches when I do this, it might be because I am using a voodoo3 and it might be card specific, but I still get that error, the problem is you can''t use depth buffering on the lightmap polygon even with GL_LEQUAL as the depthFunc, some parts of the polygons will look "scratched"

I really need to find someone who has had this specific problem and knows how to prevent it
Here''s an interesting question:

What''s the difference in between, glDisable(GL_DEPTH_TEST) and glDepthMask(GL_FALSE)

A 1,000,000 points to whoever can answer that question!
Hi,

Last question first:

glDisable(GL_DEPTH_TEST) does exactly that: disables the depth test function for each pixel. glDepthMask only enables/disables _writing_ to the z-buffer, not testing.

I use it to draw particles, since I want them to additively combine, and not just draw the nearest one.

I think the renderstate you need is: first pass glDepthFunc(GL_LESS), second pass glDepthFunc(GL_LEQUAL). Leave glDepthMask(GL_TRUE) on.

When I'm lightmapping, I render the lightmaps as the first n pass(es). This is important if you're going to want multiple lightmaps. If you do it the other way around, a lightmap that contains 0 in any areas will reduce the base texture to 0, and rendering a later lightmap with >0 in any area will fail to produce the right effect. I use GL_DST_COLOUR,GL_SRC_COLOUR when rendering the base texture, GL_ONE,GL_ZERO for the first lightmap, and GL_ONE,GL_ONE for the remaining lightmaps.

I don't know why you get problems with your code: what is this 'scratched' effect you describe? Does it look like a z fighting artifact?

HTH,

Henry

(edited when I realised I hadn't quite read the question properly)

Edited by - Gingko on January 13, 2001 11:45:10 AM
"z fighting artifact" would describe it...

It''s like some pixels from the lightmap (a few) are not drawn even though they should (depth test is at LEQUAL), almost as if sometimes some pixels tested as being behind even though they are equal --> Note: 3dfx depth buffer is at 16-bit for voodoo3... I tried increasing the precision by reducing the viewable volume, but it didn''t change anything at all.
That''s a good point concerning the order you draw ligthmaps, I was wondering about that problem lately, so that''s one question answered... (I used to draw them after)

But that still doesn''t solve my problem of depth buffering...

Here''s the basic code for an object...

NOTE: I use Illumination maps in this case, so blending function is ok...

Anything that stands out as being an error?

I''m stating to wonder if it''s not the use of quadrics that disrupts my graphics, I''m going to try using normal polygons...

glNewList(station_obj, GL_COMPILE);
// Main module
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);

glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glPushMatrix();
glCallList(StationL2.getDisplayList());
glTranslatef(0.0f, 0.0f, 0.01f);
gluCylinder(QuadricObj, 0.4, 0.1, 0.1, 32, 1);

glTranslatef(0.0f, 0.0f, -0.12f);
gluCylinder(QuadricObj, 0.1, 0.4, 0.1, 32, 1);

glCallList(StationL1.getDisplayList());
glTranslatef(0.0f, 0.0f, 0.1f);
gluCylinder(QuadricObj, 0.4, 0.4, 0.02, 32, 1);
glPopMatrix();

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);

glDepthFunc(GL_LEQUAL);
glPushMatrix();
glColor4f(0.4f, 0.4f, 0.4f, 1.0f);
glTranslatef(0.0f, 0.0f, 0.01f);
gluCylinder(QuadricObj, 0.4, 0.1, 0.1, 32, 1);

glColor4f(0.0f, 0.0f, 0.2f, 1.0f);
glTranslatef(0.0f, 0.0f, -0.02f);
gluCylinder(QuadricObj, 0.4, 0.4, 0.02, 32, 1);

glColor4f(0.4f, 0.4f, 0.4f, 1.0f);
glTranslatef(0.0f, 0.0f, -0.1f);
gluCylinder(QuadricObj, 0.1, 0.4, 0.1, 32, 1);
glPopMatrix();
glDepthFunc(GL_LESS);
glEndList();
ok, problem solved!

It was the quadrics all along... I should have gotten suspicious earlier when I saw the light glitches (normal generation)

Don''t know if this is specific to 3dfx cards though....

Spheres work ok though, it''s just the cylinders/cones that don''t work correctly, don''t know about the discs though...

Thanks for your contributions guys, good news is I was doing it right all along!

This topic is closed to new replies.

Advertisement