PDA

View Full Version : environment mapping over a texture



Arath
11-15-2000, 11:44 AM
hey,

it's me again, I don't know how I can draw a mesh with environment mapping and a texture over or vice-versa, do I need to use multi-texturing? Is there any examples, or source available on a URL?

Cheers

Arath

Rob The Bloke
11-15-2000, 01:34 PM
Two Possibilities:

1. Non-Multitexturing

Draw The Object with The Surface Texture applied.

Next, Draw Again the same Object With the Environment Map on it.

When doing this however, you must do one of two things first...

You Must Change the Depth Test to GL_LEQUAL to allow you to draw in exactly the same space. Second, you'll need to set up blending with a function of GL_ONE,GL_ONE to Blend them in equal portions.

The code will look like....

glBindTexture(GL_TEXTURE_2D, Surface_Texture);
DrawObject();

glBlendFunc(GL_ONE,GL_ONE);
glDepthFunc(GL_LEQUAL);
glEnable(GL_BLEND);

// Enable Sphere or Cube Mapping here.....

glBindTexture(GL_TEXTURE_2D, Environment_Map);
DrawObject();

// Disable Sphere or Cube Mapping Here....

glDisable(GL_BLEND);

2. The Multitexturing Method

//Set Up your two texturing units...

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,Surface);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D,environment);
// Enable Cube Or Sphere Mapping Here....

// Then Draw Your Object
DrawObject();


Bear in mind that if you are making openGL work out the texturing co-ords for you, then you can just use glTexCoord*(); to specify your texturing co-ords for the first texturing unit. The only problem with using multitexturing for doing this, is that you will not get as much control as you would with multiple rendering passes. Some openGL drivers also find this kind of thing a bit too hard to handle.

If you have a Geforce series of card, it may pay to look at the register combiners to speed things up and give you back the control of multiple passes.

If you want to take things a wee bit further, you can add an alpha channel to the surface texture. When doing the second pass, try using:

glBlendFunc(GL_DST_ALPHA,GL_ONE_MINUS_DST_ALPHA);

This will draw the environment map only in places where the alpha channel of the texture has a value of 1, Thus giving you a very crude form of gloss mapping....