PDA

View Full Version : More than one lightmap



Leyder Dylan
10-23-2003, 10:36 AM
Hi,

I've a question :

How do you when you have more than one lightmap on a polygon ?

I've tryed to render the 2 lightmaps but only one is displayed. If I display the number 1 or 2 alone, no problem.

I'm almost sure that's is because I use only 1 texture unit and the same one for rendering each lightmap.

So, how do you do for rendering more than one lightmap ?

So, if I've 6 lightmap, should I use 6 texture units ? It has no sense, not ?


Thanks,


LEYDER Dylan


[This message has been edited by Leyder Dylan (edited 10-23-2003).]

gator
10-23-2003, 12:01 PM
If I understand your question, it's either single-pass multi-texturing if you have the
hardware to do it, or multi-pass multi-texturing if you don't.

This will tell you how many texture units your card has:

#include <GL/glext.h>

INT max_texture_units;
glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &max_texture_units );

But I'm sure you already know all of this? It is a very basic mult-texturing question.


[This message has been edited by gator (edited 10-23-2003).]

Obli
10-23-2003, 12:14 PM
Originally posted by Leyder Dylan:
...
So, how do you do for rendering more than one lightmap ?

So, if I've 6 lightmap, should I use 6 texture units ? It has no sense, not ?
...
Lightmaps are usually melt togheter at compile time by adding them. So for example, each light which is static is combined in the same lightmap, each light which pulsates at a certain rithm is another lightmap (which also contains all the other lights with the same rithm) and so go on.

Now, what you do really depends from the architecture of your engine and from the target machine. Fragment programming facilities are somewhat helpful here but keeping on the topic...

First point is to accumulate all the lights. In standard multitexturing this will take a tex unit foreach lightmap. Every other lightmap is added. After every lightmap has been added, it's just time to multiply. Sounds easy? It's not.
In case you don't have so much texture units (but I guess you can do interesting things with just 5 lightmaps and a 3 base textures and some cards will let you do that) I'm afraid you will have to use the so-dreaded multipass rendering using blendfuncs. Ack.
Some time ago, I took in consideration the idea to do ping-pong rendering using a special texture. It turns out that context switching is so expensive that it really kills **a lot** of performance so it does not pay so much if you're running low resolution.

gator
10-23-2003, 01:26 PM
Ah, if he means putting multiple OpenGL lights in a scene, then that is a different question altogether.

Leyder Dylan
10-23-2003, 01:47 PM
Hi,

Here's a screenshot, you'll understand :
http://users.skynet.be/fa550206/Slug-Production/Temp/Lightmap.jpg

Sorry but the forum doesn't include the image in the message, don't know why.

Yes I'm using Multitexturing and my GeForce 4 Ti 4200 has only 4 texture units. Damned ...


First point is to accumulate all the lights

Is it possible, for static lightmap to create only one texture with all lightmaps ?

What about the fragment program ?



[This message has been edited by Leyder Dylan (edited 10-23-2003).]

jwatte
10-23-2003, 02:57 PM
This only barely qualifies as "advanced" and only barely qualifies as "OpenGL," but what the hey. There is no "basic rendering questions" board that I know of, except flipcode/gamedev...

Here's one way of doing arbitrary numbers of light maps with a simple diffuse color texture per object:

1) clear framebuffer to ambient light color
2) Enable(BLEND); BlendFunc(ONE,ONE);
3) for each lightmap
3.1) for each object within radius of that light
3.1.1) render the object with the light map
4) BlendFunc(ZERO,SRC_COLOR);
5) for each object
5.1) render the object with full-bright diffuse color map

Leyder Dylan
10-24-2003, 04:53 AM
I can render the lightmap. My question was : How can I render more than one lightmap if I only use one texture unit with ARB multitexturing.

I can do that with the polygon offset ? How it's a wrong way ... ?

Ysaneya
10-24-2003, 05:06 AM
This is confusing as hell. Why would you want more than one lightmap per triangle ? Unless you are working with advanced hybrid techniques, more than one lightmap per triangle is not needed...



How can I render more than one lightmap if I only use one texture unit with ARB multitexturing.


Sorry ? You're not making any sense at all here. If you only use one texture unit... you're not doing any MULTItexturing at all.

Y.


[This message has been edited by Ysaneya (edited 10-24-2003).]

Tom Nuydens
10-24-2003, 05:50 AM
Originally posted by Ysaneya:
This is confusing as hell. Why would you want more than one lightmap per triangle ? Unless you are working with advanced hybrid techniques, more than one lightmap per triangle is not needed...

I recall from one of his previous posts that he uses the term "(dynamic) lightmapping" to describe what is actually attenuation mapping.

