//----------------------------------------------------------------------------- // Initialize shader parameters //----------------------------------------------------------------------------- void InitParamsPhong_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, VertexLitGeneric_DX9_Vars_t &info ) { // FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture Assert( info.m_nFlashlightTexture >= 0 ); params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() ); // Write over $basetexture with $info.m_nBumpmap if we are going to be using diffuse normal mapping. if( info.m_nAlbedo != -1 && g_pConfig->UseBumpmapping() && info.m_nBumpmap != -1 && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() ) { params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() ); } // This shader can be used with hw skinning SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); // No texture means no env mask in base alpha if ( !params[info.m_nBaseTexture]->IsDefined() ) { CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); } // If in decal mode, no debug override... if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) { SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); } // We always specify we're using user data, therefore we always need tangent spaces SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); bool bBump = (info.m_nBumpmap != -1) && g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined(); bool bEnvMap = (info.m_nEnvmap != -1) && params[info.m_nEnvmap]->IsDefined(); bool bDiffuseWarp = (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined(); bool bPhong = (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined(); if( !bBump && !bEnvMap && !bDiffuseWarp && !bPhong ) { CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); } if ( ( info.m_nSelfIllumFresnelMinMaxExp != -1 ) && ( !params[info.m_nSelfIllumFresnelMinMaxExp]->IsDefined() ) ) { params[info.m_nSelfIllumFresnelMinMaxExp]->SetVecValue( 0.0f, 1.0f, 1.0f ); } InitFloatParam( info.m_nEnvmapFresnel, params, 0.0f ); InitFloatParam( info.m_nAmbientOcclusion, params, 0.0f ); InitFloatParam( info.m_nDisplacementWrinkleMap, params, 0.0f ); InitIntParam( info.m_nSelfIllumFresnel, params, 0 ); InitIntParam( info.m_nBaseMapAlphaPhongMask, params, 0 ); InitIntParam( info.m_nBaseMapLuminancePhongMask, params, 0 ); InitIntParam( info.m_nShaderSrgbRead360, params, 0 ); InitIntParam( info.m_nAllowDiffuseModulation, params, 1 ); InitIntParam( info.m_nPhongDisableHalfLambert, params, 0 ); SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nFoW, "_rt_fog_of_war" ); }
END_SHADER_PARAMS SHADER_INIT_PARAMS() { INIT_FLOAT_PARM( MAXDISTANCE, 100000.0 ); INIT_FLOAT_PARM( FARFADEINTERVAL, 400.0 ); INIT_FLOAT_PARM( MAXSIZE, 20.0 ); INIT_FLOAT_PARM( ENDFADESIZE, 20.0 ); INIT_FLOAT_PARM( STARTFADESIZE, 10.0 ); INIT_FLOAT_PARM( DEPTHBLENDSCALE, 50.0 ); INIT_FLOAT_PARM( OVERBRIGHTFACTOR, 1.0 ); INIT_FLOAT_PARM( ADDBASETEXTURE2, 0.0 ); INIT_FLOAT_PARM( ADDSELF, 0.0 ); INIT_FLOAT_PARM( ZOOMANIMATESEQ2, 0.0 ); INIT_FLOAT_PARM( ALPHATRAILFADE, 1. ); INIT_FLOAT_PARM( RADIUSTRAILFADE, 1. ); INIT_FLOAT_PARM( VERTEXFOGAMOUNT, 0.0f ); INIT_FLOAT_PARM( OUTLINEALPHA, 1.0 ); if ( !params[ORIENTATIONMATRIX]->IsDefined() ) { VMatrix mat; MatrixSetIdentity( mat ); params[ORIENTATIONMATRIX]->SetMatrixValue( mat ); } if ( !params[CROPFACTOR]->IsDefined() ) { params[CROPFACTOR]->SetVecValue( 1.0f, 1.0f ); } if ( !params[DEPTHBLEND]->IsDefined() ) { params[ DEPTHBLEND ]->SetIntValue( GetDefaultDepthFeatheringValue() ); } if ( !g_pHardwareConfig->SupportsPixelShaders_2_b() ) { params[ DEPTHBLEND ]->SetIntValue( 0 ); } InitIntParam( DUALSEQUENCE, params, 0 ); InitIntParam( MAXLUMFRAMEBLEND1, params, 0 ); InitIntParam( MAXLUMFRAMEBLEND2, params, 0 ); InitIntParam( EXTRACTGREENALPHA, params, 0 ); InitIntParam( ADDOVERBLEND, params, 0 ); InitIntParam( BLENDFRAMES, params, 1 ); InitIntParam( DISTANCEALPHA, params, 0 ); InitIntParam( OUTLINE, params, 0 ); InitIntParam( SOFTEDGES, params, 0 ); InitIntParam( PERPARTICLEOUTLINE, params, 0 ); if ( !params[USEINSTANCING]->IsDefined() ) { params[ USEINSTANCING ]->SetIntValue( IsX360() ? 1 : 0 ); } // srgb read 360 InitIntParam( SHADERSRGBREAD360, params, 0 ); // default to being translucent since that's what we always were for historical reasons. InitIntParam( OPAQUE, params, 0 ); InitIntParam( VERTEXCOLORLERP, params, 0 ); if ( !params[LERPCOLOR1]->IsDefined() ) { params[LERPCOLOR1]->SetVecValue( 1.0f, 0.0f, 0.0f ); } if ( !params[LERPCOLOR2]->IsDefined() ) { params[LERPCOLOR2]->SetVecValue( 0.0f, 1.0f, 0.0f ); } if ( params[OPAQUE]->GetIntValue() != 0 ) { // none of these make sense if we have $opaque 1: params[ADDBASETEXTURE2]->SetFloatValue( 0.0f ); params[DUALSEQUENCE]->SetIntValue( 0 ); params[SEQUENCE_BLEND_MODE]->SetIntValue( 0 ); params[MAXLUMFRAMEBLEND1]->SetIntValue( 0 ); params[MAXLUMFRAMEBLEND2]->SetIntValue( 0 ); params[EXTRACTGREENALPHA]->SetIntValue( 0 ); params[RAMPTEXTURE]->SetUndefined(); params[ZOOMANIMATESEQ2]->SetIntValue( 0 ); params[ADDOVERBLEND]->SetIntValue( 0 ); params[ADDSELF]->SetIntValue( 0 ); params[BLENDFRAMES]->SetIntValue( 0 ); params[DEPTHBLEND]->SetIntValue( 0 ); params[INVERSEDEPTHBLEND]->SetIntValue( 0 ); } SET_FLAGS2( MATERIAL_VAR2_IS_SPRITECARD ); }
SHADER_INIT_PARAMS() { if( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->IsDefined() ) { params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->SetIntValue( 0 ); } params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() ); // Write over $basetexture with $albedo if we are going to be using diffuse normal mapping. if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() && params[ALBEDO]->IsDefined() && params[BASETEXTURE]->IsDefined() && !( params[NODIFFUSEBUMPLIGHTING]->IsDefined() && params[NODIFFUSEBUMPLIGHTING]->GetIntValue() ) ) { params[BASETEXTURE]->SetStringValue( params[ALBEDO]->GetStringValue() ); } if( !params[NODIFFUSEBUMPLIGHTING]->IsDefined() ) { params[NODIFFUSEBUMPLIGHTING]->SetIntValue( 0 ); } if( !params[SELFILLUMTINT]->IsDefined() ) { params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); } if( !params[DETAILSCALE]->IsDefined() ) { params[DETAILSCALE]->SetFloatValue( 4.0f ); } if( !params[BUMPFRAME]->IsDefined() ) { params[BUMPFRAME]->SetIntValue( 0 ); } if( !params[DETAILFRAME]->IsDefined() ) { params[DETAILFRAME]->SetIntValue( 0 ); } // No texture means no self-illum or env mask in base alpha if ( !params[BASETEXTURE]->IsDefined() ) { CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); } // If in decal mode, no debug override... if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) { SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); } SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0) ) { SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); } // srgb read 360 InitIntParam( SHADERSRGBREAD360, params, 0 ); }
void InitParamsLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, LightmappedGeneric_DX9_Vars_t &info ) { if ( g_pHardwareConfig->SupportsBorderColor() ) { params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); } else { params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); } // Write over $basetexture with $albedo if we are going to be using diffuse normal mapping. if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() && !( params[info.m_nNoDiffuseBumpLighting]->IsDefined() && params[info.m_nNoDiffuseBumpLighting]->GetIntValue() ) ) { params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() ); } if( pShader->IsUsingGraphics() && params[info.m_nEnvmap]->IsDefined() && !pShader->CanUseEditorMaterials() ) { if( stricmp( params[info.m_nEnvmap]->GetStringValue(), "env_cubemap" ) == 0 ) { Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName ); params[info.m_nEnvmap]->SetUndefined(); } } if ( (mat_disable_lightwarp.GetBool() ) && (info.m_nLightWarpTexture != -1) ) { params[info.m_nLightWarpTexture]->SetUndefined(); } if ( (mat_disable_fancy_blending.GetBool() ) && (info.m_nBlendModulateTexture != -1) ) { params[info.m_nBlendModulateTexture]->SetUndefined(); } if( !params[info.m_nEnvmapTint]->IsDefined() ) params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); if( !params[info.m_nNoDiffuseBumpLighting]->IsDefined() ) params[info.m_nNoDiffuseBumpLighting]->SetIntValue( 0 ); if( !params[info.m_nSelfIllumTint]->IsDefined() ) params[info.m_nSelfIllumTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); if( !params[info.m_nDetailScale]->IsDefined() ) params[info.m_nDetailScale]->SetFloatValue( 4.0f ); if ( !params[info.m_nDetailTint]->IsDefined() ) params[info.m_nDetailTint]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f ); InitFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 ); InitIntParam( info.m_nDetailTextureCombineMode, params, 0 ); if( !params[info.m_nFresnelReflection]->IsDefined() ) params[info.m_nFresnelReflection]->SetFloatValue( 1.0f ); if( !params[info.m_nEnvmapMaskFrame]->IsDefined() ) params[info.m_nEnvmapMaskFrame]->SetIntValue( 0 ); if( !params[info.m_nEnvmapFrame]->IsDefined() ) params[info.m_nEnvmapFrame]->SetIntValue( 0 ); if( !params[info.m_nBumpFrame]->IsDefined() ) params[info.m_nBumpFrame]->SetIntValue( 0 ); if( !params[info.m_nDetailFrame]->IsDefined() ) params[info.m_nDetailFrame]->SetIntValue( 0 ); if( !params[info.m_nEnvmapContrast]->IsDefined() ) params[info.m_nEnvmapContrast]->SetFloatValue( 0.0f ); if( !params[info.m_nEnvmapSaturation]->IsDefined() ) params[info.m_nEnvmapSaturation]->SetFloatValue( 1.0f ); InitFloatParam( info.m_nAlphaTestReference, params, 0.0f ); // No texture means no self-illum or env mask in base alpha if ( !params[info.m_nBaseTexture]->IsDefined() ) { CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); } if( params[info.m_nBumpmap]->IsDefined() ) { params[info.m_nEnvmapMask]->SetUndefined(); } // If in decal mode, no debug override... if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) { SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); } SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && (params[info.m_nNoDiffuseBumpLighting]->GetIntValue() == 0) ) { SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); } // If mat_specular 0, then get rid of envmap if( !g_pConfig->UseSpecular() && params[info.m_nEnvmap]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() ) { params[info.m_nEnvmap]->SetUndefined(); } if( !params[info.m_nBaseTextureNoEnvmap]->IsDefined() ) { params[info.m_nBaseTextureNoEnvmap]->SetIntValue( 0 ); } if( !params[info.m_nBaseTexture2NoEnvmap]->IsDefined() ) { params[info.m_nBaseTexture2NoEnvmap]->SetIntValue( 0 ); } if( ( info.m_nSelfShadowedBumpFlag != -1 ) && ( !params[info.m_nSelfShadowedBumpFlag]->IsDefined() ) ) { params[info.m_nSelfShadowedBumpFlag]->SetIntValue( 0 ); } // handle line art parms InitFloatParam( info.m_nEdgeSoftnessStart, params, 0.5 ); InitFloatParam( info.m_nEdgeSoftnessEnd, params, 0.5 ); InitFloatParam( info.m_nOutlineAlpha, params, 1.0 ); // Parallax cubemaps //cubemap parallax correction requires all 4 lines (if the 2nd, 3rd, or 4th are undef, undef the first one (checking done on first var) if (!(params[info.m_nEnvmapParallaxObb2]->IsDefined() && params[info.m_nEnvmapParallaxObb3]->IsDefined() && params[info.m_nEnvmapOrigin]->IsDefined())) { params[info.m_nEnvmapParallaxObb1]->SetUndefined(); } }
void InitParamsLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, LightmappedGeneric_DX9_Vars_t &info ) { // Override vertex fog via the global setting if it isn't enabled/disabled in the material file. if ( !IS_FLAG_DEFINED( MATERIAL_VAR_VERTEXFOG ) && mat_force_vertexfog.GetBool() ) { SET_FLAGS( MATERIAL_VAR_VERTEXFOG ); } params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() ); // Write over $basetexture with $albedo if we are going to be using diffuse normal mapping. if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() && !( params[info.m_nNoDiffuseBumpLighting]->IsDefined() && params[info.m_nNoDiffuseBumpLighting]->GetIntValue() ) ) { params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() ); } if( pShader->IsUsingGraphics() && params[info.m_nEnvmap]->IsDefined() && !pShader->CanUseEditorMaterials() ) { if( stricmp( params[info.m_nEnvmap]->GetStringValue(), "env_cubemap" ) == 0 ) { Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName ); params[info.m_nEnvmap]->SetUndefined(); } } if ( (mat_disable_lightwarp.GetBool() ) && (info.m_nLightWarpTexture != -1) ) { params[info.m_nLightWarpTexture]->SetUndefined(); } if ( (mat_disable_fancy_blending.GetBool() ) && (info.m_nBlendModulateTexture != -1) ) { params[info.m_nBlendModulateTexture]->SetUndefined(); } if( !params[info.m_nEnvmapTint]->IsDefined() ) params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); if( !params[info.m_nNoDiffuseBumpLighting]->IsDefined() ) params[info.m_nNoDiffuseBumpLighting]->SetIntValue( 0 ); if( !params[info.m_nSelfIllumTint]->IsDefined() ) params[info.m_nSelfIllumTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); if( !params[info.m_nDetailScale]->IsDefined() ) params[info.m_nDetailScale]->SetFloatValue( 4.0f ); if ( !params[info.m_nDetailTint]->IsDefined() ) params[info.m_nDetailTint]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f ); InitFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 ); InitIntParam( info.m_nDetailTextureCombineMode, params, 0 ); if( !params[info.m_nFresnelReflection]->IsDefined() ) params[info.m_nFresnelReflection]->SetFloatValue( 1.0f ); if( !params[info.m_nEnvmapMaskFrame]->IsDefined() ) params[info.m_nEnvmapMaskFrame]->SetIntValue( 0 ); if( !params[info.m_nEnvmapFrame]->IsDefined() ) params[info.m_nEnvmapFrame]->SetIntValue( 0 ); if( !params[info.m_nBumpFrame]->IsDefined() ) params[info.m_nBumpFrame]->SetIntValue( 0 ); if( !params[info.m_nDetailFrame]->IsDefined() ) params[info.m_nDetailFrame]->SetIntValue( 0 ); if( !params[info.m_nEnvmapContrast]->IsDefined() ) params[info.m_nEnvmapContrast]->SetFloatValue( 0.0f ); if( !params[info.m_nEnvmapSaturation]->IsDefined() ) params[info.m_nEnvmapSaturation]->SetFloatValue( 1.0f ); InitFloatParam( info.m_nAlphaTestReference, params, 0.0f ); // No texture means no self-illum or env mask in base alpha if ( !params[info.m_nBaseTexture]->IsDefined() ) { CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); } if( params[info.m_nBumpmap]->IsDefined() ) { params[info.m_nEnvmapMask]->SetUndefined(); } // If in decal mode, no debug override... if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) { SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); } SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && (params[info.m_nNoDiffuseBumpLighting]->GetIntValue() == 0) ) { SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); } // If mat_specular 0, then get rid of envmap if( !g_pConfig->UseSpecular() && params[info.m_nEnvmap]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() ) { params[info.m_nEnvmap]->SetUndefined(); } if( !params[info.m_nBaseTextureNoEnvmap]->IsDefined() ) { params[info.m_nBaseTextureNoEnvmap]->SetIntValue( 0 ); } if( !params[info.m_nBaseTexture2NoEnvmap]->IsDefined() ) { params[info.m_nBaseTexture2NoEnvmap]->SetIntValue( 0 ); } if( ( info.m_nSelfShadowedBumpFlag != -1 ) && ( !params[info.m_nSelfShadowedBumpFlag]->IsDefined() ) ) { params[info.m_nSelfShadowedBumpFlag]->SetIntValue( 0 ); } // handle line art parms InitFloatParam( info.m_nEdgeSoftnessStart, params, 0.5 ); InitFloatParam( info.m_nEdgeSoftnessEnd, params, 0.5 ); InitFloatParam( info.m_nOutlineAlpha, params, 1.0 ); // parallax mapping InitFloatParam( info.m_nHeightScale, params, 0.1 ); // srgb read 360 InitIntParam( info.m_nShaderSrgbRead360, params, 0 ); InitFloatParam( info.m_nEnvMapLightScale, params, 0.0f ); SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nFoW, "_rt_fog_of_war" ); if ( g_pConfig->m_bPaintInGame ) { if( info.m_nPaintSplatNormal != -1 ) { if( !params[info.m_nPaintSplatNormal]->IsDefined() ) { params[info.m_nPaintSplatNormal]->SetStringValue( "paint/splatnormal_default" ); } } if( info.m_nPaintSplatEnvMap != -1 ) { if( !params[info.m_nPaintSplatEnvMap]->IsDefined() ) { if( params[info.m_nEnvmap]->IsDefined() ) { params[info.m_nPaintSplatEnvMap]->SetStringValue( params[info.m_nEnvmap]->GetStringValue() ); } else { params[info.m_nPaintSplatEnvMap]->SetStringValue( "env_cubemap" ); } } } } else { if( info.m_nPaintSplatNormal != -1 ) { params[info.m_nPaintSplatNormal]->SetUndefined(); } if( info.m_nPaintSplatEnvMap != -1 ) { params[info.m_nPaintSplatEnvMap]->SetUndefined(); } } }