Alphatest and MT with GF2 - Screen shot included!

Hi people,

I’m still scratching my head about multitexture and alpha-testing. Here is a screenshot to show what I’m talking about:
http://www.thermoteknix.com/93288989/screenshot.jpg

Now, I’m using 2 texture units - texture 1 is a heightfield map, used to displace the mesh (greyscale, but stored as RGBA) the second texture is a repeated brick texture. Combined they look nice - but I want both culled when the alpha on the first texture is zero (see screenshot). At present, the first texture is removed but the brick texture remains.

I’ve tried setting the brick alpha to 255, so that a1*a2 = 0 where a1 = 0 (obviously). But (as shot shows), this hasn’t worked. My vertex alpha is 1.0 (so 1.0 * 0.0 * 1.0 should = 0.0!). I’m using GL_REPLACE, GL_MODULATE - I want modulate to get a nice `shaded’ effect on the mesh.

Any further ideas here?

Thanks.

[This message has been edited by Robbo (edited 04-16-2002).]

You need to try and ensure your final alpha fragment is from the first texture, then you can use glAlphaFunc. Try and pass the alpha fragment through the final stage, or use a modulate operation. Maybe reversing the texture operations would do it for you.

You certainly have enough control with newer extensions but I’m not sure if you want to use them.

  1. make sure that your texture stages have:
    stage 0: replace ( heightfield tex )
    stage 1: modulate ( brick tex )

this way your vertex color has no effect on final fragment which goes to framebuffer.

  1. and also make sure that your brich tex has no alpha channel or has an alpha of 1

3)and also check your blending function
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA )

I’m not using a blend function at all - I figured I could get away with just the alpha test. With a blend function, I have to enable blending and then some bits of my texture will become transparent, surely?

Erm - can anyone spot the deliberate mistakes? Sometimes when I post questions, what I’m really after is a way to fix a bug in my code! Anyway, I fixed it and it works fine - alpha test is blinding and everything looks great. Thanks anyway!!!?!

(below is the stupid, broken version)

void CTextureMaps :: Use ( const tstring& Name1, const tstring& Name2, const bool Swap, const int Mode1, const int Mode2 )

{
//
// Get the texture.
//

CTextureMap& Texture1 = Get ( Name1 ), &Texture2 = Get ( Name2 );

//
// This is a multi-texture blend function (2 units only).
//

if ( glActiveTextureARB )
{	
	glActiveTextureARB(GL_TEXTURE0_ARB);

	//
	// Enable texture unit 1
	//
	
	pGetState ()->m_Enabler.glEnableTextureUnit1 ();
		
	//
	// Bind in texture 1.
	//

	if ( Texture1.bIsBindable () )
	{
		glBindTexture ( GL_TEXTURE_2D, Texture1.GetHandle () );
	}

	//
	// Enable texture unit 2
	//
	
	pGetState ()->m_Enabler.glEnableTextureUnit2 ();
	
	//
	// Set texture environment mode for second texture unit.
	//

	glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
	
	//
	// and use the second texture ( although not its material ).
	//

	if ( Texture2.bIsBindable () )
	{
		glBindTexture ( GL_TEXTURE_2D, Texture2.GetHandle () );
	}
}
else
{
	Use ( Name1, Mode1 );
}

}

Show us a screen grab of it working then.

Ok - one moment!
http://www.thermoteknix.com/93288989/fixed.jpg

Check out the `holes’!!! (its a rough test displacement map - but you can see it working).

[This message has been edited by Robbo (edited 04-17-2002).]

What’s all this getting textures from strings about? I saw someone else doing this in another post too…why?
You’re doing strcmp’s every frame for every texture?

Well I don’t really need to use strings now, but thats how I implemented it originally. I’m using stl maps\vectors\lists - textures are added and deleted - so all objects using textures would have to be updated with new pointers\indices every time one was removed. I’m sure there is a more efficient way - but, well I’m not writing a game so I’m not too fussed about the extra cycles I’ll get from not doing this. At least thats an idea for future optimisation!

[This message has been edited by Robbo (edited 04-17-2002).]