Exemple #1
0
void CBaseShader::SetBlendingShadowState( BlendType_t nMode )
{
	switch ( nMode )
	{
		case BT_NONE:
			DisableAlphaBlending();
			break;

		case BT_BLEND:
			EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
			break;

		case BT_ADD:
			EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
			break;

		case BT_BLENDADD:
			EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
			break;
	}
}
Exemple #2
0
void CBaseShader::SetNormalBlendingShadowState( int textureVar, bool isBaseTexture )
{
	Assert( IsSnapshotting() );

	// Either we've got a constant modulation
	bool isTranslucent = IsAlphaModulating();

	// Or we've got a vertex alpha
	isTranslucent = isTranslucent || (CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXALPHA);

	// Or we've got a texture alpha
	isTranslucent = isTranslucent || ( TextureIsTranslucent( textureVar, isBaseTexture ) &&
		                               !(CurrentMaterialVarFlags() & MATERIAL_VAR_ALPHATEST ) );

	if (isTranslucent)
	{
		EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
	}
	else
	{
		DisableAlphaBlending();
	}
}
//-----------------------------------------------------------------------------
// Fixed function multiply by detail texture pass
//-----------------------------------------------------------------------------
void CBaseShader::FixedFunctionMultiplyByDetailPass( int baseTextureVar, int frameVar, 
		int textureTransformVar, int detailVar, int detailScaleVar )
{
	IMaterialVar** params = s_ppParams;

	if (!params[detailVar]->IsDefined())
		return;

	if (IsSnapshotting())
	{
		s_pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) );

		bool translucentTexture = TextureIsTranslucent( baseTextureVar, true ) ||
			IS_FLAG_SET(MATERIAL_VAR_ALPHATEST);
		s_pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, translucentTexture );
		s_pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE1, true );
		s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, false );
		s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE1, false );

		// Mod 2x blend here
		EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR );

		s_pShaderShadow->EnableCustomPixelPipe( true );
		s_pShaderShadow->CustomTextureStages( 2 );

		// We need to blend towards grey based on alpha...
		// We can never get the perfect alpha (vertex alpha * cc alpha * texture alpha)
		// so we'll just choose to use cc alpha * texture alpha

		int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1;

		// Compute alpha, stage 0 is used, stage 1 isn't.
		if ( translucentTexture )
		{
			s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, 
				SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE, 
				SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR );
			flags |= SHADER_DRAW_TEXCOORD0;
		}
		else
		{
			bool hasVertexAlpha = (CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXALPHA) != 0;
			if (hasVertexAlpha)
			{
				flags |= SHADER_DRAW_COLOR;
			}

			s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, 
				SHADER_TEXCHANNEL_ALPHA, hasVertexAlpha ? SHADER_TEXOP_MODULATE : SHADER_TEXOP_SELECTARG2, 
				SHADER_TEXARG_VERTEXCOLOR, SHADER_TEXARG_CONSTANTCOLOR );
		}

		s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, 
			SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, 
			SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_NONE );

		// This here will perform color = vertex light * alpha + 0.5f * (1 - alpha)
		// Stage 0 really doesn't do anything
		s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, 
			SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, 
			SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR );

		s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, 
			SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA, 
			SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR );

		s_pShaderShadow->DrawFlags( flags );

		Draw( );

		s_pShaderShadow->EnableCustomPixelPipe( false );
		DisableAlphaBlending();
	}
	else
	{
		if (TextureIsTranslucent( baseTextureVar, true ) )
		{
			SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, textureTransformVar );
			BindTexture( SHADER_TEXTURE_STAGE0, baseTextureVar, frameVar );
		}

		BindTexture( SHADER_TEXTURE_STAGE1, detailVar, frameVar );
		SetFixedFunctionTextureScaledTransform( MATERIAL_TEXTURE1, textureTransformVar, detailScaleVar );
		float alpha = GetAlpha();
		s_pShaderAPI->Color4ub( 128, 128, 128, 255 * alpha );
		FogToGrey();

		Draw( );
	}
}