Sign in to follow this  
Zorbas-E-

How to use primary color in simple Normal Mapping?

Recommended Posts

Hello everyone,

I have recently been able to impement the simple bump/normal mapping technique for my hobby game engine. This technique is based on Nehe's tutorials and Paul Baker's relatice example. It only considers a single diffuse light.

This is the equation that I implement using just texture units.
color = max{l.n, 0}*diffuse

max{l.n, 0} <- this part is ok. It looks great and it's like the light source is white.

I'm trying to implement the diffuse color multiplication using modulation and by enabling the color arrays. My idea is to modulate the bump mapped texture with the GL_PRIMARY_COLOR. It doesn't work and it seems that I have no access to the primitive color fragments from texture unit 3.

this is my code. I use Vertex arrays

//Bind normalisation cube map to Texture Unit 0
m_extObj->glActiveTextureARB()(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, m_imgObj->GetTexId(0));
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
//Specify and enable Texture coordinates for cube map (sends tangent space light for normalisation-UNIT 0)
m_extObj->glClientActiveTextureARB()(GL_TEXTURE0_ARB);
glTexCoordPointer(3, GL_FLOAT, sizeof(CVertex), (void*)(5*sizeof(CVec3D)));
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//Specify and enable Vertice coordinates
glVertexPointer(3, GL_FLOAT, sizeof(CVertex), 0);
glEnableClientState(GL_VERTEX_ARRAY);
//Specify and enable color arrays
glColorPointer(3, GL_FLOAT, sizeof(CVertex), (void*)(6*sizeof(CVec3D)));
glEnableClientState(GL_COLOR_ARRAY);

//Bind normal map to Texture Unit 1
m_extObj->glActiveTextureARB()(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_imgObj->GetTexId(2));
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
//Specify and enable Texture coordinates for normal map texture
m_extObj->glClientActiveTextureARB()(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, sizeof(CVertex), (void*)(sizeof(CVec3D)));
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

//Bind texture to Texture Unit 2
m_extObj->glActiveTextureARB()(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_imgObj->GetTexId(1));
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//Specify and enable Texture coordinates for normal map texture
m_extObj->glClientActiveTextureARB()(GL_TEXTURE2_ARB);
glTexCoordPointer(2, GL_FLOAT, sizeof(CVertex), (void*)(sizeof(CVec3D)));
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

//Material color by Texture Unit 3
m_extObj->glActiveTextureARB()(GL_TEXTURE3_ARB);
glDisable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);


Can't I implement the above equation in a single pass?

Thanks!

Share this post


Link to post
Share on other sites
Get yourself familiar with pixel shaders. All this texEnv stuff is deprecated, and you will find with shaders you can do pretty much any operations you can imagine, instead of trying to stretch all these fixed functions into something kind of like what you want.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this