Fix: Alpha test without blend
by Tom Spilman · in Torque Game Engine Advanced · 03/28/2007 (1:05 pm) · 5 replies
Here is a little change to MatInstance::setupPass() which allows alpha test materials without alpha blending:
I think this change shouldn't break anybody and still allow the previous behavior.
EDIT: Added a little state change optimization by avoiding the call to set the blend op if the blend op is disabled.
if( mMaterial->translucent )
{
GFX->setAlphaBlendEnable( mMaterial->translucentBlendOp != Material::None ); // CHANGE!
if ( mMaterial->translucentBlendOp != Material::None ) // CHANGE!
mMaterial->setBlendState( mMaterial->translucentBlendOp );
GFX->setZWriteEnable( mMaterial->translucentZWrite );
GFX->setAlphaTestEnable( mMaterial->alphaTest );
GFX->setAlphaRef( mMaterial->alphaRef );
GFX->setAlphaFunc( GFXCmpGreaterEqual );
// set up register combiners
GFX->setTextureStageAlphaOp( 0, GFXTOPModulate );
GFX->setTextureStageAlphaOp( 1, GFXTOPDisable );
GFX->setTextureStageAlphaArg1( 0, GFXTATexture );
GFX->setTextureStageAlphaArg2( 0, GFXTADiffuse );
}I think this change shouldn't break anybody and still allow the previous behavior.
EDIT: Added a little state change optimization by avoiding the call to set the blend op if the blend op is disabled.
About the author
Tom is a programmer and co-owner of Sickhead Games, LLC.
#2
In this case its a material on a standard DTS... so i don't have access to the HLSL like that.
03/29/2007 (11:51 am)
No prob... i figured that would happen.In this case its a material on a standard DTS... so i don't have access to the HLSL like that.
#3
03/31/2007 (3:59 am)
Thanks Tom. This works great!
#4
... this little test was making materials with translucentBlendOp set to "None" load as LerpAlpha.
06/01/2007 (9:19 pm)
Found another little bug with this feature in Material::onAdd()... if( translucentBlendOp >= NumBlendTypes || translucentBlendOp < 0 ) // Changed == 0 to < 0
{
Con::errorf( "Invalid blend op in material: %s", getName() );
translucentBlendOp = LerpAlpha;
}... this little test was making materials with translucentBlendOp set to "None" load as LerpAlpha.
#5
06/04/2007 (3:17 pm)
Now that makes sense! I was wondering why "None" was provided as an "option" yet gave an error when it was used. Thanks Tom.
Torque Owner Brian Ramage
Black Jacket Games