Originally posted by Leyder Dylan:
[b]…
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 ?
…[/b]
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.
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:
clear framebuffer to ambient light color
Enable(BLEND); BlendFunc(ONE,ONE);
for each lightmap
3.1) for each object within radius of that light
3.1.1) render the object with the light map
BlendFunc(ZERO,SRC_COLOR);
for each object
5.1) render the object with full-bright diffuse color map
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).]
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.
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:
render full scene
check all triangle/quad’s vertices and prepare “light-geometry” for each object and light.
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?
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.
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 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
…
ohhh… sorry, i’ve made mistake.
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);