You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
3.2 KiB
73 lines
3.2 KiB
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
|
|
|
// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..3" [ps20b] [PC]
|
|
// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC]
|
|
// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [CONSOLE]
|
|
|
|
#include "common_fog_ps_fxc.h"
|
|
// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b]
|
|
// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30]
|
|
// DYNAMIC: "UBERLIGHT" "0..1" [ps30] [PC]
|
|
|
|
#include "common_flashlight_fxc.h"
|
|
#include "shader_constant_register_map.h"
|
|
|
|
sampler BaseTextureSampler : register( s0 );
|
|
sampler SpotSampler : register( s1 );
|
|
sampler FlashlightDepthSampler : register( s2 );
|
|
sampler RandomRotationSampler : register( s3 );
|
|
|
|
const float4 g_FogParams : register( PSREG_FOG_PARAMS );
|
|
const float3 g_EyePos : register( PSREG_EYEPOS_SPEC_EXPONENT );
|
|
const float4 g_ShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS );
|
|
|
|
#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
|
|
|
|
|
|
struct PS_INPUT
|
|
{
|
|
float2 baseTexCoord : TEXCOORD0; // Base texture coordinates
|
|
float4 spotTexCoord : TEXCOORD1; // Spotlight texture coordinates
|
|
float3 vertAtten : TEXCOORD2; // Distance/spot attenuation
|
|
float4 projPos : TEXCOORD3; // Projective space position
|
|
float3 worldPos : TEXCOORD4; // Necessary for pixel fog
|
|
};
|
|
|
|
float4_color_return_type main( PS_INPUT i ) : COLOR
|
|
{
|
|
#if defined( SHADER_MODEL_PS_2_0 )
|
|
float3 result = tex2Dproj( SpotSampler, i.spotTexCoord.xyzw );
|
|
#else
|
|
float3 vProjCoords = i.spotTexCoord.xyz / i.spotTexCoord.w;
|
|
float3 result = tex2D( SpotSampler, vProjCoords ).rgb;
|
|
#endif
|
|
|
|
result *= cFlashlightColor.rgb;
|
|
|
|
#if FLASHLIGHTSHADOWS && ( defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) )
|
|
result *= DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, i.projPos.xy / i.projPos.z, FLASHLIGHTDEPTHFILTERMODE, g_ShadowTweaks );
|
|
|
|
#if UBERLIGHT && defined( SHADER_MODEL_PS_3_0 )
|
|
float4 uberLightPosition = mul( float4( i.worldPos, 1.0f ), g_FlashlightWorldToLight ).yzxw;
|
|
result *= uberlight( uberLightPosition, g_vSmoothEdge0, g_vSmoothEdge1,
|
|
g_vSmoothOneOverWidth, g_vShearRound.xy, g_aAbB, g_vShearRound.zw );
|
|
#endif
|
|
|
|
#endif
|
|
result *= 0.35f; // Without this, unshadowed teeth always seem to glow
|
|
|
|
result *= i.vertAtten; // Distance atten, NdotL and forward vector
|
|
|
|
float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
|
|
result *= baseSample.rgb; // Multiply by base map and diffuse
|
|
|
|
float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.xyz, i.worldPos.xyz, i.projPos.z );
|
|
return FinalOutput( float4( result, baseSample.a ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
|
|
}
|