PDA

View Full Version : Multitexturing - It's driving me nuts!



GeoGecko
04-12-2009, 03:50 AM
Hey there, thanks in advance for any help!

This is my issue, I have a terrain and it's lovely and smooth and stuff so I thought I'd texture it all nice! So I thought I'd have two textures a grass texture and a snow texture and I'd use multitexturing to blend the two into each other at a certain height. Alas, it was never meant to be, I have fallen at the first hurdle!

Ok, so, in my render function for my terrain I have:

glActiveTextureARB(GL_TEXTURE1_ARB); //Set up texture unit 2
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, grassTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glActiveTextureARB(GL_TEXTURE0_ARB); //Set up texture Unit1
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, snowTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

This is all before I render the first vertex.

I then have a height test so if it's over a certain height I use:

glNormal3f(normal.x,normal.y,normal.z);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
glVertex3f(position.x,position.y,position.z);
obviously this is repeated 4 times with different round the 4 corners of each patch.

For under the certain height I have:

glNormal3f(normal.x,normal.y,normal.z);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f);
glVertex3f(position.x,position.y,position.z);

Now, I thought that by doing this I'd at least have snow capped peaks and grassy plains but instead I seem to get normal grass and the snow looks like it's been blended with the grass (it's green!)

I think a picture probably illustrates this best:
http://i3.photobucket.com/albums/y59/GeoGecko/Terrain.jpg

Also, I know I don't need to use multitexturing just yet since there is no textures actually being blended (or i don't want them to be yet) but the next step will be blending the partition between the high and the low areas.

Any help would be much appreciated!

Thankyou.

zeoverlord
04-12-2009, 06:08 AM
well it is blended, multi texturing means just that, blending multiple textures together, it doesn't work just feeding it texture coordinates for the different textures, you have to feed it all at once.

next to get the correct blending of textures i suggest you use a shader to correctly composite the two based on height

GeoGecko
04-12-2009, 09:48 AM
But how come the top is blended but the bottom isn't? And when I try to change the grass texture to snow so it should be blending snow with snow that doesn't work either! :( Multitexturing is confusing!

zeoverlord
04-12-2009, 05:06 PM
both are blended it's just that the top is blended with a solid green color and the bottom with a solid white color (which results in no change at all), so it only looks like the bottom isn't blended but it is.

yooyo
04-12-2009, 05:25 PM
Result of your multitextureing setup is:
(vertex color * snow_texture) * grass_texture.

OpenGL is state machine. This mean each time yo call glVertex it will use current state of other vertex attributes. So... if you set multitex-coord-0 it will remain unchanged and used until you pass another value.

Y-tension
04-13-2009, 07:43 AM
Use GL_INTERPOLATE mode for TexEnv. The result is to be expected. White modulated with green gives green. What you want to do is interpolate between two textures based on some value.

Y-tension
04-13-2009, 07:46 AM
And yes, multitexturing IS kinda complicated so read the documentation well and make sure you understand mathematically what each function does.