262 lines
8.1 KiB
Plaintext
262 lines
8.1 KiB
Plaintext
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
|
|
|
// STATIC: "ENVMAP_MASK" "0..1"
|
|
// STATIC: "TANGENTSPACE" "0..1"
|
|
// STATIC: "BUMPMAP" "0..1"
|
|
// STATIC: "DETAILTEXTURE" "0..1"
|
|
// STATIC: "DIFFUSEBUMPMAP" "0..1"
|
|
// STATIC: "VERTEXCOLOR" "0..1"
|
|
// STATIC: "VERTEXALPHATEXBLENDFACTOR" "0..1"
|
|
// STATIC: "PARALLAX_MAPPING" "0..1"
|
|
// STATIC: "SEAMLESS" "0..1"
|
|
// STATIC: "BUMPMASK" "0..1"
|
|
// STATIC: "FLASHLIGHT" "0..1" [XBOX]
|
|
// STATIC: "FANCY_BLENDING" "0..1"
|
|
// STATIC: "SELFILLUM" "0..1"
|
|
// STATIC: "LIGHTING_PREVIEW" "0..3" [PC]
|
|
// STATIC: "LIGHTING_PREVIEW" "0..0" [XBOX]
|
|
|
|
// DYNAMIC: "FASTPATH" "0..1"
|
|
|
|
// This should not be a combo since I'm a moron with the tangent space and the flashlight.
|
|
// SKIP: !$BUMPMAP && $DIFFUSEBUMPMAP
|
|
// SKIP: $SEAMLESS && $PARALLAXMAP
|
|
// SKIP: $BUMPMASK && $PARALLAXMAP
|
|
// SKIP: $BUMPMASK && $SEAMLESS
|
|
|
|
// SKIP: $LIGHTING_PREVIEW && $FLASHLIGHT
|
|
|
|
#include "common_fog_vs_supportsvertexfog_fxc.h"
|
|
#include "common_vs_fxc.h"
|
|
#include "common_lightmappedgeneric_fxc.h"
|
|
|
|
|
|
static const int g_FogType = DOWATERFOG;
|
|
static const bool g_UseSeparateEnvmapMask = ENVMAP_MASK;
|
|
static const bool g_bTangentSpace = TANGENTSPACE;
|
|
static const bool g_bBumpmap = BUMPMAP;
|
|
static const bool g_bBumpmapDiffuseLighting = DIFFUSEBUMPMAP;
|
|
static const bool g_bVertexColor = VERTEXCOLOR;
|
|
static const bool g_bVertexAlphaTexBlendFactor = VERTEXALPHATEXBLENDFACTOR;
|
|
static const bool g_BumpMask = BUMPMASK;
|
|
|
|
#if SEAMLESS
|
|
const float4 SeamlessScale : register( SHADER_SPECIFIC_CONST_0 );
|
|
#define SEAMLESS_SCALE (SeamlessScale.x)
|
|
#else
|
|
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
|
|
const float4 cDetailOrBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_2 );
|
|
#endif
|
|
// This should be identity if we are bump mapping, otherwise we'll screw up the lightmapTexCoordOffset.
|
|
const float4 cEnvmapMaskTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 );
|
|
|
|
#if FLASHLIGHT
|
|
const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_6 );
|
|
#endif
|
|
|
|
#if DETAILTEXTURE && BUMPMAP && !SELFILLUM && !FANCY_BLENDING
|
|
const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_10 ); // not contiguous with the rest!
|
|
#else
|
|
const float4 cFancyBlendMaskTexCoordTransform[2]: register( SHADER_SPECIFIC_CONST_10 ); // not contiguous with the rest!
|
|
#endif
|
|
|
|
#if ( LIGHTING_PREVIEW == 3 )
|
|
const float4 g_vEyeVector : register( SHADER_SPECIFIC_CONST_12 );
|
|
#endif
|
|
|
|
struct VS_INPUT
|
|
{
|
|
float3 vPos : POSITION;
|
|
float4 vNormal : NORMAL;
|
|
float2 vBaseTexCoord : TEXCOORD0;
|
|
float2 vLightmapTexCoord : TEXCOORD1;
|
|
float2 vLightmapTexCoordOffset : TEXCOORD2;
|
|
float3 vTangentS : TANGENT;
|
|
float3 vTangentT : BINORMAL;
|
|
float4 vColor : COLOR0;
|
|
};
|
|
|
|
VS_OUTPUT main( const VS_INPUT v )
|
|
{
|
|
VS_OUTPUT o = ( VS_OUTPUT )0;
|
|
|
|
float3 vObjNormal;
|
|
DecompressVertex_Normal( v.vNormal, vObjNormal );
|
|
|
|
float4 projPos;
|
|
float3 worldPos;
|
|
|
|
projPos = mul( float4( v.vPos, 1 ), cModelViewProj );
|
|
o.projPos = projPos;
|
|
|
|
worldPos = mul( float4( v.vPos, 1 ), cModel[0] );
|
|
|
|
o.worldPos_projPosZ.w = projPos.z;
|
|
o.worldPos_projPosZ.xyz = worldPos;
|
|
|
|
#if ( LIGHTING_PREVIEW == 3 )
|
|
o.worldPos_projPosZ.w = dot( g_vEyeVector, worldPos.xyz - cEyePos.xyz ); // Linear depth
|
|
#endif
|
|
|
|
float3 worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] );
|
|
|
|
#if TANGENTSPACE || LIGHTING_PREVIEW || PARALLAX_MAPPING || defined( _X360 )
|
|
float3 worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] );
|
|
float3 worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] );
|
|
|
|
#if SEAMLESS && BUMPMAP && defined( _X360 )
|
|
float3 n = normalize( worldNormal );
|
|
float3 n2 = n * n; // sums to 1.
|
|
|
|
o.tangentSpaceTranspose[0] = normalize( float3( n2.y + n2.z, 0.0f, n2.x ) );
|
|
o.tangentSpaceTranspose[1] = normalize( float3( 0.0f, n2.x + n2.z, n2.y ) );
|
|
o.tangentSpaceTranspose[2] = worldNormal;
|
|
#else
|
|
o.tangentSpaceTranspose[0] = worldTangentS;
|
|
o.tangentSpaceTranspose[1] = worldTangentT;
|
|
o.tangentSpaceTranspose[2] = worldNormal;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
float3 worldVertToEyeVector = VSHADER_VECT_SCALE * (cEyePos - worldPos);
|
|
|
|
#if ( SEAMLESS )
|
|
{
|
|
// we need to fill in the texture coordinate projections
|
|
o.SeamlessTexCoord_fogFactorW.xyz = SEAMLESS_SCALE * worldPos;
|
|
}
|
|
#else
|
|
{
|
|
if ( FASTPATH )
|
|
{
|
|
o.baseTexCoord_fogFactorZ.xy = v.vBaseTexCoord;
|
|
}
|
|
else
|
|
{
|
|
o.baseTexCoord_fogFactorZ.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0] ) + cBaseTexCoordTransform[0].w;
|
|
o.baseTexCoord_fogFactorZ.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1] ) + cBaseTexCoordTransform[1].w;
|
|
}
|
|
// calculate detailorbumptexcoord
|
|
if ( FASTPATH )
|
|
{
|
|
o.DETAILORBUMPCOORDS = v.vBaseTexCoord.xy;
|
|
}
|
|
else
|
|
{
|
|
o.DETAILORBUMPCOORDS = float2( dot( v.vBaseTexCoord, cDetailOrBumpTexCoordTransform[0] ) + cDetailOrBumpTexCoordTransform[0].w,
|
|
dot( v.vBaseTexCoord, cDetailOrBumpTexCoordTransform[1] ) + cDetailOrBumpTexCoordTransform[1].w );
|
|
}
|
|
}
|
|
#endif
|
|
if ( FASTPATH )
|
|
{
|
|
o.lightmapTexCoord3.zw = v.vBaseTexCoord;
|
|
#if DETAILTEXTURE && BUMPMAP && !SELFILLUM && !FANCY_BLENDING
|
|
o.BUMPCOORDS = v.vBaseTexCoord;
|
|
#endif
|
|
#if FANCY_BLENDING
|
|
o.FANCYBLENDMASKCOORDS = v.vBaseTexCoord;
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
#if DETAILTEXTURE && BUMPMAP && !SELFILLUM && !FANCY_BLENDING
|
|
o.BUMPCOORDS = float2( dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] ) + cBumpTexCoordTransform[0].w,
|
|
dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] ) + cBumpTexCoordTransform[1].w );
|
|
#endif
|
|
#if FANCY_BLENDING
|
|
o.FANCYBLENDMASKCOORDS = float2( dot( v.vBaseTexCoord, cFancyBlendMaskTexCoordTransform[0] ) + cFancyBlendMaskTexCoordTransform[0].w,
|
|
dot( v.vBaseTexCoord, cFancyBlendMaskTexCoordTransform[1] ) + cFancyBlendMaskTexCoordTransform[1].w );
|
|
#endif
|
|
}
|
|
|
|
// compute lightmap coordinates
|
|
if( g_bBumpmap && g_bBumpmapDiffuseLighting )
|
|
{
|
|
o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord + v.vLightmapTexCoordOffset;
|
|
|
|
float2 lightmapTexCoord2 = o.lightmapTexCoord1And2.xy + v.vLightmapTexCoordOffset;
|
|
float2 lightmapTexCoord3 = lightmapTexCoord2 + v.vLightmapTexCoordOffset;
|
|
|
|
// reversed component order
|
|
o.lightmapTexCoord1And2.w = lightmapTexCoord2.x;
|
|
o.lightmapTexCoord1And2.z = lightmapTexCoord2.y;
|
|
|
|
o.lightmapTexCoord3.xy = lightmapTexCoord3;
|
|
}
|
|
else
|
|
{
|
|
o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord;
|
|
}
|
|
|
|
if( g_UseSeparateEnvmapMask || g_BumpMask )
|
|
{
|
|
// reversed component order
|
|
#if FASTPATH
|
|
o.ENVMAPMASKCOORDS = v.vBaseTexCoord.xy;
|
|
#else
|
|
o.ENVMAPMASKCOORDS = float2( dot( v.vBaseTexCoord, cEnvmapMaskTexCoordTransform[0] ) + cEnvmapMaskTexCoordTransform[0].w,
|
|
dot( v.vBaseTexCoord, cEnvmapMaskTexCoordTransform[1] ) + cEnvmapMaskTexCoordTransform[1].w );
|
|
#endif
|
|
}
|
|
|
|
#if ( HARDWAREFOGBLEND )
|
|
{
|
|
o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
|
|
}
|
|
#endif
|
|
|
|
#if ( !DOPIXELFOG && !HARDWAREFOGBLEND )
|
|
{
|
|
#if ( SEAMLESS )
|
|
{
|
|
o.SeamlessTexCoord_fogFactorW.w = CalcNonFixedFunctionFog( worldPos, g_FogType );
|
|
}
|
|
#else
|
|
{
|
|
o.baseTexCoord_fogFactorZ.z = CalcNonFixedFunctionFog( worldPos, g_FogType );
|
|
}
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
if ( !g_bVertexColor )
|
|
{
|
|
o.vertexColor = float4( 1.0f, 1.0f, 1.0f, cModulationColor.a );
|
|
}
|
|
else
|
|
{
|
|
if ( g_bVertexAlphaTexBlendFactor )
|
|
{
|
|
o.vertexColor.rgb = v.vColor.rgb;
|
|
o.vertexColor.a = cModulationColor.a;
|
|
}
|
|
else
|
|
{
|
|
o.vertexColor = v.vColor;
|
|
o.vertexColor.a *= cModulationColor.a;
|
|
}
|
|
}
|
|
#if SEAMLESS
|
|
// compute belnd weights in rgb
|
|
float3 vNormal=normalize( worldNormal );
|
|
o.vertexColor.xyz = vNormal * vNormal; // sums to 1.
|
|
#endif
|
|
|
|
// On 360, we have extra iterators and can fold the flashlight into this shader
|
|
#if defined( _X360 )
|
|
#if FLASHLIGHT
|
|
o.flashlightSpacePos = mul( float4( worldPos, 1.0f ), g_FlashlightWorldToTexture );
|
|
o.vProjPos = projPos;
|
|
#endif
|
|
#endif
|
|
|
|
if ( g_bVertexAlphaTexBlendFactor )
|
|
{
|
|
o.vertexBlendX.x = v.vColor.a;
|
|
}
|
|
|
|
return o;
|
|
}
|