The answer to the problem is exactly what jwatte posted. Also note that the very first pass should not use blending, because that one will need to lay down the Z-buffer. You also need to switch to DepthMask(FALSE) and DepthFunc(GL_EQUAL) after the first pass.

-- Tom

Leyder Dylan
10-24-2003, 06:30 AM
Oups, sorry jwatte to haven't followed your advice.

Kick my ass.

That's work.

V-man
10-24-2003, 07:43 AM
>>>DepthFunc(GL_EQUAL) <<<

why not use GL_LEQUAL globally

gvm
10-24-2003, 09:42 AM
amm.. i thought a little about rendering of multiple lights...
what if we will prepare some kind of geometry dependend from current object(which will be lighted) and light position and do same attenuation mapping on this?
i think it will speed up perfomence if we will render that triangles(which will be lighted) on all scene with blending(it will be faster because we don't render all scene).
i mean:
1. render full scene
2. check all triangle/quad's vertices and prepare "light-geometry" for each object and light.
3. render those...

Leyder Dylan
10-24-2003, 12:47 PM
Now another problem.

The other textures are transparent :

http://users.skynet.be/fa550206/Slug-Production/Temp/Lightmap.jpg

gvm
10-25-2003, 04:19 AM
which one? i see a wall with lightmap strangly clamped on sides.
if it's clamped by other lightmaps then you blend them not right...
ammm. 13fps???? on Ti4200?

Leyder Dylan
10-25-2003, 06:50 AM
13 fps ??? It's when I take the screenshot, the FPS is always down ...

Here's the good lightmap with the 2 lightmaps :

http://users.skynet.be/fa550206/Slug-Production/Temp/Lightmap1.jpg


And the problem :

http://users.skynet.be/fa550206/Slug-Production/Temp/Lightmap2.jpg

For the blending, I use :




glBlendFunc(GL_ONE, GL_ONE);

// We enable the Blending
glEnable(GL_BLEND);

// 1. First Texture Unit
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_3D_EXT, Attenuation_Texture);
glEnable(GL_TEXTURE_3D_EXT);

// Render the lightmap

// We disable the First Texture Unit
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_3D_EXT);

glBlendFunc(GL_DST_COLOR, GL_ZERO);

// Render the map

// Disable the blending
glDisable(GL_BLEND);


And the 3D Texture params :




// ...
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// ...




[This message has been edited by Leyder Dylan (edited 10-25-2003).]

jwatte
10-25-2003, 03:01 PM
Tom,

You're right, there's a bug in the technique I suggested. Rather than "clear framebuffer to ambient" what you want to do is "clear Z buffer, and draw all geometry using only ambient color." Then you can turn off Z writes for the successive passes, which is nice.

gvm
10-26-2003, 02:30 AM
for what you are using blending?
blending should be used for multipass rendering of scene here to make multiple lights.
but it looks like you think that blending blends textures in multi-texturing http://www.opengl.org/discussion_boards/ubb/smile.gif no!
textures are mutliplyied or added through glTexEnv
e.g. glActiveTexture(...0); glTexEnv(..., GL_REPLACE);
glActiveTexture(...1); glTexEnv(...,GL_MODULATE);
render(); // renders something with two textures...

for making multiple lights you must do: (pseudo-code) (don't take too seriously...)
// first pass
glBlendFunc(GL_SRC_COLOR, GL_ZERO);
active_texture(0); bind(atten_map);
actuve)texture(1); bind(decal_tex);
render_scene();
// second and other passes...
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
active_texture(0); bind(atten_map);
actuve)texture(1); bind(decal_tex);
render_scene(); // again
...

Leyder Dylan
10-26-2003, 04:27 AM
gvm,

I used because that's work http://www.opengl.org/discussion_boards/ubb/smile.gif

I didn't thought about your idea, thanks, I'm gonna try that today.

Perhaps the bug will be fixed with that.

gvm
10-26-2003, 09:46 AM
ohhh... sorry, i've made mistake. http://www.opengl.org/discussion_boards/ubb/frown.gif
there's just no need in second glActiveTextureARB(GL_TEXTURE0_ARB);
i just thought that there is glActiveTextureARB(GL_TEXTURE1_ARB);
but in your case all ok... just it's better to use multitexturing, but no multipassing

I think that problem is in this: glBlendFunc(GL_DST_COLOR, GL_ZERO);

this will just replace lightmap with decal-texture, but it must be modulated together here...

and it couldn't work just because of
glBlendFunc(src,dst);
so maybe this: glBlendFunc(GL_SRC_COLOR, GL_ZERO); // but this will replace...
try next:
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);