Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ilici

3 textures with DOT3 - 1 pass ?

This topic is 5364 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, For my terrain engine i'm using dynamic lighting with DOT3 bumpmapping. I setup the first texture stage with the normalmap and the env mode. Then the second texture - the color map using GL_MODULATE. Now i want to add a detail texture to the combiner. I've tried to use the combiner with GL_MODULATE with source0: texture and source1: previous but it does not work. 1.Does anyone have any ideea if this is possible in one pass and how to set up the combiner? 2.How should i bias the DOT3 bumpmapping to create the effect of a ambient color? here's the code:
	GL.ActiveTexture(GL_TEXTURE0_ARB);
	GL.Enable(GL_TEXTURE_2D);
	GL.BindTexture(GL_TEXTURE_2D, terLight.GetName());

	float envc[4] = {Game.Sky.GetSunPos().x, Game.Sky.GetSunPos().y, Game.Sky.GetSunPos().z, 1.0f};
	
	GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, envc);

	GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
	GL.TextureEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);

	GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
	GL.TextureEnv(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
	GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT_ARB);
	GL.TextureEnv(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

	GL.ActiveTexture(GL_TEXTURE1_ARB);
	GL.Enable(GL_TEXTURE_2D);
	GL.BindTexture(GL_TEXTURE_2D, terTexture.GetName());

	GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// or maybe use this (??)

//	GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);

//	GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);

//	GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);


	GL.ActiveTexture(GL_TEXTURE2_ARB);
	GL.Enable(GL_TEXTURE_2D);
	GL.BindTexture(GL_TEXTURE_2D, terDetail.GetName());

//this part screws things up

//	GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);

//	GL.TextureEnv(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);

	
//	GL.TextureEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

//	GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);

//	GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);


	GL.MatrixMode(GL_TEXTURE);
	GL.PushMatrix();
	GL.Scale(64.0f, 64.0f, 1.0f);

	GL.ClientActiveTexture(GL_TEXTURE0_ARB);
	GL.EnableClientState(GL_TEXTURE_COORD_ARRAY);

	GL.ClientActiveTexture(GL_TEXTURE1_ARB);
	GL.EnableClientState(GL_TEXTURE_COORD_ARRAY);

	GL.ClientActiveTexture(GL_TEXTURE2_ARB);
	GL.EnableClientState(GL_TEXTURE_COORD_ARRAY);
[ My Site ] 'I wish life was not so short,' he thought. 'Languages take such a time, and so do all the things one wants to know about.' - J.R.R Tolkien /*ilici*/ [edited by - Ilici on October 8, 2003 4:25:36 PM] [edited by - Ilici on October 8, 2003 4:26:31 PM]

Share this post


Link to post
Share on other sites
Advertisement
Your DOT3 part is right. However, you still have to use GL_COMBINE_ARB for modulating each other texture as well.

glTextureEnv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTextureEnv (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

glTextureEnv (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTextureEnv (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTextureEnv (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS);
glTextureEnv (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

I think that''s it, at least. . . I''m not at home to confirm this, though. . .

Share this post


Link to post
Share on other sites
I''ve tried modulating the color map and the detail map but the detail just replaces the color:

GL.ActiveTexture(GL_TEXTURE0_ARB);
GL.Enable(GL_TEXTURE_2D);
GL.BindTexture(GL_TEXTURE_2D, terLight.GetName());

float envc[4] = {Game.Sky.GetSunPos().x, Game.Sky.GetSunPos().y, Game.Sky.GetSunPos().z, 1.0f};

GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, envc);

GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
GL.TextureEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);

GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
GL.TextureEnv(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT_ARB);
GL.TextureEnv(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

GL.ActiveTexture(GL_TEXTURE1_ARB);
GL.Enable(GL_TEXTURE_2D);
GL.BindTexture(GL_TEXTURE_2D, terTexture.GetName());

GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);

GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
GL.TextureEnv(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
GL.TextureEnv(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

GL.ActiveTexture(GL_TEXTURE2_ARB);
GL.Enable(GL_TEXTURE_2D);
GL.BindTexture(GL_TEXTURE_2D, terDetail.GetName());

GL.TextureEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
GL.TextureEnv(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);

GL.TextureEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
GL.TextureEnv(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
GL.TextureEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
GL.TextureEnv(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

This should evaluate (tex1 dot light) * tex2 * tex3 right?



[ My Site ]
''I wish life was not so short,'' he thought. ''Languages take such a time, and so do all the things one wants to know about.'' - J.R.R Tolkien
/*ilici*/

Share this post


Link to post
Share on other sites
Strange. . . I''ve tested it with a modified version of a simple bump-mapping tutorial and it works fine, for me. The following code uses a normalization cube-map (to normalize the light vectors), but ignoring that it''s basically the same as what you''re doing:


glActiveTextureARB (GL_TEXTURE0_ARB);
glBindTexture (GL_TEXTURE_2D, normalMap);
glEnable (GL_TEXTURE_2D);

glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);

glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glActiveTextureARB (GL_TEXTURE1_ARB);
glBindTexture (GL_TEXTURE_CUBE_MAP_ARB, normalisationCubeMap);
glEnable (GL_TEXTURE_CUBE_MAP_ARB);

glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);

glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

glActiveTextureARB (GL_TEXTURE2_ARB);
glBindTexture (GL_TEXTURE_2D, decalTexture);
glEnable (GL_TEXTURE_2D);

glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

glActiveTextureARB (GL_TEXTURE3_ARB);
glBindTexture (GL_TEXTURE_2D, detailTexture);
glEnable (GL_TEXTURE_2D);

glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);


What does your detail texture look like?

Share this post


Link to post
Share on other sites
8Bit Greyscale 512x512
it's the one everyone uses from the heightmap tutorial on gametutorials.com.

I'll test my code on another video card, maybe there is a driver problem on my Radeon.

EDIT: Tested it on GeForce2 but does not work.

[ My Site ]
'I wish life was not so short,' he thought. 'Languages take such a time, and so do all the things one wants to know about.' - J.R.R Tolkien
/*ilici*/


[edited by - Ilici on October 9, 2003 9:51:52 AM]

Share this post


Link to post
Share on other sites
Radeon(1) DDR 64mb VRAM.

The other rendering code:


GL.SetVertexPointer(3, GL_FLOAT, sizeof(tTerrainVertex), &patch->pVertices[0].Vertex);

GL.ClientActiveTexture(GL_TEXTURE2_ARB);
GL.SetTexCoordPointer(2, GL_FLOAT, sizeof(tTerrainVertex), &patch->pVertices[0].TexCoords);

GL.ClientActiveTexture(GL_TEXTURE1_ARB);
GL.SetTexCoordPointer(2, GL_FLOAT, sizeof(tTerrainVertex), &patch->pVertices[0].TexCoords);

GL.ClientActiveTexture(GL_TEXTURE0_ARB);
GL.SetTexCoordPointer(2, GL_FLOAT, sizeof(tTerrainVertex), &patch->pVertices[0].TexCoords);

GL.DrawIndexedArrays(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, indexArray);



[ My Site ]
''I wish life was not so short,'' he thought. ''Languages take such a time, and so do all the things one wants to know about.'' - J.R.R Tolkien
/*ilici*/

Share this post


Link to post
Share on other sites
Well, assuming you''ve also remembered to enable the GL_TEXTURE_COORD_ARRAY client states for each glClientActiveTexture. . . I have no idea what''s going wrong. When that Radeon you have came out, ATI specifically advertised its ability to render three textures in a single pass.

Share this post


Link to post
Share on other sites
yep, it has 3 texture units.

here''s the code u were talking about:

GL.ClientActiveTexture(GL_TEXTURE0_ARB);
GL.EnableClientState(GL_TEXTURE_COORD_ARRAY);

GL.ClientActiveTexture(GL_TEXTURE1_ARB);
GL.EnableClientState(GL_TEXTURE_COORD_ARRAY);

GL.ClientActiveTexture(GL_TEXTURE2_ARB);
GL.EnableClientState(GL_TEXTURE_COORD_ARRAY);



[ My Site ]
''I wish life was not so short,'' he thought. ''Languages take such a time, and so do all the things one wants to know about.'' - J.R.R Tolkien
/*ilici*/

Share this post


Link to post
Share on other sites
OMG, OH TEH NOOOES!! I am teh stupid!!

When declaring GL_TEXTURE2_ARB i copyed the def of GL_TEXTURE1_ARB changed the "1" to "2" but forgot to change the value so GL_TEXTURE2_ARB refered to GL_TEXTURE1_ARB.

*bangs head against keyboard in rage* I hate it when problems that seem hard are corrected by changing one character.

Any idees on the other question (How to bias the result from the DOT3 to create the effect of ambient light) ?



[ My Site ]
'I wish life was not so short,' he thought. 'Languages take such a time, and so do all the things one wants to know about.' - J.R.R Tolkien
/*ilici*/


[edited by - Ilici on October 9, 2003 10:26:10 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!