View Full Version : gloss mapping using seperate gloss texture

06-24-2005, 10:03 AM
I'm trying to do 'gloss mapping' using nothing but multi-texturing and cubemaps in a single pass (FYI: using this method for older cards that don't support shaders well).

I've come across quite a few threads, demos and tutorials but they all make use of a glossmap stored in the alpha channel of the diffuse texture.

However, I would like to reserve this channel for blending/alphatesting and use a seperate GL_LUMINANCE texture for the glossmap instead.

I'm confused however how to set up the texture environments, in particular the glTexEnvi calls.

1) diffuse+alpha (GL_RGBA)
2) lightmap (GL_RGB)
3) reflection/specular cubemap (GL_RGB)
4) gloss map (GL_LUMINANCE)

Specular/reflection should be additive, but not be 'shadowed' by the lightmap.

So how do I go about setting up these textures?

06-24-2005, 01:09 PM
I hope you're familiar with ARB_texture_env_combine.

Te0 rgb: modulate (tex0.rgb*tex1.rgb)
Te0 a: replace (tex0.a)
Te1 rgb: mad (tex2.rgb*tex3.rgb+previous.rgb)
Te1 a: replace (previous.a)
Te2: just pass through rgb and alpha
Te3: ditto

You need crossbar support for this. At least I don't see how it would work without it atm.

06-25-2005, 07:31 AM
I'm sorry, but I don't quite understand what you posted. Could you please elaborate?

I'd like to know what effect each glTexEnvi call + parameter in this case has.

I can get around with blend modes, but honestly I've never really understood it, same with this... :confused:

06-26-2005, 09:46 AM
I thought you already knew how the texture environments work because you posted to the advanced forum. You would have gotten a better initial response in the beginners forum. No offense.

You want to use "combine" mode for all four texture environments. This allows you to specify, per texture environment, separated by rgb and alpha, a function and up to three inputs to that function, and optional source inversion.

Have a look at the ARB_texture_env_combine spec (http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt) , or section 3.8.13 in the core GL spec (ARB_tec was promoted to core with OpenGL 1.3).

////settings for texture environment 0
//set "combine" mode
//set rgb function
//set inputs to rgb function

//set alpha function
//set input to alpha function
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_ARB,GL_ SRC_ALPHA);Unfortunately, my suggestion for the next texture environment needs even more extensions. Either ATI(X)_texture_env_combine3 or NV_texture_env_combine4. There is no multiply-add function in the base ARB_texture_env_combine, and this is absolutely required here. Sorry.

06-27-2005, 03:28 AM
Originally posted by zeckensack:
I thought you already knew how the texture environments work because you posted to the advanced forum. You would have gotten a better initial response in the beginners forum. No offense.No problem, even though I've coded some imho advanced stuff I just never understood this for some reason.

But that example code you posted got me thinking. I'm sure I'll be able to figure out the rest.

Thanks a lot! :)

06-27-2005, 10:46 PM
If possible, you might want to put your gloss texture into the lightmap's alpha channel..
RGB textures are stored as RGBA internally in most graphics cards anyway..

06-27-2005, 11:20 PM
The problem with this is that typically the lightmap has different texture coordinates than the glossmap, and it often has a much lower resolution.