Counter Strike : Global Offensive Source Code
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.
|
|
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
// STATIC: "STAGE" "0..2" // STATIC: "USEONSTATICPROP" "0..1" // DYNAMIC: "COMPRESSED_VERTS" "0..1"
// Includes #include "common_vs_fxc.h"
// Globals const float g_flTime : register( SHADER_SPECIFIC_CONST_0 ); const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
const float2 g_vConst3 : register( SHADER_SPECIFIC_CONST_3 ); #define g_flPortalOpenAmount g_vConst3.x #define g_flPortalStaticAmount g_vConst3.y
const float g_vIsRecursivePortalView : register( SHADER_SPECIFIC_CONST_4 );
// Structs struct VS_INPUT { float4 vPos : POSITION; // Position #if ( USEONSTATICPROP == 0 ) float4 vNormal : NORMAL; // Normal #endif float2 vTexCoord0 : TEXCOORD0; // Base texture coordinates #if ( USEONSTATICPROP == 0 ) float flDecalOffset : TEXCOORD1; // How far to move each vertex along the normal float4 vTangent : TANGENT; // Flip in w #endif };
struct VS_OUTPUT { float4 vProjPosition : POSITION; // Projection-space position float2 vUv0 : TEXCOORD0; float3 vWorldTangent : TEXCOORD1; float3 vWorldBinormal : TEXCOORD2; float4 vWorldPosition : TEXCOORD3; // Proj pos z in w float3 vProjPosForRefract : TEXCOORD4; float4 vNoiseTexCoord : TEXCOORD5; #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 ) float fog : FOG; #endif };
// Main VS_OUTPUT main( const VS_INPUT i ) { float kFlPortalOuterBorder = 0.075f; // Must match PS!
VS_OUTPUT o = (VS_OUTPUT)0;
float3 vObjNormal; #if ( USEONSTATICPROP == 0 ) { DecompressVertex_Normal( i.vNormal, vObjNormal ); } #endif
// Move the portal decal away from the base surface a bit to avoid z fighting float4 vObjPos = i.vPos.xyzw;
#if ( USEONSTATICPROP == 0 ) { float flDecalOffset = 1.0f; // This offset is used in recursive portal views when using fast clipping (e.g. on the PS3). // It prevents ugly Z fighting between the portal and the surface it's on due to reduced Z precision when // a player is really really close to a portal. if ( g_vIsRecursivePortalView == 0.0f ) { flDecalOffset = i.flDecalOffset; } vObjPos.xyz += flDecalOffset * vObjNormal.xyz; } #endif
// Transform the position float3 vWorldPosition = mul4x3( vObjPos, cModel[0] ); #if ( USEONSTATICPROP == 0 ) float3 vWorldNormal = normalize( mul3x3( vObjNormal, ( float3x3 )cModel[0] ) ); float3 vWorldTangent = normalize( mul3x3( i.vTangent.xyz, ( float3x3 )cModel[0] ) ); float3 vWorldBinormal = normalize( cross( vWorldNormal, vWorldTangent ) * i.vTangent.w ); #else float3 vWorldNormal = float3( 0.0f, 0.0f, 1.0f ); float3 vWorldTangent = float3( 1.0f, 0.0f, 0.0f ); float3 vWorldBinormal = float3( 0.0f, 1.0f, 0.0f ); #endif
o.vWorldPosition.xyz = vWorldPosition.xyz; //o.vWorldNormal.xyz = vWorldNormal.xyz; o.vWorldTangent.xyz = vWorldTangent.xyz + vWorldPosition.xyz; o.vWorldBinormal.xyz = vWorldBinormal.xyz + vWorldPosition.xyz;
// Transform into projection space float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj );
// Map projected position to the refraction texture float2 vRefractPos; vRefractPos.x = vProjPosition.x; vRefractPos.y = -vProjPosition.y; // Invert Y vRefractPos = ( vRefractPos + vProjPosition.w ) * 0.5f; o.vProjPosForRefract.xyz = float3(vRefractPos.x, vRefractPos.y, vProjPosition.w);
#ifdef _PS3 // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1] vProjPosition.y = -vProjPosition.y; vProjPosition.z = 2.0f * vProjPosition.z - vProjPosition.w; #endif // _PS3
o.vProjPosition.xyzw = vProjPosition.xyzw; o.vWorldPosition.w = vProjPosition.z; #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 ) o.fog = CalcFixedFunctionFog( vWorldPosition, FOGTYPE_RANGE ); #endif
// View vector float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz);
// Texture coordinates float2 vBaseUv; vBaseUv.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0].xy ); vBaseUv.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1].xy ); //o.vUv0.xy = vBaseUv.xy; o.vUv0.xy = vBaseUv.xy * ( 1.0f + kFlPortalOuterBorder ) - ( kFlPortalOuterBorder * 0.5f ); // Adjust uv's for shrunken portal
// Portal open time float flPortalOpenAmount = saturate( g_flPortalOpenAmount + 0.001f ); // 0.001f to avoid divide by zero
// Noise UV float kFlBorderNoiseScale = 0.3f; float kFlNoiseUvScroll = g_flTime * 0.0275f; float2 vNoiseUv = ( ( vBaseUv.xy - 0.5f ) / flPortalOpenAmount ) + 0.5f; o.vNoiseTexCoord.xy = ( vNoiseUv.xy * kFlBorderNoiseScale ) + float2( kFlNoiseUvScroll, 0 ); o.vNoiseTexCoord.zw = ( vNoiseUv.xy * kFlBorderNoiseScale ) - float2( kFlNoiseUvScroll, 0 ); // Will fetch as wz to avoid matching layers
return o; }
|