480 lines
20 KiB
Plaintext
480 lines
20 KiB
Plaintext
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
|
|
|
// STATIC: "CUBEMAP" "0..1"
|
|
// STATIC: "SELFILLUM" "0..1"
|
|
// STATIC: "SELFILLUMFRESNEL" "0..1"
|
|
// STATIC: "FLASHLIGHT" "0..1"
|
|
// STATIC: "LIGHTWARPTEXTURE" "0..1"
|
|
// STATIC: "PHONGWARPTEXTURE" "0..1"
|
|
// STATIC: "WRINKLEMAP" "0..1"
|
|
// STATIC: "DETAIL_BLEND_MODE" "0..6"
|
|
// STATIC: "DETAILTEXTURE" "0..1"
|
|
// STATIC: "RIMLIGHT" "0..1"
|
|
// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC]
|
|
// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC]
|
|
// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX]
|
|
// STATIC: "SHADER_SRGB_READ" "0..1" [XBOX]
|
|
// STATIC: "SHADER_SRGB_READ" "0..0" [PC]
|
|
// STATIC: "WORLD_NORMAL" "0..0" [ps20b] [PC]
|
|
// STATIC: "WORLD_NORMAL" "0..1" [ps30] [PC]
|
|
// STATIC: "WORLD_NORMAL" "0..0" [XBOX]
|
|
// STATIC: "PHONG_HALFLAMBERT" "0..1"
|
|
|
|
// DYNAMIC: "WRITEWATERFOGTODESTALPHA" "0..1"
|
|
#include "common_fog_ps_fxc.h"
|
|
// DYNAMIC: "NUM_LIGHTS" "0..4"
|
|
// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC]
|
|
// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX]
|
|
// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30]
|
|
// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b]
|
|
// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30]
|
|
// DYNAMIC: "UBERLIGHT" "0..1" [ps30] [PC]
|
|
|
|
// blend mode doesn't matter if we only have one texture
|
|
// SKIP: (! $DETAILTEXTURE) && ( $DETAIL_BLEND_MODE != 0 )
|
|
|
|
// We don't care about flashlight depth unless the flashlight is on
|
|
// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 )
|
|
|
|
// We don't care about uberlight unless the flashlight is on
|
|
// SKIP: ( $FLASHLIGHT == 0 ) && ( $UBERLIGHT == 1 ) [ps30]
|
|
|
|
// Only need self illum fresnel when self illum enabled
|
|
// SKIP: ( $SELFILLUM == 0 ) && ( $SELFILLUMFRESNEL == 1 )
|
|
|
|
// Don't skip these on 360 since we do single-pass rendering+flashlight there!
|
|
// SKIP: ( $FLASHLIGHT == 1 ) && ( $SELFILLUMFRESNEL == 1 ) [PC]
|
|
// SKIP: ( $FLASHLIGHT == 1 ) && ( $SELFILLUM == 1 ) [PC]
|
|
|
|
// Only do world normals in constrained case
|
|
// SKIP: ( $WORLD_NORMAL == 1 ) && ( $FLASHLIGHTSHADOWS == 1 ) && ( $NUM_LIGHTS != 0 ) && ( $WRITEWATERFOGTODESTALPHA == 1 )
|
|
|
|
|
|
#include "common_flashlight_fxc.h"
|
|
#include "shader_constant_register_map.h"
|
|
|
|
#ifdef _X360
|
|
#define SINGLE_PASS_FLASHLIGHT 1
|
|
#else
|
|
#define SINGLE_PASS_FLASHLIGHT 0
|
|
#endif
|
|
|
|
const float4 g_SelfIllumTint_and_DetailBlendFactor : register( PSREG_SELFILLUMTINT );
|
|
#if ( SELFILLUMFRESNEL == 1 )
|
|
const float4 g_SelfIllumScaleBiasExpBrightness : register( PSREG_SELFILLUM_SCALE_BIAS_EXP );
|
|
#endif
|
|
const float4 g_DiffuseModulation : register( PSREG_DIFFUSE_MODULATION );
|
|
|
|
const float4 g_vPsConst2 : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS );
|
|
#define g_vEnvmapTint ( g_vPsConst2.xyz )
|
|
#define g_bHasNormalMapAlphaEnvmapMask g_vPsConst2.w
|
|
|
|
#if ( SINGLE_PASS_FLASHLIGHT )
|
|
const float4 g_vPsConst43 : register( c43 );
|
|
#define g_vShadowTweaks g_vPsConst43
|
|
#else
|
|
#define g_vShadowTweaks g_vPsConst2
|
|
#endif
|
|
|
|
const float3 cAmbientCube[6] : register( PSREG_AMBIENT_CUBE );
|
|
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 ); // This is overridden too!
|
|
const float4x4 g_FlashlightWorldToTexture : register( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE );
|
|
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)
|
|
const float4 g_ShaderControls : register( PSREG_SHADER_CONTROLS );
|
|
const float4 g_ShaderControls2 : register( PSREG_SHADER_CONTROLS_2 );
|
|
|
|
#if UBERLIGHT && defined( SHADER_MODEL_PS_3_0 )
|
|
const float3 g_vSmoothEdge0 : register( PSREG_UBERLIGHT_SMOOTH_EDGE_0 ); // ps_3_0 and up (over 32 registers)
|
|
const float3 g_vSmoothEdge1 : register( PSREG_UBERLIGHT_SMOOTH_EDGE_1 );
|
|
const float3 g_vSmoothOneOverWidth : register( PSREG_UBERLIGHT_SMOOTH_EDGE_OOW );
|
|
const float4 g_vShearRound : register( PSREG_UBERLIGHT_SHEAR_ROUND );
|
|
const float4 g_aAbB : register( PSREG_UBERLIGHT_AABB );
|
|
const float4x4 g_FlashlightWorldToLight : register( PSREG_UBERLIGHT_WORLD_TO_LIGHT );
|
|
#endif
|
|
|
|
#if ( SINGLE_PASS_FLASHLIGHT )
|
|
const float4 g_RimParams : register( PSREG_RIMPARAMS );
|
|
#define g_RimMaskControl g_RimParams.x
|
|
#define g_fRimBoost g_RimParams.y
|
|
#else
|
|
#define g_RimMaskControl g_FlashlightAttenuationFactors_RimMask.x
|
|
#define g_fRimBoost g_FlashlightPos_RimBoost.w
|
|
#endif
|
|
|
|
#define g_FlashlightPos g_FlashlightPos_RimBoost.xyz
|
|
#define g_FresnelRanges g_FresnelSpecParams.xyz
|
|
#define g_SpecularBoost g_FresnelSpecParams.w
|
|
#define g_SpecularTint g_SpecularRimParams.xyz
|
|
#define g_RimExponent g_SpecularRimParams.w
|
|
#define g_FlashlightAttenuationFactors g_FlashlightAttenuationFactors_RimMask
|
|
#define g_EyePos g_EyePos_SpecExponent.xyz
|
|
|
|
|
|
// Could merge g_fBaseMapAlphaPhongMask and g_fBaseLumPhongMask into a single -1, 0, 1 control code with some clever negation/saturation logic
|
|
//
|
|
// These scalars control behavior with straight-line "control flow" using lerp operations
|
|
#define g_fBaseMapAlphaPhongMask g_ShaderControls.x
|
|
#define g_fInverseBlendTintByBaseAlpha g_ShaderControls.z
|
|
#define g_fInvertPhongMask g_ShaderControls.w
|
|
#define g_fEnvMapFresnel g_ShaderControls2.x
|
|
#define g_fBaseLumPhongMask g_ShaderControls2.y
|
|
#define g_fSpecExp g_ShaderControls2.z
|
|
#define g_SelfIllumMaskControl g_ShaderControls2.w
|
|
#define g_fAmbientOcclusionStrength g_EyePos_SpecExponent.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)
|
|
sampler NormalMapSampler : register( s3 ); // Normal map, specular mask in alpha
|
|
sampler ShadowDepthSampler : register( s4 ); // Flashlight shadow depth map sampler
|
|
sampler NormalizeRandRotSampler : register( s5 ); // Normalization / RandomRotation samplers
|
|
sampler FlashlightSampler : register( s6 ); // Flashlight cookie
|
|
sampler SpecExponentSampler : register( s7 ); // Specular exponent map
|
|
sampler EnvmapSampler : register( s8 ); // Cubic environment map
|
|
|
|
#if WRINKLEMAP
|
|
sampler WrinkleSampler : register( s9 ); // Compression base
|
|
sampler StretchSampler : register( s10 ); // Expansion base
|
|
sampler NormalWrinkleSampler : register( s11 ); // Compression normal
|
|
sampler NormalStretchSampler : register( s12 ); // Expansion normal
|
|
#endif
|
|
|
|
#if DETAILTEXTURE
|
|
sampler DetailSampler : register( s13 ); // detail texture
|
|
#endif
|
|
|
|
sampler SelfIllumMaskSampler : register( s14 ); // selfillummask
|
|
|
|
#if !defined( _X360 ) && defined( SHADER_MODEL_PS_3_0 )
|
|
sampler AmbientOcclusionSampler : register( s15 ); // screen space ambient occlusion sampler on PC
|
|
#endif
|
|
|
|
#define FLASHLIGHT_ONLY ( FLASHLIGHT && !SINGLE_PASS_FLASHLIGHT )
|
|
|
|
struct PS_INPUT
|
|
{
|
|
#ifdef SHADER_MODEL_PS_3_0
|
|
float2 vPos : VPOS; // Normalized Screenpos, call ComputeScreenPos() to get useful 2D coordinates
|
|
#endif
|
|
|
|
float4 baseTexCoordDetailTexCoord : TEXCOORD0; // xy=base zw=detail
|
|
float4 lightAtten : TEXCOORD1; // Scalar light attenuation factors for FOUR lights
|
|
float3x3 tangentSpaceTranspose : TEXCOORD2;
|
|
// second row : TEXCOORD3;
|
|
// third row : TEXCOORD4;
|
|
float4 projPos_fWrinkleWeight : TEXCOORD5;
|
|
#if HARDWAREFOGBLEND || DOPIXELFOG
|
|
float3 worldPos_vertexFogFactor : TEXCOORD6; //it's important that this declaration stay down here. Moving it seems to trigger a BS compile error on 360 saying we've run out of temp registers.
|
|
#else
|
|
float4 worldPos_vertexFogFactor : TEXCOORD6; //it's important that this declaration stay down here. Moving it seems to trigger a BS compile error on 360 saying we've run out of temp registers.
|
|
#endif
|
|
};
|
|
|
|
#if defined( _X360 )
|
|
// The compiler runs out of temp registers in certain combos, increase the maximum for now
|
|
#if ( ( NUM_LIGHTS > 2 ) && ( FLASHLIGHT == 1 ) && ( RIMLIGHT == 1 ) )
|
|
[maxtempreg(39)]
|
|
#elif ( SHADER_SRGB_READ == 1 ) || ( SELFILLUMFRESNEL == 1 )
|
|
[maxtempreg(35)]
|
|
#endif
|
|
#endif
|
|
|
|
float4 main( PS_INPUT i ) : COLOR
|
|
{
|
|
// Unpacking for convenience
|
|
float fWrinkleWeight = i.projPos_fWrinkleWeight.w;
|
|
float fSSAODepth = i.projPos_fWrinkleWeight.z;
|
|
float3 vProjPos = i.projPos_fWrinkleWeight.xyz;
|
|
float3 vWorldPos = i.worldPos_vertexFogFactor.xyz;
|
|
float4 vLightAtten = i.lightAtten;
|
|
|
|
float4 baseColor = tex2Dsrgb( BaseTextureSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
|
|
float flWrinkleAmount, flStretchAmount, flTextureAmount;
|
|
#if ( WRINKLEMAP )
|
|
{
|
|
flWrinkleAmount = saturate( -fWrinkleWeight ); // One of these two is zero
|
|
flStretchAmount = saturate( fWrinkleWeight ); // while the other is in the 0..1 range
|
|
|
|
flTextureAmount = 1.0f - flWrinkleAmount - flStretchAmount; // These should sum to one
|
|
|
|
float4 wrinkleColor = tex2Dsrgb( WrinkleSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
float4 stretchColor = tex2Dsrgb( StretchSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
|
|
// Apply wrinkle blend to only RGB. Alpha comes from the base texture
|
|
baseColor.rgb = ( flTextureAmount * baseColor ) + ( flWrinkleAmount * wrinkleColor ) + ( flStretchAmount * stretchColor );
|
|
}
|
|
#endif
|
|
|
|
float4 detailColor;
|
|
#if ( DETAILTEXTURE )
|
|
{
|
|
detailColor = tex2D( DetailSampler, i.baseTexCoordDetailTexCoord.zw );
|
|
baseColor = TextureCombine( baseColor, detailColor, DETAIL_BLEND_MODE, g_SelfIllumTint_and_DetailBlendFactor.w );
|
|
}
|
|
#endif
|
|
|
|
float3 lumCoefficients = { 0.3, 0.59, 0.11 };
|
|
float baseLum = dot( baseColor.rgb, lumCoefficients );
|
|
|
|
float fSpecMask = 1.0f;
|
|
float4 normalTexel = tex2D( NormalMapSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
#if ( WRINKLEMAP )
|
|
{
|
|
float4 wrinkleNormal = tex2D( NormalWrinkleSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
float4 stretchNormal = tex2D( NormalStretchSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
normalTexel = flTextureAmount * normalTexel + flWrinkleAmount * wrinkleNormal + flStretchAmount * stretchNormal;
|
|
}
|
|
#endif
|
|
|
|
float3 tangentSpaceNormal = 2.0f * normalTexel.xyz - 1.0f;
|
|
|
|
fSpecMask = lerp( normalTexel.a, baseColor.a, g_fBaseMapAlphaPhongMask );
|
|
fSpecMask = lerp( fSpecMask, baseLum, g_fBaseLumPhongMask );
|
|
|
|
// We need a normal if we're doing any lighting
|
|
float3 worldSpaceNormal = normalize( mul( (float3x3)i.tangentSpaceTranspose, tangentSpaceNormal ) );
|
|
//worldSpaceNormal = float3( 0.0f, 0.0f, 0.0f );
|
|
|
|
float3 vEyeDir = normalize( g_EyePos - vWorldPos );
|
|
|
|
float fFresnelRanges;
|
|
fFresnelRanges = Fresnel( worldSpaceNormal, vEyeDir, g_FresnelRanges );
|
|
|
|
float3 diffuseLighting = float3( 0.0f, 0.0f, 0.0f );
|
|
float3 envMapColor = float3( 0.0f, 0.0f, 0.0f );
|
|
#if ( !FLASHLIGHT_ONLY )
|
|
{
|
|
// Summation of diffuse illumination from all local lights
|
|
diffuseLighting = PixelShaderDoLighting( vWorldPos, worldSpaceNormal,
|
|
float3( 0.0f, 0.0f, 0.0f ), false, true, vLightAtten,
|
|
cAmbientCube, NormalizeRandRotSampler, NUM_LIGHTS, cLightInfo, PHONG_HALFLAMBERT,
|
|
LIGHTWARPTEXTURE, DiffuseWarpSampler );
|
|
|
|
#if( CUBEMAP )
|
|
{
|
|
float3 vReflect = CalcReflectionVectorUnnormalized( worldSpaceNormal, vEyeDir );
|
|
envMapColor = ENV_MAP_SCALE * texCUBE( EnvmapSampler, vReflect ) * g_vEnvmapTint.xyz;
|
|
|
|
// Optionally apply Fresnel to envmap
|
|
envMapColor = lerp( envMapColor, fFresnelRanges * envMapColor, g_fEnvMapFresnel );
|
|
|
|
float fEnvMapMask;
|
|
// Mask is either normal map alpha or base map alpha
|
|
#if ( SELFILLUMFRESNEL == 1 ) // This is to match the 2.0 version of vertexlitgeneric
|
|
{
|
|
fEnvMapMask = lerp( baseColor.a, g_fInvertPhongMask, g_bHasNormalMapAlphaEnvmapMask );
|
|
}
|
|
#else
|
|
{
|
|
fEnvMapMask = lerp( baseColor.a, fSpecMask, g_bHasNormalMapAlphaEnvmapMask );
|
|
}
|
|
#endif
|
|
|
|
envMapColor *= lerp( fEnvMapMask, 1-fEnvMapMask, g_fInvertPhongMask );
|
|
}
|
|
#endif
|
|
}
|
|
#endif
|
|
float fSpecExp = g_fSpecExp;
|
|
|
|
float4 vSpecExpMap = tex2D( SpecExponentSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
float fSpecExpMap = vSpecExpMap.r;
|
|
float fRimMask = 0.0f;
|
|
|
|
#if ( !FLASHLIGHT_ONLY )
|
|
{
|
|
fRimMask = lerp( 1.0f, vSpecExpMap.a, g_RimMaskControl ); // Select rim mask
|
|
}
|
|
#endif
|
|
|
|
// If the exponent passed in as a constant is zero, use the value from the map as the exponent
|
|
#if defined( _X360 )
|
|
[flatten]
|
|
#endif
|
|
if ( fSpecExp == 0 )
|
|
fSpecExp = 1.0f - fSpecExpMap + 150.0f * fSpecExpMap;
|
|
|
|
float3 vSpecularTint;
|
|
// If constant tint is negative, tint with albedo, based upon scalar tint map
|
|
#if defined( _X360 )
|
|
[flatten]
|
|
#endif
|
|
if ( g_SpecularTint.r < 0 )
|
|
vSpecularTint = lerp( float3(1.0f, 1.0f, 1.0f), baseColor.rgb, vSpecExpMap.g );
|
|
else
|
|
vSpecularTint = g_SpecularTint.rgb;
|
|
|
|
#if ( PHONGWARPTEXTURE )
|
|
{
|
|
fFresnelRanges = Fresnel( worldSpaceNormal, vEyeDir, g_FresnelRanges );
|
|
}
|
|
#endif
|
|
|
|
float3 albedo = baseColor.rgb;
|
|
|
|
float3 specularLighting = float3( 0.0f, 0.0f, 0.0f );
|
|
float3 rimLighting = float3( 0.0f, 0.0f, 0.0f );
|
|
#if ( !FLASHLIGHT_ONLY )
|
|
{
|
|
float3 specularLightingFromPhong;
|
|
// Summation of specular from all local lights besides the flashlight
|
|
PixelShaderDoSpecularLighting( vWorldPos, worldSpaceNormal,
|
|
fSpecExp, vEyeDir, vLightAtten,
|
|
NUM_LIGHTS, cLightInfo, PHONGWARPTEXTURE, SpecularWarpSampler, fFresnelRanges, RIMLIGHT, g_RimExponent,
|
|
|
|
// Outputs
|
|
specularLightingFromPhong, rimLighting );
|
|
specularLighting += specularLightingFromPhong;
|
|
}
|
|
#endif
|
|
#if ( FLASHLIGHT )
|
|
{
|
|
float4 flashlightSpacePosition = mul( float4( vWorldPos, 1.0f ), g_FlashlightWorldToTexture );
|
|
|
|
float3 diffuseLightingFromFlashlight;
|
|
float3 specularLightingFromFlashlight;
|
|
|
|
DoSpecularFlashlight( g_FlashlightPos, vWorldPos, flashlightSpacePosition, worldSpaceNormal,
|
|
g_FlashlightAttenuationFactors.xyz, g_FlashlightAttenuationFactors.w,
|
|
FlashlightSampler, ShadowDepthSampler, NormalizeRandRotSampler, FLASHLIGHTDEPTHFILTERMODE, FLASHLIGHTSHADOWS, true, vProjPos.xy / vProjPos.z,
|
|
fSpecExp, vEyeDir, LIGHTWARPTEXTURE, DiffuseWarpSampler, PHONGWARPTEXTURE, SpecularWarpSampler, fFresnelRanges, g_vShadowTweaks,
|
|
|
|
// These two values are output
|
|
diffuseLightingFromFlashlight, specularLightingFromFlashlight );
|
|
|
|
#if ( UBERLIGHT && defined( SHADER_MODEL_PS_3_0 ) )
|
|
{
|
|
float4 uberLightPosition = mul( float4( vWorldPos, 1.0f ), g_FlashlightWorldToLight ).yzxw;
|
|
float fUber = uberlight( uberLightPosition, g_vSmoothEdge0, g_vSmoothEdge1,
|
|
g_vSmoothOneOverWidth, g_vShearRound.xy, g_aAbB, g_vShearRound.zw );
|
|
diffuseLightingFromFlashlight *= fUber;
|
|
specularLightingFromFlashlight *= fUber;
|
|
}
|
|
#endif
|
|
|
|
specularLighting += specularLightingFromFlashlight;
|
|
diffuseLighting += diffuseLightingFromFlashlight;
|
|
}
|
|
#endif
|
|
|
|
// Modulate with spec mask, boost and tint
|
|
specularLighting *= fSpecMask * g_SpecularBoost * vSpecularTint;
|
|
|
|
// If we didn't already apply Fresnel to specular warp, modulate the specular
|
|
#if ( !PHONGWARPTEXTURE )
|
|
{
|
|
specularLighting *= fFresnelRanges;
|
|
}
|
|
#endif
|
|
|
|
// Optionally use basealpha to blend in the diffuse modulation (saturated add of g_fInverseBlendTintByBaseAlpha turns this on/off)
|
|
diffuseLighting *= lerp( float3( 1.0f, 1.0f, 1.0f ), g_DiffuseModulation.rgb, saturate( baseColor.a + g_fInverseBlendTintByBaseAlpha ) );
|
|
|
|
float3 diffuseComponent = albedo * diffuseLighting;
|
|
#if ( SELFILLUM && !FLASHLIGHT_ONLY )
|
|
{
|
|
#if ( SELFILLUMFRESNEL == 1 ) // To free up the constant register...see top of file
|
|
{
|
|
// This will apply a Fresnel term based on the vertex normal (not the per-pixel normal!) to help fake and internal glow look
|
|
float3 vVertexNormal = normalize( float3( i.tangentSpaceTranspose[0].z, i.tangentSpaceTranspose[1].z, i.tangentSpaceTranspose[2].z ) );
|
|
float3 vSelfIllumMask = tex2D( SelfIllumMaskSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
vSelfIllumMask = lerp( baseColor.aaa, vSelfIllumMask, g_SelfIllumMaskControl );
|
|
float flSelfIllumFresnel = ( pow( saturate( dot( vVertexNormal.xyz, vEyeDir.xyz ) ), g_SelfIllumScaleBiasExpBrightness.z ) * g_SelfIllumScaleBiasExpBrightness.x ) + g_SelfIllumScaleBiasExpBrightness.y;
|
|
diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * albedo * g_SelfIllumScaleBiasExpBrightness.w, vSelfIllumMask.rgb * saturate( flSelfIllumFresnel ) );
|
|
}
|
|
#else
|
|
{
|
|
float3 vSelfIllumMask = tex2D( SelfIllumMaskSampler, i.baseTexCoordDetailTexCoord.xy );
|
|
vSelfIllumMask = lerp( baseColor.aaa, vSelfIllumMask, g_SelfIllumMaskControl );
|
|
diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * albedo, vSelfIllumMask );
|
|
}
|
|
#endif
|
|
|
|
diffuseComponent = max( 0.0f, diffuseComponent );
|
|
}
|
|
#endif
|
|
|
|
#if ( DETAILTEXTURE )
|
|
{
|
|
diffuseComponent = TextureCombinePostLighting( diffuseComponent, detailColor, DETAIL_BLEND_MODE, g_SelfIllumTint_and_DetailBlendFactor.w );
|
|
}
|
|
#endif
|
|
|
|
#if ( RIMLIGHT && !FLASHLIGHT_ONLY )
|
|
{
|
|
float fRimFresnel = Fresnel4( worldSpaceNormal, vEyeDir );
|
|
|
|
// Add in rim light modulated with tint, mask and traditional Fresnel (not using Fresnel ranges)
|
|
rimLighting *= fRimMask * fRimFresnel;
|
|
|
|
// Fold rim lighting into specular term by using the max so that we don't really add light twice...
|
|
specularLighting = max( specularLighting, rimLighting );
|
|
|
|
// Add in view-ray lookup from ambient cube
|
|
specularLighting += fRimFresnel * fRimMask * g_fRimBoost * PixelShaderAmbientLight( vEyeDir, cAmbientCube) * saturate(dot(worldSpaceNormal, float3(0, 0 , 1)) );
|
|
}
|
|
#endif
|
|
|
|
// Screen-space dynamic ambient occlusion on PC
|
|
float fAmbientOcclusion = 1.0f;
|
|
#if !defined( _X360 ) && defined( SHADER_MODEL_PS_3_0 )
|
|
{
|
|
fAmbientOcclusion = lerp( 1.0f, tex2D( AmbientOcclusionSampler, ComputeScreenPos( i.vPos ) ).r, g_fAmbientOcclusionStrength );
|
|
}
|
|
#endif
|
|
|
|
float3 result = (specularLighting + envMapColor + diffuseComponent) * fAmbientOcclusion;
|
|
|
|
float flVertexFogFactor = 0.0f;
|
|
#if ( !HARDWAREFOGBLEND && !DOPIXELFOG )
|
|
{
|
|
flVertexFogFactor = i.worldPos_vertexFogFactor.w;
|
|
}
|
|
#endif
|
|
float fogFactor = CalcPixelFogFactorSupportsVertexFog( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, vWorldPos.xyz, vProjPos.z, flVertexFogFactor );
|
|
|
|
float alpha;
|
|
#if ( WRITEWATERFOGTODESTALPHA && ( PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT ) )
|
|
{
|
|
alpha = fogFactor;
|
|
}
|
|
#else
|
|
{
|
|
alpha = g_DiffuseModulation.a;
|
|
|
|
// Want to multiply by 1.0 if we are using base alpha for anything that isn't translucency.
|
|
float fBaseAlphaIsForTranslucency = 1.0f;
|
|
|
|
#if ( SELFILLUM )
|
|
// If we are selfillum, base alpha can only be used for translucency if we have a separate selfillummask
|
|
fBaseAlphaIsForTranslucency *= g_SelfIllumMaskControl;
|
|
#endif
|
|
|
|
// Can't use base alpha for translucency if it's being used for a phong mask.
|
|
fBaseAlphaIsForTranslucency *= ( 1.0f - g_fBaseMapAlphaPhongMask );
|
|
|
|
// Lerp between 1.0f and baseColor.a based on if we are using the basealpha for translucency.
|
|
alpha *= lerp( 1.0f, baseColor.a, fBaseAlphaIsForTranslucency );
|
|
}
|
|
#endif
|
|
|
|
bool bWriteDepthToAlpha = ( WRITE_DEPTH_TO_DESTALPHA != 0 ) && ( WRITEWATERFOGTODESTALPHA == 0 );
|
|
|
|
#if ( WORLD_NORMAL )
|
|
{
|
|
return float4( worldSpaceNormal, fSSAODepth );
|
|
}
|
|
#else
|
|
{
|
|
//FIXME: need to take dowaterfog into consideration
|
|
return FinalOutput( float4( result, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, bWriteDepthToAlpha, vProjPos.z );
|
|
}
|
|
#endif
|
|
}
|