PDA

View Full Version : gloss mapping using seperate gloss texture



remdul
06-24-2005, 11: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.

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?

zeckensack
06-24-2005, 02: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.

remdul
06-25-2005, 08: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:

zeckensack
06-26-2005, 10: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
glActiveTextureARB(GL_TEXTURE0_ARB);
//set "combine" mode
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_CO MBINE_ARB);
//set rgb function
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_MOD ULATE);
//set inputs to rgb function
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_TEX TURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SR C_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEX TURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SR C_COLOR);

//set alpha function
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA_ARB,GL_R EPLACE);
//set input to alpha function
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_ARB,GL_T EXTURE0_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.

remdul
06-27-2005, 04: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! :)

LogicalError
06-27-2005, 11: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..

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