gloss mapping using seperate gloss texture

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.

Textures:

  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?

I hope you’re familiar with ARB_texture_env_combine.

Te0 rgb: modulate (tex0.rgbtex1.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.

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:

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 , 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
glActiveTextureARB(GL_TEXTURE0_ARB);
//set "combine" mode
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_ARB);
//set rgb function
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_MODULATE);
//set inputs to rgb function
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SRC_COLOR);

//set alpha function
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA_ARB,GL_REPLACE);
//set input to alpha function
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_ARB,GL_TEXTURE0_ARB);
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.

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! :slight_smile:

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…

The problem with this is that typically the lightmap has different texture coordinates than the glossmap, and it often has a much lower resolution.