what glBlendFuc to use ?

Started by
3 comments, last by stryx 21 years, 11 months ago
Hi, I've got a problem displaying my lightmaps correctly. Here are some lightmaps:
And some textures: What params should I use with the glBlendFunc to get an correct looking lightmap effect ? Thanks, stryx [edited by - stryx on May 1, 2002 5:39:40 PM] [edited by - stryx on May 1, 2002 5:40:39 PM]
Anything that requires finding convex hulls in realtime isstarting to sound like a bad idea. -- John Carmack
Advertisement
Well, it depends on which order you draw them in. What I did was draw the lightmaps first, with glBlendFunc(GL_ONE, GL_ZERO), then draw the texture maps, with glBlendFunc(GL_ZERO, GL_SRC_COLOR).

Edit: That was using Quake 3's textures and lightmaps, BTW.

[edited by - Martee on May 1, 2002 5:44:57 PM]
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Martee's method will work, even though I'd recommend disabling blending in the first pass instead of using glBlendFunc(GL_ONE, GL_ZERO)

It's also known as shadow-mapping since the real thing you do is adding shadows, not really adding light.
That is, if you skip the 'lightmap' pass your scene will be fully bright, so using 'lightmaps' only adds shadows and that's why it's sometimes called 'shadowmaps'

If possible, I'd recommend multi-texturing with your ground/metal texture in texture unit 0 and the lightmap in texture unit 1, and use the texture environment function GL_MODULATE in texture unit 1. It is alot faster (if the graphics card supports it in hardware of course) and saves the usage of blending, thus allowing various blending effects on your lightmapped object(s).

[edited by - vincoof on May 2, 2002 3:19:52 AM]
well.. if you know that white is 1 and black is zero, then you easy find out that you want to multiply your lightmap with your base-texture, as multiplying a white part with the base texture results in 1*basetex = basetex, and multiplying a black part with the base texture results in 0*basetex = 0 = black...

next you need to know is what the blendfunc does..

lets call the parameters of the blendfunc like this:
glBlendFunc(param0,param1);

then what it does while drawing onto the framebuffer is this:
framebuffercolor = trianglecolor*param0 + framebuffercolor*param1

you''ve drawn for example in the first pass your lightmaps into the framebuffer, so framebuffercolor is your lightmap..

now you want to multiply your new trianglecolor in the second pass with it (cause in the second pass your trianglecolor is the basetex)..

this means..
glBlendFunc(GL_ZERO,GL_SRC_COLOR);

wich results in
framebuffercolor = trianglecolor*0 + framebuffercolor*GL_SRC_COLOR

and GL_SRC_COLOR is your sourcecolor, the trianglecolor how i called it...

resulting equation:
pass0:
framebuffer = lightmap
pass1:
framebuffer = basetex*framebuffer

together:
framebuffer = basetex*lightmap

its all about math.. (and when you get into multitexturing and bumpmapping and all that stuss, it gets much much more complicated at first.. once you got how the stuff works, its easy, then you only need some shit of paper and some math..)

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Ok, Thanks Guys.

I know how to use it with the ARB_multitexture, but I want to support it on cards that don''t "speak" ARB_multitexture.

(my Laptop and the computers at my school


Thanks @ll
Anything that requires finding convex hulls in realtime isstarting to sound like a bad idea. -- John Carmack

This topic is closed to new replies.

Advertisement