|
|
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
// STATIC: "MIRROR" "0..1" // STATIC: "NORMALMAP" "0..1"
// DYNAMIC: "SKINNING" "0..1" // DYNAMIC: "COMPRESSED_VERTS" "0..1" // DYNAMIC: "NUM_LIGHTS" "0..4"
#include "common_vs_fxc.h"
const float4 g_patternTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); // 0 & 1
const float4 g_const2 : register( SHADER_SPECIFIC_CONST_2 ); #define g_flAspectRatioHeight g_const2.x
static const bool g_bSkinning = SKINNING ? true : false;
struct VS_INPUT { float4 vPos : POSITION; float2 vTexCoord : TEXCOORD0; float4 vNormal : NORMAL; #if ( NORMALMAP == 1 ) float4 vTangent : TANGENT; #endif float4 vBoneWeights : BLENDWEIGHT; float4 vBoneIndices : BLENDINDICES; };
struct VS_OUTPUT { float4 vProjPos : POSITION; float4 vBaseUV_PatternUV : TEXCOORD0; float4 lightAtten : TEXCOORD2; float3 worldPos : TEXCOORD3; #if ( NORMALMAP == 1 ) float3x3 tangentSpaceTranspose : TEXCOORD4; // second row : TEXCOORD5; // third row : TEXCOORD6; #else float3 vWorldNormal : TEXCOORD4; #endif };
// Main VS_OUTPUT main( const VS_INPUT i ) { VS_OUTPUT o;
float4 vPosition, vTangent; float3 vNormal, worldPos, worldNormal, worldTangentS, worldTangentT;
vPosition = i.vPos;
// Perform skinning #if ( NORMALMAP == 0 ) DecompressVertex_Normal( i.vNormal, vNormal ); SkinPositionAndNormal( g_bSkinning, vPosition, vNormal, i.vBoneWeights, i.vBoneIndices, worldPos, worldNormal );
worldNormal = normalize( worldNormal ); o.vWorldNormal = worldNormal; #else DecompressVertex_NormalTangent( i.vNormal, i.vTangent, vNormal, vTangent ); SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent, i.vBoneWeights, i.vBoneIndices, worldPos, worldNormal, worldTangentS, worldTangentT ); worldTangentS = normalize( worldTangentS ); worldTangentT = normalize( worldTangentT ); worldNormal = normalize( worldNormal );
// Tangent space transform o.tangentSpaceTranspose[0].xyz = float3( worldTangentS.x, worldTangentT.x, worldNormal.x ); o.tangentSpaceTranspose[1].xyz = float3( worldTangentS.y, worldTangentT.y, worldNormal.y ); o.tangentSpaceTranspose[2].xyz = float3( worldTangentS.z, worldTangentT.z, worldNormal.z ); #endif
// Bump out the decal so it doesn't z-fight with coplanar polys. // This means we don't have to push decal faces in content, and may dial this value globally if needed. worldPos -= normalize( worldPos.xyz - cEyePos.xyz ) * 0.05;
o.worldPos = worldPos; o.vProjPos = mul( float4( worldPos, 1.0f ), cViewProj );
o.lightAtten.x = GetVertexAttenForLight( worldPos, 0 ); o.lightAtten.y = GetVertexAttenForLight( worldPos, 1 ); o.lightAtten.z = GetVertexAttenForLight( worldPos, 2 ); o.lightAtten.w = GetVertexAttenForLight( worldPos, 3 );
o.vBaseUV_PatternUV.xy = i.vTexCoord; #if (MIRROR == 0) o.vBaseUV_PatternUV.z = dot ( i.vTexCoord, g_patternTexCoordTransform[0].xy ) + g_patternTexCoordTransform[0].w; o.vBaseUV_PatternUV.w = dot ( i.vTexCoord, g_patternTexCoordTransform[1].xy ) + g_patternTexCoordTransform[1].w; #else float2 flippedTexCoord = float2( 1.0f - i.vTexCoord.x, i.vTexCoord.y ); o.vBaseUV_PatternUV.z = dot ( flippedTexCoord, g_patternTexCoordTransform[0].xy ) + g_patternTexCoordTransform[0].w; o.vBaseUV_PatternUV.w = dot ( flippedTexCoord, g_patternTexCoordTransform[1].xy ) + g_patternTexCoordTransform[1].w; #endif
//maintain input texture aspect ratio o.vBaseUV_PatternUV.zw = float2( o.vBaseUV_PatternUV.z, ( (o.vBaseUV_PatternUV.w - 0.5f) * g_flAspectRatioHeight ) + 0.5f );
//o.vWearUV_GrungeUV.x = dot ( i.vTexCoord, g_wearTexCoordTransform[0].xy ) + g_wearTexCoordTransform[0].w; //o.vWearUV_GrungeUV.y = dot ( i.vTexCoord, g_wearTexCoordTransform[1].xy ) + g_wearTexCoordTransform[1].w; //o.vWearUV_GrungeUV.z = dot ( i.vTexCoord, g_grungeTexCoordTransform[0].xy ) + g_grungeTexCoordTransform[0].w; //o.vWearUV_GrungeUV.w = dot ( i.vTexCoord, g_grungeTexCoordTransform[1].xy ) + g_grungeTexCoordTransform[1].w;
return o; }
|