Archived

This topic is now archived and is closed to further replies.

stryx

what glBlendFuc to use ?

Recommended Posts

stryx    122
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]

Share this post


Link to post
Share on other sites
Martee    476
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]

Share this post


Link to post
Share on other sites
vincoof    514
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]

Share this post


Link to post
Share on other sites
davepermen    1047
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

Share this post


Link to post
Share on other sites
stryx    122
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

Share this post


Link to post
Share on other sites