1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-01-07 09:43:40 +08:00
hl2sdk/materialsystem/stdshaders/multiblend_vs20.fxc
Scott Ehlert fdd0bbf277 SDK sync.
2012-07-06 20:35:59 -05:00

142 lines
4.2 KiB
Plaintext

//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
//
// Purpose:
//
//===========================================================================//
// STATIC: "MODEL" "0..1"
#include "common_fog_vs_fxc.h"
// DYNAMIC: "SKINNING" "0..1"
// DYNAMIC: "MORPHING" "0..1" [vs30] [ = pShaderAPI->IsHWMorphingEnabled() ]
// STATIC: "SPECULAR" "0..1"
// STATIC: "FLASHLIGHT" "0..1"
// STATIC: "FOW" "0..1"
#include "common_vs_fxc.h"
#include "fow_vs_fxc.h"
static const bool g_bSkinning = SKINNING ? true : false;
static const int g_FogType = DOWATERFOG;
const float4 cBaseTexCoordTransform[ 2 ] : register( SHADER_SPECIFIC_CONST_6 );
const float4 g_vFoWWorldSize : register( c26 );
const float4 g_vRotations : register( c27 );
const float4 g_vScales : register( c28 );
const float4 g_vLightDir : register( c29 ); // xyz = light dir, w = spec power
#if ( FLASHLIGHT == 1 )
const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_0 );
#endif
struct VS_INPUT
{
float3 vPos : POSITION;
float4 vNormal : NORMAL;
float2 vBaseTexCoord : TEXCOORD0;
float2 vLightmapTexCoord : TEXCOORD1;
// float2 vLightmapTexCoordOffset : TEXCOORD2;
float4 vAlphaBlend : TEXCOORD3;
float4 vColorBlend1 : TEXCOORD4;
float4 vColorBlend2 : TEXCOORD5;
float4 vColorBlend3 : TEXCOORD6;
float4 vColorBlend4 : TEXCOORD7;
};
struct VS_OUTPUT
{
float4 vProjPos : POSITION;
float4 vBaseTexCoord : TEXCOORD0; // xy = blend 1 coord, zw = lightmap cord
float4 worldPos_projPosZ : TEXCOORD1;
#if FLASHLIGHT
float4 vFlashlightSpacePos : TEXCOORD2;
#endif
float4 vFowCoord : TEXCOORD3; // xy = fow, zw = blend4 coord
float4 vAlphaBlend : TEXCOORD4; // xyz = alpha blend of 1, 2, 3. w = flSpecPower
// float3 worldVertToEyeVector : TEXCOORD5;
float4 vBlendCoords23 : TEXCOORD5;
float4 vColorBlend1 : COLOR0;
float4 vColorBlend2 : COLOR1;
float4 vColorBlend3 : TEXCOORD6;
float3 vColorBlend4 : TEXCOORD7;
};
float2 ComputeTexCoord( const float2 vBaseCoord, const float flRotation, const float flScale )
{
float2 vAdjust = vBaseCoord - float2( 0.5, 0.5 );
float2 vResult;
float c = cos( flRotation );
float s = sin( flRotation );
vResult.x = ( vAdjust.x * c ) + ( vAdjust.y * -s );
vResult.y = ( vAdjust.x * s ) + ( vAdjust.y * c );
return ( vResult / flScale ) + float2( 0.5, 0.5 );
}
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o;
float3 vObjNormal;
DecompressVertex_Normal( v.vNormal, vObjNormal );
float4 vProjPos;
float3 vWorldPos;
vProjPos = mul( float4( v.vPos, 1 ), cModelViewProj );
o.vProjPos = vProjPos;
vWorldPos = mul( float4( v.vPos, 1 ), cModel[0] );
o.worldPos_projPosZ.w = vProjPos.z;
o.worldPos_projPosZ.xyz = vWorldPos;
#if ( FOW == 1 )
o.vFowCoord.xy = CalcFoWCoord( g_vFoWWorldSize, vWorldPos.xy );
#else
o.vFowCoord.xy = float2( 0.0, 0.0 );
#endif
float3 vWorldNormal = mul( vObjNormal, ( float3x3 )cModel[0] );
o.vBaseTexCoord.xy = ComputeTexCoord( v.vBaseTexCoord, g_vRotations.x, g_vScales.x );
o.vBlendCoords23.xy = ComputeTexCoord( v.vBaseTexCoord, g_vRotations.y, g_vScales.y );
o.vBlendCoords23.zw = ComputeTexCoord( v.vBaseTexCoord, g_vRotations.z, g_vScales.z );
o.vFowCoord.zw = ComputeTexCoord( v.vBaseTexCoord, g_vRotations.w, g_vScales.w );
o.vBaseTexCoord.zw = v.vLightmapTexCoord; // + v.vLightmapTexCoordOffset;
o.vColorBlend1 = v.vColorBlend1;
o.vColorBlend2 = v.vColorBlend2;
o.vColorBlend3 = v.vColorBlend3;
o.vColorBlend4.xyz = v.vColorBlend4.xyz;
o.vAlphaBlend.xyz = v.vAlphaBlend.xyz;
#if ( SPECULAR == 1 )
float3 vWorldVertToEyeVector = cEyePos - vWorldPos;
float3 vView = normalize( vWorldVertToEyeVector );
float3 vReflect = reflect( g_vLightDir, vWorldNormal );
float fDot = dot( vView, vReflect );
o.vAlphaBlend.w = saturate( pow( saturate( fDot ), g_vLightDir.w ) );
#else
o.vAlphaBlend.w = 0;
#endif
#if ( FLASHLIGHT == 1 )
o.vFlashlightSpacePos = mul( float4( vWorldPos, 1.0f ), g_FlashlightWorldToTexture );
o.vBaseTexCoord.zw = vProjPos.xy / vProjPos.w;
#endif
return o;
}