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.
 
 
 
 
 
 

199 lines
6.4 KiB

//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
//
// Purpose:
//
//===========================================================================//
// STATIC: "NORMALMAP" "0..1"
// STATIC: "WORLDVERTEXTRANSITION" "0..1"
// STATIC: "SEAMLESS" "0..1"
// STATIC: "DETAIL" "0..1"
#include "common_fog_vs_supportsvertexfog_fxc.h"
#include "common_vs_fxc.h"
const float3 g_FlashlightPos : register( SHADER_SPECIFIC_CONST_0 );
const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_1 );
const float4 g_FlashlightAttenuationFactors : register( SHADER_SPECIFIC_CONST_5 );
#if SEAMLESS
const float4 SeamlessScale : register( SHADER_SPECIFIC_CONST_6 );
#define SEAMLESS_SCALE (SeamlessScale.x)
#endif
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_6 );
const float4 cNormalMapOrDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_8 );
static const int g_FogType = DOWATERFOG;
struct VS_INPUT
{
float3 vPos : POSITION; //This HAS to match lightmappedgeneric_vs20.fxc's position input. Otherwise depth fighting errors occur on the 360
float4 vNormal : NORMAL;
float2 vBaseTexCoord : TEXCOORD0;
#if WORLDVERTEXTRANSITION
float2 vLightmapTexCoord : TEXCOORD1;
float4 vColor : COLOR0;
#endif
#if NORMALMAP
float3 vTangentS : TANGENT;
float3 vTangentT : BINORMAL;
#endif
};
struct VS_OUTPUT
{
float4 projPos : POSITION;
#if HARDWAREFOGBLEND
float fog : FOG;
#endif
float4 spotTexCoord : TEXCOORD0;
#if SEAMLESS
float3 SeamlessTexCoord : TEXCOORD1;
#else
float2 baseTexCoord : TEXCOORD1;
#endif
#if NORMALMAP
float3 tangentPosToLightVector : TEXCOORD2;
float2 normalMapTexCoord : TEXCOORD3;
#else
float3 worldPosToLightVector : TEXCOORD2;
float3 normal : TEXCOORD3;
#endif
float2 detailCoords : TEXCOORD4;
float4 worldPos_worldTransition : TEXCOORD5;
#if HARDWAREFOGBLEND || DOPIXELFOG
float3 projPos_fogFactorW : TEXCOORD6;
#else
float4 projPos_fogFactorW : TEXCOORD6;
#endif
float4 vNormalSqr : COLOR1;
};
float RemapValClamped( float val, float A, float B, float C, float D)
{
float cVal = (val - A) / (B - A);
cVal = saturate( cVal );
return C + (D - C) * cVal;
}
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = (VS_OUTPUT)0;
float3 vObjNormal;
DecompressVertex_Normal( v.vNormal, vObjNormal );
float4 projPos;
float3 worldPos;
float3 worldNormal;
float3 eyeVector;
//Projection math HAS to match lightmappedgeneric_vs20.fxc's math exactly. Otherwise depth fighting errors occur on the 360
worldPos = mul4x3( float4( v.vPos, 1 ), cModel[0] );
projPos = mul( float4( worldPos, 1 ), cViewProj );
o.projPos = projPos;
#ifdef _PS3
// Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
o.projPos.y = -o.projPos.y;
o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
#endif // _PS3
o.projPos_fogFactorW.xyz = projPos.xyw;
worldNormal = mul3x3( vObjNormal, ( float3x3 )cModel[0] );
o.worldPos_worldTransition = float4( worldPos.xyz, 1.0f );
#if HARDWAREFOGBLEND
o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
#endif
#if !DOPIXELFOG && !HARDWAREFOGBLEND
o.projPos_fogFactorW.w = CalcNonFixedFunctionFog( worldPos, g_FogType );
#endif
#if NORMALMAP
float3 worldTangentS = mul3x3( v.vTangentS, ( float3x3 )cModel[0] );
float3 worldTangentT = mul3x3( v.vTangentT, ( float3x3 )cModel[0] );
#endif
#if SEAMLESS
float3 vNormal=normalize( worldNormal );
o.vNormalSqr.xyz = vNormal * vNormal; // sums to 1.
o.SeamlessTexCoord = SEAMLESS_SCALE*worldPos;
// Generate new tangent and binormal with seamless projection
#if NORMALMAP
// Brute-force for prototype - This must match the projection in the pixel shader!
//float3 vVecX = { 1.0f, 0.0f, 0.0f };
//float3 vVecY = { 0.0f, 1.0f, 0.0f };
//float3 vVecZ = { 0.0f, 0.0f, 1.0f };
//worldTangentS.xyz = normalize( ( o.vNormalSqr.x * vVecZ.xyz ) + ( o.vNormalSqr.y * vVecX.xyz ) + ( o.vNormalSqr.z * vVecX.xyz ) );
//worldTangentT.xyz = normalize( ( o.vNormalSqr.x * vVecY.xyz ) + ( o.vNormalSqr.y * vVecZ.xyz ) + ( o.vNormalSqr.z * vVecY.xyz ) );
// Optimized version - This must match the projection in the pixel shader!
worldTangentS.xyz = normalize( float3( o.vNormalSqr.y + o.vNormalSqr.z, 0.0f, o.vNormalSqr.x ) );
worldTangentT.xyz = normalize( float3( 0.0f, o.vNormalSqr.x + o.vNormalSqr.z, o.vNormalSqr.y ) );
#endif
#else
#if (SEAMLESS == 0 )
o.baseTexCoord.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0].xy ) + cBaseTexCoordTransform[0].w;
o.baseTexCoord.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1].xy ) + cBaseTexCoordTransform[1].w;
#endif
#endif
float4 spotTexCoord = TransformFlashlightWorldToTexture( worldPos, g_FlashlightWorldToTexture );
o.spotTexCoord = spotTexCoord.xyzw;
float3 worldPosToLightVector = g_FlashlightPos - worldPos;
#if NORMALMAP
#if (DETAIL == 0)
o.normalMapTexCoord.x = dot( v.vBaseTexCoord, cNormalMapOrDetailTexCoordTransform[0].xy ) + cNormalMapOrDetailTexCoordTransform[0].w;
o.normalMapTexCoord.y = dot( v.vBaseTexCoord, cNormalMapOrDetailTexCoordTransform[1].xy ) + cNormalMapOrDetailTexCoordTransform[1].w;
#else
#if SEAMLESS
o.normalMapTexCoord = v.vBaseTexCoord;
#else
o.normalMapTexCoord = o.baseTexCoord;
#endif
#endif
o.tangentPosToLightVector.x = dot( worldPosToLightVector, worldTangentS );
o.tangentPosToLightVector.y = dot( worldPosToLightVector, worldTangentT );
o.tangentPosToLightVector.z = dot( worldPosToLightVector, worldNormal );
#else
o.worldPosToLightVector = worldPosToLightVector;
o.normal = worldNormal;
#endif
#if DETAIL
o.detailCoords.x = dot( v.vBaseTexCoord, cNormalMapOrDetailTexCoordTransform[0].xy ) + cNormalMapOrDetailTexCoordTransform[0].w;
o.detailCoords.y = dot( v.vBaseTexCoord, cNormalMapOrDetailTexCoordTransform[1].xy ) + cNormalMapOrDetailTexCoordTransform[1].w;
#else
o.detailCoords = float2(0,0);
#endif
//float3 delta = worldPosToLightVector;
//float distSquared = dot( delta, delta );
//float dist = sqrt( distSquared );
//float farZ = g_FlashlightAttenuationFactors.w;
//float endFalloffFactor = RemapValClamped( dist, farZ, 0.6f * farZ, 0.0f, 1.0f );
//o.projPos_atten.w = endFalloffFactor * dot( g_FlashlightAttenuationFactors, float3( 1.0f, 1.0f/dist, 1.0f/distSquared ) );
//o.projPos_atten.w = saturate( o.projPos_atten.w );
#if WORLDVERTEXTRANSITION
o.worldPos_worldTransition.w = v.vColor.w;
#endif
return o;
}