mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-01-07 09:43:40 +08:00
270 lines
8.7 KiB
Plaintext
270 lines
8.7 KiB
Plaintext
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
|
|
|
// STATIC: "HALFLAMBERT" "0..1"
|
|
// STATIC: "USE_WITH_2B" "0..1"
|
|
// STATIC: "DECAL" "0..1" [vs30]
|
|
// STATIC: "FLASHLIGHT" "0..1" [XBOX]
|
|
// STATIC: "NORMALIZEEYEVEC" "0..1"
|
|
// STATIC: "WORLD_NORMAL" "0..0" [vs20] [PC]
|
|
// STATIC: "WORLD_NORMAL" "0..1" [vs30] [PC]
|
|
// STATIC: "WORLD_NORMAL" "0..0" [XBOX]
|
|
// STATIC: "STATICLIGHT3" "0..0" // MAINTOL4DMERGEFIXME
|
|
|
|
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
|
|
// DYNAMIC: "SKINNING" "0..1"
|
|
|
|
// DYNAMIC: "MORPHING" "0..1" [vs30] [ = pShaderAPI->IsHWMorphingEnabled() ]
|
|
// DYNAMIC: "TESSELLATION" "0..2" [vs30] [PC]
|
|
// DYNAMIC: "TESSELLATION" "0..0" [XBOX]
|
|
// DYNAMIC: "TESSELLATION" "0..0" [vs20] [PC]
|
|
|
|
// When tessellating, we don't have room in the super-prim vertices for more colors, tex coords or objects space positions
|
|
// SKIP: ( $STATICLIGHT3 || $MORPHING || $SKINNING || $COMPRESSED_VERTS) && $TESSELLATION
|
|
|
|
#include "common_fog_vs_supportsvertexfog_fxc.h"
|
|
#include "common_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_0 ); // 0 & 1
|
|
|
|
const float4 g_vEyeVector : register( SHADER_SPECIFIC_CONST_2 );
|
|
|
|
const float4 cDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); // 4 & 5
|
|
const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_6 ); // 6, 7, 8, 9
|
|
|
|
#ifdef SHADER_MODEL_VS_3_0
|
|
// NOTE: cMorphTargetTextureDim.xy = target dimensions,
|
|
// cMorphTargetTextureDim.z = 4tuples/morph
|
|
const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_10 );
|
|
const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_11 );
|
|
|
|
sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 );
|
|
#endif
|
|
|
|
|
|
|
|
#if TESSELLATION
|
|
|
|
#include "tessellation_vs_fxc.h"
|
|
const float4 g_SubDControls : register( SHADER_SPECIFIC_CONST_3 );
|
|
sampler2D BezierSampler : register( s1 );
|
|
sampler2D DispSampler : register( s2 );
|
|
// VS_INPUT defined in header
|
|
|
|
#else // no TESSELLATION
|
|
|
|
struct VS_INPUT
|
|
{
|
|
// This is all of the stuff that we ever use.
|
|
float4 vPos : POSITION;
|
|
float4 vBoneWeights : BLENDWEIGHT;
|
|
float4 vBoneIndices : BLENDINDICES;
|
|
float4 vNormal : NORMAL;
|
|
float4 vColor : COLOR0;
|
|
float3 vStaticLight : COLOR1;
|
|
#if STATICLIGHT3
|
|
float3 vStaticLight2 : COLOR2;
|
|
float3 vStaticLight3 : COLOR3;
|
|
#endif
|
|
// make these float2's and stick the [n n 0 1] in the dot math.
|
|
float4 vTexCoord0 : TEXCOORD0;
|
|
float4 vTexCoord1 : TEXCOORD1;
|
|
float4 vTexCoord2 : TEXCOORD2;
|
|
float4 vTexCoord3 : TEXCOORD3;
|
|
float3 vTangentS : TANGENT;
|
|
float3 vTangentT : BINORMAL;
|
|
float4 vUserData : TANGENT;
|
|
// Position and normal/tangent deltas
|
|
float3 vPosFlex : POSITION1;
|
|
float3 vNormalFlex : NORMAL1;
|
|
#ifdef SHADER_MODEL_VS_3_0
|
|
float vVertexID : POSITION2;
|
|
#endif
|
|
};
|
|
|
|
#endif // TESSELLATION
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Output vertex format
|
|
//-----------------------------------------------------------------------------
|
|
struct VS_OUTPUT
|
|
{
|
|
// Stuff that isn't seen by the pixel shader
|
|
float4 projPos : POSITION;
|
|
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
|
float fog : FOG;
|
|
#endif
|
|
|
|
// Stuff that is seen by the pixel shader
|
|
float4 baseTexCoord2_light0e01 : TEXCOORD0;
|
|
#if STATICLIGHT3
|
|
float4 light1e012_light0e2 : TEXCOORD1;
|
|
#else
|
|
float3 lightAtten : TEXCOORD1;
|
|
#endif
|
|
float4 worldVertToEyeVectorXYZ_light2e0 : TEXCOORD2;
|
|
float4 vWorldNormal_light2e1 : TEXCOORD3;
|
|
float4 vWorldTangent : TEXCOORD4;
|
|
#if USE_WITH_2B
|
|
float4 vProjPos : TEXCOORD5;
|
|
#else
|
|
float3 vWorldBinormal : TEXCOORD5;
|
|
#endif
|
|
float4 worldPos_projPosZ : TEXCOORD6;
|
|
float4 detailTexCoord_atten3_or_light2e2_fogFactorW : TEXCOORD7;
|
|
|
|
#if defined( _X360 ) && FLASHLIGHT
|
|
float4 flashlightSpacePos : TEXCOORD8;
|
|
#endif
|
|
};
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Main shader entry point
|
|
//-----------------------------------------------------------------------------
|
|
VS_OUTPUT main( const VS_INPUT v )
|
|
{
|
|
VS_OUTPUT o = ( VS_OUTPUT )0;
|
|
|
|
float4 vPosition, vTangent;
|
|
float3 vNormal, worldPos, worldNormal, worldTangentS, worldTangentT;
|
|
|
|
#if ( TESSELLATION )
|
|
{
|
|
float flDummyWrinkle;
|
|
EvaluateSubdivisionSurface( v, g_SubDControls.x, g_SubDControls.y, g_SubDControls.z, BezierSampler, DispSampler,
|
|
worldNormal, worldPos, worldTangentS, worldTangentT, vTangent.w,
|
|
flDummyWrinkle, o.baseTexCoord2_light0e01.xy, o.detailTexCoord_atten3_or_light2e2_fogFactorW.xy );
|
|
}
|
|
#else // no TESSELLATION
|
|
{
|
|
vPosition = v.vPos;
|
|
|
|
DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent );
|
|
|
|
#if ( !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING )
|
|
{
|
|
ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal, vTangent.xyz );
|
|
}
|
|
#else
|
|
{
|
|
ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect,
|
|
v.vVertexID, v.vTexCoord2, vPosition.xyz, vNormal, vTangent.xyz );
|
|
}
|
|
#endif
|
|
|
|
// Perform skinning
|
|
SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent,
|
|
v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal, worldTangentS, worldTangentT );
|
|
|
|
// Always normalize since flex path is controlled by runtime
|
|
// constant not a shader combo and will always generate the normalization
|
|
worldNormal = normalize( worldNormal );
|
|
worldTangentS = normalize( worldTangentS );
|
|
worldTangentT = normalize( worldTangentT );
|
|
|
|
#if ( defined( SHADER_MODEL_VS_3_0 ) && MORPHING && DECAL )
|
|
{
|
|
// Avoid z precision errors
|
|
worldPos += worldNormal * 0.05f * v.vTexCoord2.z;
|
|
}
|
|
#endif
|
|
|
|
#if ( STATICLIGHT3 )
|
|
{
|
|
// Adjust lighting data
|
|
float3 cStaticLight1 = DoLighting( worldPos, worldNormal, v.vStaticLight, true, false, false );
|
|
float3 cStaticLight2 = DoLighting( worldPos, worldNormal, v.vStaticLight2, true, false, false );
|
|
float3 cStaticLight3 = DoLighting( worldPos, worldNormal, v.vStaticLight3, true, false, false );
|
|
|
|
// Pack 3-streams of lighting data
|
|
o.baseTexCoord2_light0e01.zw = cStaticLight1.xy;
|
|
o.light1e012_light0e2.xyz = cStaticLight2.xyz;
|
|
o.light1e012_light0e2.w = cStaticLight1.z;
|
|
o.worldVertToEyeVectorXYZ_light2e0.w = cStaticLight3.x;
|
|
o.vWorldNormal_light2e1.w = cStaticLight3.y;
|
|
o.detailTexCoord_atten3_or_light2e2_fogFactorW.z = cStaticLight3.z;
|
|
}
|
|
#endif
|
|
|
|
// Base texture coordinate transform
|
|
o.baseTexCoord2_light0e01.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
|
|
o.baseTexCoord2_light0e01.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
|
|
|
|
// Detail texture coordinate transform
|
|
o.detailTexCoord_atten3_or_light2e2_fogFactorW.x = dot( v.vTexCoord0, cDetailTexCoordTransform[0] );
|
|
o.detailTexCoord_atten3_or_light2e2_fogFactorW.y = dot( v.vTexCoord0, cDetailTexCoordTransform[1] );
|
|
}
|
|
#endif // TESSELLATION
|
|
|
|
// Transform into projection space
|
|
o.projPos = mul( float4( worldPos, 1 ), cViewProj );
|
|
|
|
o.vWorldNormal_light2e1.xyz = worldNormal.xyz;
|
|
|
|
o.vWorldTangent = float4( worldTangentS.xyz, vTangent.w ); // Propagate binormal sign in world tangent.w
|
|
|
|
#if ( USE_WITH_2B )
|
|
{
|
|
o.vProjPos = o.projPos;
|
|
}
|
|
#else
|
|
{
|
|
o.vWorldBinormal.xyz = worldTangentT.xyz;
|
|
}
|
|
#endif
|
|
|
|
#if ( STATICLIGHT3 == 0 )
|
|
{
|
|
// Scalar light attenuation
|
|
o.lightAtten.x = GetVertexAttenForLight( worldPos, 0 );
|
|
o.lightAtten.y = GetVertexAttenForLight( worldPos, 1 );
|
|
o.lightAtten.z = GetVertexAttenForLight( worldPos, 2 );
|
|
o.detailTexCoord_atten3_or_light2e2_fogFactorW.z = GetVertexAttenForLight( worldPos, 3 );
|
|
}
|
|
#endif
|
|
|
|
// Needed for water fog alpha and diffuse lighting
|
|
o.worldPos_projPosZ = float4( worldPos, o.projPos.z );
|
|
|
|
#if ( WORLD_NORMAL )
|
|
{
|
|
o.worldPos_projPosZ.w = dot( g_vEyeVector, worldPos.xyz - cEyePos.xyz ); // Linear depth
|
|
}
|
|
#endif
|
|
|
|
// Needed for cubemapping + parallax mapping
|
|
#if ( NORMALIZEEYEVEC == 1 )
|
|
{
|
|
o.worldVertToEyeVectorXYZ_light2e0.xyz = normalize( cEyePos.xyz - worldPos.xyz );
|
|
}
|
|
#else
|
|
{
|
|
o.worldVertToEyeVectorXYZ_light2e0.xyz = cEyePos.xyz - worldPos.xyz;
|
|
}
|
|
#endif
|
|
|
|
#if ( HARDWAREFOGBLEND )
|
|
{
|
|
o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
|
|
}
|
|
#endif
|
|
#if ( !DOPIXELFOG && !HARDWAREFOGBLEND )
|
|
{
|
|
o.detailTexCoord_atten3_or_light2e2_fogFactorW.w = CalcNonFixedFunctionFog( worldPos, g_FogType );
|
|
}
|
|
#endif
|
|
|
|
#if ( defined( _X360 ) && FLASHLIGHT )
|
|
{
|
|
o.flashlightSpacePos = mul( float4( worldPos, 1.0f ), g_FlashlightWorldToTexture );
|
|
}
|
|
#endif
|
|
|
|
|
|
return o;
|
|
}
|