diff options
Diffstat (limited to 'mp/src/materialsystem/stdshaders')
9 files changed, 62 insertions, 22 deletions
diff --git a/mp/src/materialsystem/stdshaders/BaseVSShader.cpp b/mp/src/materialsystem/stdshaders/BaseVSShader.cpp index 40e3934b..fdaeb563 100644 --- a/mp/src/materialsystem/stdshaders/BaseVSShader.cpp +++ b/mp/src/materialsystem/stdshaders/BaseVSShader.cpp @@ -458,6 +458,21 @@ void CBaseVSShader::SetPixelShaderTextureScaledTransform( int pixelReg, int tran //----------------------------------------------------------------------------- // Moves a matrix into vertex shader constants //----------------------------------------------------------------------------- +void CBaseVSShader::SetVertexShaderMatrix2x4( int vertexReg, int matrixVar ) +{ + IMaterialVar* pTranslationVar = s_ppParams[ matrixVar ]; + if ( pTranslationVar ) + { + s_pShaderAPI->SetVertexShaderConstant( vertexReg, &pTranslationVar->GetMatrixValue()[ 0 ][ 0 ], 2 ); + } + else + { + VMatrix matrix; + MatrixSetIdentity( matrix ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, &matrix[ 0 ][ 0 ], 2 ); + } +} + void CBaseVSShader::SetVertexShaderMatrix3x4( int vertexReg, int matrixVar ) { IMaterialVar* pTranslationVar = s_ppParams[matrixVar]; diff --git a/mp/src/materialsystem/stdshaders/BaseVSShader.h b/mp/src/materialsystem/stdshaders/BaseVSShader.h index 1ba6cc43..860c6876 100644 --- a/mp/src/materialsystem/stdshaders/BaseVSShader.h +++ b/mp/src/materialsystem/stdshaders/BaseVSShader.h @@ -118,6 +118,7 @@ public: int transformVar, int scaleVar ); // Moves a matrix into vertex shader constants + void SetVertexShaderMatrix2x4( int vertexReg, int matrixVar ); void SetVertexShaderMatrix3x4( int vertexReg, int matrixVar ); void SetVertexShaderMatrix4x4( int vertexReg, int matrixVar ); diff --git a/mp/src/materialsystem/stdshaders/example_model_dx9_helper.cpp b/mp/src/materialsystem/stdshaders/example_model_dx9_helper.cpp index 82b8d466..fc6a7208 100644 --- a/mp/src/materialsystem/stdshaders/example_model_dx9_helper.cpp +++ b/mp/src/materialsystem/stdshaders/example_model_dx9_helper.cpp @@ -19,7 +19,7 @@ static ConVar mat_fullbright( "mat_fullbright", "0", FCVAR_CHEAT ); static ConVar r_lightwarpidentity( "r_lightwarpidentity", "0", FCVAR_CHEAT ); -static ConVar r_rimlight( "r_rimlight", "1", FCVAR_CHEAT ); +static ConVar r_rimlight( "r_rimlight", "1", FCVAR_NONE ); // Textures may be bound to the following samplers: // SHADER_SAMPLER0 Base (Albedo) / Gloss in alpha diff --git a/mp/src/materialsystem/stdshaders/skin_dx9_helper.cpp b/mp/src/materialsystem/stdshaders/skin_dx9_helper.cpp index 1e2d30f3..cc999788 100644 --- a/mp/src/materialsystem/stdshaders/skin_dx9_helper.cpp +++ b/mp/src/materialsystem/stdshaders/skin_dx9_helper.cpp @@ -23,7 +23,7 @@ static ConVar mat_fullbright( "mat_fullbright", "0", FCVAR_CHEAT ); static ConVar r_lightwarpidentity( "r_lightwarpidentity", "0", FCVAR_CHEAT ); -static ConVar r_rimlight( "r_rimlight", "1", FCVAR_CHEAT ); +static ConVar r_rimlight( "r_rimlight", "1", FCVAR_NONE ); // Textures may be bound to the following samplers: // SHADER_SAMPLER0 Base (Albedo) / Gloss in alpha @@ -270,6 +270,9 @@ void DrawSkin_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShad float flTintReplacementAmount = GetFloatParam( info.m_nTintReplacesBaseColor, params ); + float flPhongExponentFactor = ( info.m_nPhongExponentFactor != -1 ) ? GetFloatParam( info.m_nPhongExponentFactor, params ) : 0.0f; + const bool bHasPhongExponentFactor = flPhongExponentFactor != 0.0f; + BlendType_t nBlendType= pShader->EvaluateBlendRequirements( bBlendTintByBaseAlpha ? -1 : info.m_nBaseTexture, true ); bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !bIsAlphaTested && !bHasFlashlight; //dest alpha is free for special use @@ -676,6 +679,7 @@ void DrawSkin_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShad SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PHONG_USE_EXPONENT_FACTOR, bHasPhongExponentFactor ); SET_DYNAMIC_PIXEL_SHADER( skin_ps20b ); } #ifndef _X360 @@ -697,6 +701,7 @@ void DrawSkin_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShad SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PHONG_USE_EXPONENT_FACTOR, bHasPhongExponentFactor ); SET_DYNAMIC_PIXEL_SHADER( skin_ps30 ); bool bUnusedTexCoords[3] = { false, false, !pShaderAPI->IsHWMorphingEnabled() || !bIsDecal }; @@ -806,15 +811,23 @@ void DrawSkin_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShad float vSpecularTint[4] = {1, 1, 1, 4}; pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); - // Use the alpha channel of the normal map for the exponent by default - vEyePos_SpecExponent[3] = -1.f; - if ( (info.m_nPhongExponent != -1) && params[info.m_nPhongExponent]->IsDefined() ) + // If we have a phong exponent factor, then use that as a multiplier against the texture. + if ( bHasPhongExponentFactor ) + { + vEyePos_SpecExponent[3] = flPhongExponentFactor; + } + else { - float fValue = params[info.m_nPhongExponent]->GetFloatValue(); - if ( fValue > 0.f ) + // Use the alpha channel of the normal map for the exponent by default + vEyePos_SpecExponent[3] = -1.f; + if ( (info.m_nPhongExponent != -1) && params[info.m_nPhongExponent]->IsDefined() ) { - // Nonzero value in material overrides map channel - vEyePos_SpecExponent[3] = fValue; + float fValue = params[info.m_nPhongExponent]->GetFloatValue(); + if ( fValue > 0.f ) + { + // Nonzero value in material overrides map channel + vEyePos_SpecExponent[3] = fValue; + } } } diff --git a/mp/src/materialsystem/stdshaders/skin_ps20b.fxc b/mp/src/materialsystem/stdshaders/skin_ps20b.fxc index 20c3eef9..8d2e3204 100644 --- a/mp/src/materialsystem/stdshaders/skin_ps20b.fxc +++ b/mp/src/materialsystem/stdshaders/skin_ps20b.fxc @@ -24,6 +24,8 @@ // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30] // DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] // DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30] +// DYNAMIC: "PHONG_USE_EXPONENT_FACTOR" "0..0" [ps20] +// DYNAMIC: "PHONG_USE_EXPONENT_FACTOR" "0..1" [ps20b] [ps30] [PC] // SKIP: ($PIXELFOGTYPE == 0) && ($WRITEWATERFOGTODESTALPHA != 0) @@ -76,7 +78,9 @@ const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); const float4 g_FogParams : register( PSREG_FOG_PARAMS ); const float4 g_FlashlightAttenuationFactors_RimMask : register( PSREG_FLASHLIGHT_ATTENUATION ); // On non-flashlight pass, x has rim mask control const float4 g_FlashlightPos_RimBoost : register( PSREG_FLASHLIGHT_POSITION_RIM_BOOST ); -const float4x4 g_FlashlightWorldToTexture : register( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE ); +#if FLASHLIGHT + const float4x4 g_FlashlightWorldToTexture : register( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE ); +#endif const float4 g_FresnelSpecParams : register( PSREG_FRESNEL_SPEC_PARAMS ); // xyz are fresnel, w is specular boost const float4 g_SpecularRimParams : register( PSREG_SPEC_RIM_PARAMS ); // xyz are specular tint color, w is rim power PixelShaderLightInfo cLightInfo[3] : register( PSREG_LIGHT_INFO_ARRAY ); // 2 registers each - 6 registers total (4th light spread across w's) @@ -96,6 +100,7 @@ const float4 g_ShaderControls : register( PSREG_CONSTANT_27 ); // x is #define g_fTintReplacementControl g_ShaderControls.z #define g_fInvertPhongMask g_ShaderControls.w + sampler BaseTextureSampler : register( s0 ); // Base map, selfillum in alpha sampler SpecularWarpSampler : register( s1 ); // Specular warp sampler (for iridescence etc) sampler DiffuseWarpSampler : register( s2 ); // Lighting warp sampler (1D texture for diffuse lighting modification) @@ -119,7 +124,6 @@ sampler DetailSampler : register( s13 ); // detail texture sampler SelfIllumMaskSampler : register( s14 ); // selfillummask - struct PS_INPUT { float4 baseTexCoordDetailTexCoord : TEXCOORD0; // xy=base zw=detail @@ -258,7 +262,11 @@ float4 main( PS_INPUT i ) : COLOR [flatten] #endif +#if ( PHONG_USE_EXPONENT_FACTOR ) + fSpecExp = ( 1.0f + g_EyePos_SpecExponent.w * vSpecExpMap.r ); +#else fSpecExp = (g_EyePos_SpecExponent.w >= 0.0) ? g_EyePos_SpecExponent.w : (1.0f + 149.0f * vSpecExpMap.r); +#endif // If constant tint is negative, tint with albedo, based upon scalar tint map #if defined( _X360 ) @@ -286,15 +294,17 @@ float4 main( PS_INPUT i ) : COLOR } else { - float4 flashlightSpacePosition = mul( float4( vWorldPos, 1.0f ), g_FlashlightWorldToTexture ); + #if FLASHLIGHT + float4 flashlightSpacePosition = mul( float4( vWorldPos, 1.0f ), g_FlashlightWorldToTexture ); - DoSpecularFlashlight( g_FlashlightPos, vWorldPos, flashlightSpacePosition, worldSpaceNormal, - g_FlashlightAttenuationFactors.xyz, g_FlashlightAttenuationFactors.w, - FlashlightSampler, ShadowDepthSampler, NormalizeRandRotSampler, FLASHLIGHTDEPTHFILTERMODE, FLASHLIGHTSHADOWS, true, vProjPos.xy / vProjPos.z, - fSpecExp, vEyeDir, bDoSpecularWarp, SpecularWarpSampler, fFresnelRanges, g_EnvmapTint_ShadowTweaks, + DoSpecularFlashlight( g_FlashlightPos, vWorldPos, flashlightSpacePosition, worldSpaceNormal, + g_FlashlightAttenuationFactors.xyz, g_FlashlightAttenuationFactors.w, + FlashlightSampler, ShadowDepthSampler, NormalizeRandRotSampler, FLASHLIGHTDEPTHFILTERMODE, FLASHLIGHTSHADOWS, true, vProjPos.xy / vProjPos.z, + fSpecExp, vEyeDir, bDoSpecularWarp, SpecularWarpSampler, fFresnelRanges, g_EnvmapTint_ShadowTweaks, - // These two values are output - diffuseLighting, specularLighting ); + // These two values are output + diffuseLighting, specularLighting ); + #endif } // If we didn't already apply Fresnel to specular warp, modulate the specular diff --git a/mp/src/materialsystem/stdshaders/vertexlit_and_unlit_generic_ps2x.fxc b/mp/src/materialsystem/stdshaders/vertexlit_and_unlit_generic_ps2x.fxc index abfd9b6f..eb3cbfac 100644 --- a/mp/src/materialsystem/stdshaders/vertexlit_and_unlit_generic_ps2x.fxc +++ b/mp/src/materialsystem/stdshaders/vertexlit_and_unlit_generic_ps2x.fxc @@ -358,8 +358,8 @@ float4 main( PS_INPUT i ) : COLOR diffuseLighting = f3LightmapColor; #endif - float3 albedo = baseColor; + if (bBlendTintByBaseAlpha) { float3 tintedColor = albedo * g_DiffuseModulation.rgb; diff --git a/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp b/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp index 4281dcac..5e7e61e9 100644 --- a/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp +++ b/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp @@ -54,6 +54,7 @@ BEGIN_VS_SHADER( VertexLitGeneric, "Help for VertexLitGeneric" ) SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" ) SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" ) SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" ) + SHADER_PARAM( PHONGEXPONENTFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "When using a phong exponent texture, this will be multiplied by the 0..1 that comes out of the texture." ) SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" ) SHADER_PARAM( BASEMAPALPHAPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "indicates that there is no normal map and that the phong mask is in base alpha" ) SHADER_PARAM( INVERTPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "invert the phong mask (0=full phong, 1=no phong)" ) @@ -180,6 +181,7 @@ BEGIN_VS_SHADER( VertexLitGeneric, "Help for VertexLitGeneric" ) info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE; info.m_nPhongWarpTexture = PHONGWARPTEXTURE; info.m_nPhongBoost = PHONGBOOST; + info.m_nPhongExponentFactor = PHONGEXPONENTFACTOR; info.m_nPhongFresnelRanges = PHONGFRESNELRANGES; info.m_nPhong = PHONG; info.m_nBaseMapAlphaPhongMask = BASEMAPALPHAPHONGMASK; diff --git a/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp b/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp index 40390824..431d0de5 100644 --- a/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp +++ b/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp @@ -433,7 +433,7 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial bool bHasVertexAlpha = bVertexLitGeneric ? false : IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ); /*^*/ // printf("\t\t[%d] bHasVertexColor\n",(int)bHasVertexColor); /*^*/ // printf("\t\t[%d] bHasVertexAlpha\n",(int)bHasVertexAlpha); - + if ( pShader->IsSnapshotting() || (! pContextData ) || ( pContextData->m_bMaterialVarsChanged ) ) { /*^*/ // printf("\t\t[1] snapshotting=%d pContextData=%08x pContextData->m_bMaterialVarsChanged=%d \n",(int)pShader->IsSnapshotting(), (int)pContextData, pContextData ? (int)pContextData->m_bMaterialVarsChanged : -1 ); @@ -1221,7 +1221,6 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial } } - MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; int numBones = pShaderAPI->GetCurrentNumBones(); diff --git a/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h b/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h index 8bc8d430..5820dbeb 100644 --- a/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h +++ b/mp/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h @@ -68,6 +68,7 @@ struct VertexLitGeneric_DX9_Vars_t int m_nPhongWarpTexture; int m_nPhongBoost; int m_nPhongFresnelRanges; + int m_nPhongExponentFactor; int m_nSelfIllumEnvMapMask_Alpha; int m_nAmbientOnly; int m_nHDRColorScale; @@ -131,7 +132,6 @@ struct VertexLitGeneric_DX9_Vars_t int m_nBlendTintByBaseAlpha; int m_nTintReplacesBaseColor; - }; void InitParamsVertexLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, bool bVertexLitGeneric, VertexLitGeneric_DX9_Vars_t &info ); |