Advertisement

blending lightmaps

Started by December 10, 2002 01:42 PM
20 comments, last by Crispy 22 years, 2 months ago
Hi, generally I don''t get this confused this easily, but right now I can''t think of a single good combination of blending functions. I need to map a lightmap onto a bunch of textured faces where the lightmap is in the usual form (basically a white blotch on black), so that the original faces'' texture would be prevalent and the lightmap would only be seen where the lightmap texture is non-black. In a word, the usual lightmapping.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Do you want your lightmap to brighten the scene, or fo you want to darken it ?
In other words, do you want it to be a lightmap or a shadowmap ?
Advertisement
I''d like it to be a lightmap - mostly for projectiles as they come close to world geometry.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
What do you want to brighten ? Do you want to render your lightmaps exactly on your walls, or do you want to render arbitrary quads around the scene like if there was smoke filling the room ?
quote:
Original post by vincoof
... or do you want to render arbitrary quads around the scene like if there was smoke filling the room ?


I''m not sure what you mean by that. Anyway, my aim is to add a glow (bright), to the world geometry. For example if the light source were yellow, the lighmap would be drawn with glColor set to yellow, illuminating any face in comes near.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
okay, so you want to apply a lightmap over objects, just like if you used standard OpenGL lighting except the fact that lightmaps allow lighting to be done per-pixel instead of per-vertex.

According to the beginning of the thread, I think that you already have your lightmap texture, and that you already computed your texture coordinates, but what you need is the "pixel shader" that gives the effect of lighting. Is that right ?

If you render your lightmap through multitexturing, you just have to set the texture environment of the lightmap texture unit to GL_ADD (need the ARB_texture_env_add extension or OpenGL1.3+), for instance :
glActiveTextureARB(GL_TEXTURE1_ARB); // Lightmap in second texture unit
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); // Tell the lightmap to be "added" which will brighten the scene where the lightmap is white, and won''t change the scene where the lightmap is black.

Without multitexturing, you have to perform multipass with blending enabled using the following blending function in the pass where you render your lightmap :
glBlendFunc(GL_ONE, GL_ONE); // Also known as "Additive blending"... guess why ?

Is that what you looked for ?
Advertisement
quote:
Original post by vincoof
okay, so you want to apply a lightmap over objects, just like if you used standard OpenGL lighting except the fact that lightmaps allow lighting to be done per-pixel instead of per-vertex.



Pretty much, yeah. Per-vertex (or true dynamic lighting) is a little too much for this engine - too many vertexes (at least 300 for even a small light). I''m actually lightmapping the same landscape that can be seen in the reflections thread...

quote:

According to the beginning of the thread, I think that you already have your lightmap texture, and that you already computed your texture coordinates, but what you need is the "pixel shader" that gives the effect of lighting. Is that right ?



Regarding the texture coordinates, I''m still working on that - something''s not 100% correct, but I''ve extracted the faces that need lighting and the rest is a ok.

quote:

If you render your lightmap through multitexturing, you just have to set the texture environment of the lightmap texture unit to GL_ADD (need the ARB_texture_env_add extension or OpenGL1.3+), for instance :
glActiveTextureARB(GL_TEXTURE1_ARB); // Lightmap in second texture unit
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); // Tell the lightmap to be "added" which will brighten the scene where the lightmap is white, and won''t change the scene where the lightmap is black.



Très futé, but I''m already out of texture units

quote:

Without multitexturing, you have to perform multipass with blending enabled using the following blending function in the pass where you render your lightmap :
glBlendFunc(GL_ONE, GL_ONE); // Also known as "Additive blending"... guess why ?

Is that what you looked for ?


I won''t hazard a guess - it''s 2 AM Anyway, I think the problem is a wee bit more complicated. I''ll enumerate what I''m doing right now (wow - I''m already talking C):

1) Disable blending
2) Draw the world
3) Enable blending
4) Set glBlendFunc(GL_SRC_COLOR, GL_ZERO); because I want to see throught the darker pixels
5) Draw the lightmaps

However, now nothing appears on the "right" side - though the lightmaps are well visible from below. Maybe this is because of z-fighting which, then again, should be accompanied by shearing. I''ve never had to deal with it so I''m not so sure...

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Your algorithm seems right, except the fact that I wouldn''t use SRC_COLOR, ZERO without checking first if the NV_blend_square extension or OpenGL1.4 is supported.

Which "right" side ? Do you mean the right part of the window ? The triangles that are facing right (normals point to the right side) ?
quote:
Original post by vincoof
Your algorithm seems right, except the fact that I wouldn''t use SRC_COLOR, ZERO without checking first if the NV_blend_square extension or OpenGL1.4 is supported.




Why''s that?

quote:

Which "right" side ? Do you mean the right part of the window ? The triangles that are facing right (normals point to the right side) ?



The "right" side is the "up" side - in other words the side of the polygons that is not culled.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
When you call glBlendFunc(sfactor, dfactor) the sfactor is what is multiplied by the source color and dfactor is what is multiplied by the destination color, right ?

But according to OpenGL Specifications 1.0, scolor may not be SRC_COLOR (neither ONE_MINUS_SRC_COLOR) and dfactor may not be DST_COLOR nor ONE_MINUS_DST_COLOR. You can check this manual page hosted at opengl.org .

Though, NVIDIA introduced the ability to let the source be multiplied by source and destination multiplied by destination. This was exposed through the NV_blend_square extension (spec here).
And later, this became part of the OpenGL core (in OpenGL1.4).

What I mean is that you may check the availability of the NV_blend_square extension or tha availability of OpenGL1.4 before you use this feature.


Ok I understand your "right" side. You mean front faces I guess
Does your lightmap appear correctly on back faces, and don''t appear on front faces ? That''d be weird.

This topic is closed to new replies.

Advertisement