Jump to content
  • Advertisement
Sign in to follow this  
felipedrl

Gloss map for water

This topic is 3304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to get some nice water effects for my game. The problem is that the hardware I'm writing to doesn't support shaders neither cube map. So I've came up with a bump and gloss map. The bump is working just fine but I'm facing some problems with the gloss map. To tell you the truth I'm not sure if I'm doing it right. All the samples I found on the internet use shaders. Nevertheless, I managed to find one piece of code which uses DOT3_RGBA and worked on it, but it seems the code have some bugs. The gloss don't quite appear... Well, Here's I've do so far. I draw the water in two passes. The first one draws the geometry with a bump texture set to channel 0 and a base(water) texture set to channel 1. I use DOT3_RGB and the blend mode is set to (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) because I want the water to be transparent. The second pass I draw the water with the bump set to channel 0 and the gloss set to channel 1 using DOT3_RGBA and blend mode (GL_SRC_ALPHA, GL_ONE) This is the piece of code where I set up the texenv ( 2nd pass ).

// Second Pass
if( m_bEnableGloss && m_iGlossMapTextureID )
{
	glEnable(GL_BLEND);
	glBlendFunc( GL_SRC_ALPHA, GL_ONE );
					
	glActiveTexture(GL_TEXTURE0);
	glEnable( GL_TEXTURE_2D );
	glClientActiveTexture(GL_TEXTURE0);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	
	glBindTexture( GL_TEXTURE_2D, m_iBumpMapTextureID);
			
	//dot3(bumpmap, tangent_space_light_vector)
	glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvx(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGBA);

	glTexEnvx(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
	glTexEnvx(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

	glTexEnvx(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
	glTexEnvx(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

	// Apply Gloss texture
	glActiveTexture(GL_TEXTURE1);
	glEnable( GL_TEXTURE_2D );
	glClientActiveTexture(GL_TEXTURE1);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glBindTexture( GL_TEXTURE_2D, m_iBumpMapTextureID );

	glTexCoordPointer(2, GL_FIXED, 0, m_pMultiTexCoords);
				
	glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvx(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED);
	glTexEnvx(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD_SIGNED);

	glTexEnvx(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
	glTexEnvx(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

	glTexEnvx(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
	glTexEnvx(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

	glTexEnvx(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
	glTexEnvx(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);

	glTexEnvx(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
	glTexEnvx(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);

        if(m_pGlossVecColor)
        {
 		glEnableClientState(GL_COLOR_ARRAY);
		glColorPointer(4, GL_FIXED, 0, m_pGlossVecColor);
	}
							
	glDrawElements( m_apSubMeshList[iSubMesh]->m_iMode, indexCount, 
			m_apSubMeshList[iSubMesh]->m_iType, indices);
	
	if(m_pGlossVecColor)
	{
		glDisableClientState(GL_COLOR_ARRAY);
	}
			
	// Restore default state
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisable(GL_TEXTURE_2D);
	glClientActiveTexture(GL_TEXTURE0);
	glActiveTexture(GL_TEXTURE0);
	
}

The m_pGlossVecColor is computed as follows:
if ( m_bEnableGloss )
{
	Vector3 halfVec, halfVecInTanSpace;
			
	lightVector = m_lightPosition - m_pVerticeCoords[iElement];
			
	halfVec.x.value = lightVector.x.value + cameraPos.x.value;
	halfVec.y.value = lightVector.y.value + cameraPos.y.value;
	halfVec.z.value = lightVector.z.value + cameraPos.z.value;
	halfVec.Normalize();

	halfVecInTanSpace.x = m_pTangentArray[iElement].Dot(halfVec);
	halfVecInTanSpace.y = m_pBinormalArray[iElement].Dot(halfVec);
	halfVecInTanSpace.z = m_pNormalArray[iElement].Dot(halfVec);
			
	
	m_pGlossVecColor[iElement].r.value = (halfVecInTanSpace.x.value >> 1) + FIXED32_HALF;
	m_pGlossVecColor[iElement].g.value = (halfVecInTanSpace.y.value >> 1) + FIXED32_HALF;
	m_pGlossVecColor[iElement].b.value = (halfVecInTanSpace.z.value >> 1) + FIXED32_HALF;
	m_pGlossVecColor[iElement].a.value = FIXED32_1;
}

Anyone has any why's the gloss not neing shown? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!