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.
116 lines
3.7 KiB
116 lines
3.7 KiB
//============ Copyright (c) Valve Corporation, All rights reserved. ============
|
|
|
|
// STATIC: "BASETEXTURE" "0..1"
|
|
|
|
#include "common_vs_fxc.h"
|
|
|
|
const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
|
|
const float4 cBaseTextureTransform[2] : register( SHADER_SPECIFIC_CONST_3 );
|
|
|
|
struct VS_INPUT
|
|
{
|
|
float4 vPos : POSITION;
|
|
float4 vNormal : NORMAL;
|
|
float4 vBaseTexCoord : TEXCOORD0;
|
|
float2 vLightmapTexCoord : TEXCOORD1;
|
|
float2 vLightmapTexCoordOffset : TEXCOORD2;
|
|
float3 vTangentS : TANGENT;
|
|
float3 vTangentT : BINORMAL0;
|
|
};
|
|
|
|
struct VS_OUTPUT
|
|
{
|
|
float4 vProjPos_POSITION : POSITION;
|
|
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
|
float fog : FOG;
|
|
#endif
|
|
float4 vBumpTexCoordXY_vTexCoordXY : TEXCOORD0;
|
|
float4 vPositionToCameraRayTs_projW : TEXCOORD1;
|
|
float4 vReflectXY_vRefractYX : TEXCOORD2;
|
|
float4 vProjPos : TEXCOORD4;
|
|
float3 worldPos : TEXCOORD5;
|
|
#if BASETEXTURE
|
|
float4 lightmapTexCoord1And2 : TEXCOORD6;
|
|
float4 lightmapTexCoord3 : TEXCOORD7;
|
|
#endif
|
|
};
|
|
|
|
VS_OUTPUT main( const VS_INPUT v )
|
|
{
|
|
VS_OUTPUT o = ( VS_OUTPUT )0;
|
|
|
|
float3 vObjNormal;
|
|
DecompressVertex_Normal( v.vNormal, vObjNormal );
|
|
|
|
// Projected position
|
|
float3 vWorldPos = mul4x3( v.vPos, cModel[0] );
|
|
float4 vProjPos = mul( float4( vWorldPos, 1 ), cViewProj );
|
|
|
|
#ifdef _PS3
|
|
// Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
|
|
vProjPos.y = -vProjPos.y;
|
|
vProjPos.z = 2.0f * vProjPos.z - vProjPos.w;
|
|
#endif // _PS3
|
|
|
|
o.vProjPos = o.vProjPos_POSITION = vProjPos;
|
|
|
|
// Project tangent basis
|
|
float2 vProjTangentS = mul( v.vTangentS, cViewProj ).xy;
|
|
float2 vProjTangentT = mul( v.vTangentT, cViewProj ).xy;
|
|
|
|
// Map projected position to the reflection texture
|
|
float2 vReflectPos;
|
|
vReflectPos.x = -vProjPos.x;
|
|
vReflectPos.y = -vProjPos.y; // invert Y
|
|
vReflectPos = ( vReflectPos + vProjPos.w ) * 0.5f;
|
|
|
|
// Map projected position to the refraction texture
|
|
float2 vRefractPos;
|
|
vRefractPos.x = vProjPos.x;
|
|
vRefractPos.y = -vProjPos.y; // invert Y
|
|
vRefractPos = ( vRefractPos + vProjPos.w ) * 0.5f;
|
|
|
|
// Reflection transform
|
|
o.vReflectXY_vRefractYX = float4( vReflectPos.x, vReflectPos.y, vRefractPos.y, vRefractPos.x );
|
|
o.vPositionToCameraRayTs_projW.w = vProjPos.w;
|
|
|
|
// Compute fog based on the position
|
|
o.worldPos = vWorldPos;
|
|
|
|
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
|
|
o.fog = CalcFixedFunctionFog( vWorldPos, FOGTYPE_RANGE );
|
|
#endif
|
|
|
|
// Eye vector
|
|
float3 vPositionToCameraRayWs = cEyePos.xyz - vWorldPos.xyz;
|
|
// Transform to the tangent space
|
|
o.vPositionToCameraRayTs_projW.x = dot( vPositionToCameraRayWs.xyz, v.vTangentS.xyz );
|
|
o.vPositionToCameraRayTs_projW.y = dot( vPositionToCameraRayWs.xyz, v.vTangentT.xyz );
|
|
o.vPositionToCameraRayTs_projW.z = dot( vPositionToCameraRayWs.xyz, vObjNormal.xyz );
|
|
|
|
// Tranform bump coordinates
|
|
o.vBumpTexCoordXY_vTexCoordXY.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] );
|
|
o.vBumpTexCoordXY_vTexCoordXY.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] );
|
|
|
|
#if BASETEXTURE
|
|
o.vBumpTexCoordXY_vTexCoordXY.z = dot( v.vBaseTexCoord, cBaseTextureTransform[0] );
|
|
o.vBumpTexCoordXY_vTexCoordXY.w = dot( v.vBaseTexCoord, cBaseTextureTransform[1] );
|
|
|
|
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.vBumpTexCoordXY_vTexCoordXY.z = 0.0f;
|
|
o.vBumpTexCoordXY_vTexCoordXY.w = 0.0f;
|
|
#endif
|
|
|
|
return o;
|
|
}
|
|
|