//===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== // STATIC: "HASALPHAMASK" "0..1" // STATIC: "HASSTATICTEXTURE" "0..1" // DYNAMIC: "ADDSTATIC" "0..1" // DYNAMIC: "D_NVIDIA_STEREO" "0..1" [ps20b] [PC] // DYNAMIC: "D_NVIDIA_STEREO" "0..0" [ps20b] [CONSOLE] #include "common_fog_ps_fxc.h" #define USESTATICTEXTURE ( ( ( ADDSTATIC == 1 ) && ( HASSTATICTEXTURE == 1 ) ) ) #include "common_ps_fxc.h" #include "shader_constant_register_map.h" const float4 g_StaticAmount : register( c0 ); //x is static, y is 1.0 - static const float4 g_FogParams : register( PSREG_FOG_PARAMS ); const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); sampler PortalSampler : register( s0 ); #if ( ( HASALPHAMASK == 1 ) || ( USESTATICTEXTURE ) ) sampler SecondarySampler : register( s1 ); #if ( ( HASALPHAMASK == 1 ) && ( USESTATICTEXTURE ) ) sampler TertiarySampler : register( s2 ); #endif #endif #if D_NVIDIA_STEREO sampler StereoParamSampler : register( s3 ); #endif struct PS_INPUT { float3 vPortalTexCoord : TEXCOORD0; #if ( ( HASALPHAMASK == 1 ) || ( USESTATICTEXTURE ) ) float2 vSecondaryTexCoord : TEXCOORD1; #if ( ( HASALPHAMASK == 1 ) && ( USESTATICTEXTURE ) ) float2 vTertiaryTexCoord : TEXCOORD2; #endif #endif float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog }; // NVIDIA's function to convert mono refract UV to the correct stereo UV for each eye float2 MonoTostereoClipPosXY( float3 vMonoClipPos ) // .z is actually .w { #if ( !D_NVIDIA_STEREO ) { return vMonoClipPos.xy; } #else { // 0th pixel = 1/16 == 1/16 + 1/8 * 0 float flEyeSep = tex2D( StereoParamSampler, float2( 0.0625f, 0 ) ).x; // 0.19 * 0.1316; // 1st pixel = 3/16 == 1/16 + 1/8 * 1 float flConvergence = tex2D( StereoParamSampler, float2( 0.1875, 0 ) ).x; // 4; float3 vStereoClipPos = vMonoClipPos.xyz; // Undo the stereo transform vStereoClipPos.x += flEyeSep * ( vMonoClipPos.z - flConvergence ); return vStereoClipPos.xy; } #endif } float4_color_return_type main( PS_INPUT i ) : COLOR { float4 result; result.rgb = tex2D( PortalSampler, MonoTostereoClipPosXY( i.vPortalTexCoord.xyz ) / i.vPortalTexCoord.z ).rgb; //mix in static #if ( ADDSTATIC == 1 ) { result.rgb *= g_StaticAmount.y; //inverse static on original colors #if ( HASSTATICTEXTURE == 1 ) { #if ( HASALPHAMASK == 1 ) result.rgb += tex2D( TertiarySampler, i.vTertiaryTexCoord ).rgb * g_StaticAmount.x; //static #else result.rgb += tex2D( SecondarySampler, i.vSecondaryTexCoord ).rgb * g_StaticAmount.x; //static #endif } #else { result.rgb += g_StaticAmount.x * 0.25; //mix in gray } #endif } #endif #if ( HASALPHAMASK == 1 ) { //alpha mask result.a = tex2D( SecondarySampler, i.vSecondaryTexCoord ).a; } #else { result.a = 1; } #endif float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w ); return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE ); }