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.
131 lines
4.6 KiB
131 lines
4.6 KiB
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
|
|
|
// STATIC: "VERTEXCOLOR" "0..1"
|
|
// STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1" [vs20] [PC]
|
|
// STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..0" [CONSOLE]
|
|
|
|
// DYNAMIC: "SKINNING" "0..1"
|
|
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
|
|
// DYNAMIC: "DYNAMIC_LIGHT" "0..1"
|
|
// DYNAMIC: "STATIC_LIGHT" "0..1"
|
|
// DYNAMIC: "NUM_LIGHTS" "0..4"
|
|
|
|
// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
|
|
// SKIP: ( $FLATTEN_STATIC_CONTROL_FLOW == 0 ) && ( $NUM_LIGHTS > 0 ) [vs20] [PC]
|
|
|
|
// Includes =======================================================================================
|
|
#include "common_vs_fxc.h"
|
|
|
|
// Structs ========================================================================================
|
|
struct VS_INPUT
|
|
{
|
|
float4 vPos : POSITION; // Position
|
|
float4 vNormal : NORMAL; // Normal
|
|
float4 vBoneWeights : BLENDWEIGHT; // Skin weights
|
|
float4 vBoneIndices : BLENDINDICES; // Skin indices
|
|
float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates
|
|
float4 vTangent : TANGENT;
|
|
#if ( VERTEXCOLOR )
|
|
float4 vVertexColor : COLOR0;
|
|
#endif
|
|
float3 vSpecularN1 : COLOR1;
|
|
float3 vSpecularN2 : TEXCOORD1;
|
|
float3 vSpecularN3 : TEXCOORD2;
|
|
};
|
|
|
|
struct VS_OUTPUT
|
|
{
|
|
float4 vProjPosition : POSITION; // Projection-space position
|
|
float3 vUv0 : TEXCOORD0;
|
|
float3 vWorldNormal : TEXCOORD1;
|
|
float3 vWorldTangent : TEXCOORD2;
|
|
float3 vWorldBinormal : TEXCOORD3;
|
|
float3 vWorldPosition : TEXCOORD4;
|
|
float4 vLightAtten : TEXCOORD5;
|
|
float4 vSpecularPack1 : TEXCOORD6;
|
|
float4 vSpecularPack2 : TEXCOORD7;
|
|
#if ( VERTEXCOLOR )
|
|
float4 vVertexColor : COLOR0;
|
|
#endif
|
|
};
|
|
|
|
// Main ===========================================================================================
|
|
VS_OUTPUT main( const VS_INPUT i )
|
|
{
|
|
VS_OUTPUT o;
|
|
|
|
bool bDynamicLight = false;
|
|
bool bHalfLambert = false;
|
|
|
|
float4 vObjPosition = i.vPos;
|
|
float4 vObjTangent = i.vTangent;
|
|
float3 vObjNormal;
|
|
DecompressVertex_Normal( i.vNormal, vObjNormal );
|
|
|
|
// Transform the position
|
|
float3 vWorldPosition = { 0.0f, 0.0f, 0.0f };
|
|
float3 vWorldNormal = { 0.0f, 0.0f, 0.0f };
|
|
float3 vWorldTangent = { 0.0f, 0.0f, 0.0f };
|
|
float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f };
|
|
SkinPositionNormalAndTangentSpace( SKINNING, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal );
|
|
vWorldNormal.xyz = normalize( vWorldNormal.xyz );
|
|
vWorldTangent.xyz = normalize( vWorldTangent.xyz );
|
|
vWorldBinormal.xyz = normalize( vWorldBinormal.xyz );
|
|
|
|
o.vWorldNormal.xyz = vWorldNormal.xyz;
|
|
o.vWorldTangent.xyz = vWorldTangent.xyz;
|
|
o.vWorldBinormal.xyz = vWorldBinormal.xyz;
|
|
o.vWorldPosition.xyz = vWorldPosition.xyz;
|
|
|
|
// Transform into projection space
|
|
float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj );
|
|
o.vProjPosition.xyzw = vProjPosition.xyzw;
|
|
|
|
// View vector
|
|
float3 vWorldViewVector = normalize( vWorldPosition.xyz - cEyePos.xyz );
|
|
|
|
// Texture coordinates
|
|
o.vUv0.xy = i.vTexCoord0.xy;
|
|
|
|
// Scalar light attenuation
|
|
#if ( defined ( SHADER_MODEL_VS_2_0 ) && FLATTEN_STATIC_CONTROL_FLOW )
|
|
o.vLightAtten = float4( 0, 0 , 0, 0 );
|
|
#if ( NUM_LIGHTS > 0 )
|
|
o.vLightAtten.x = GetVertexAttenForLight( vWorldPosition, 0, false );
|
|
#endif
|
|
#if ( NUM_LIGHTS > 1 )
|
|
o.vLightAtten.y = GetVertexAttenForLight( vWorldPosition, 1, false );
|
|
#endif
|
|
#if ( NUM_LIGHTS > 2 )
|
|
o.vLightAtten.z = GetVertexAttenForLight( vWorldPosition, 2, false );
|
|
#endif
|
|
#if ( NUM_LIGHTS > 3 )
|
|
o.vLightAtten.w = GetVertexAttenForLight( vWorldPosition, 3, false );
|
|
#endif
|
|
#else
|
|
o.vLightAtten.x = GetVertexAttenForLight( vWorldPosition.xyz, 0, true );
|
|
o.vLightAtten.y = GetVertexAttenForLight( vWorldPosition.xyz, 1, true );
|
|
o.vLightAtten.z = GetVertexAttenForLight( vWorldPosition.xyz, 2, true );
|
|
o.vLightAtten.w = GetVertexAttenForLight( vWorldPosition.xyz, 3, true );
|
|
#endif
|
|
|
|
#if ( VERTEXCOLOR )
|
|
{
|
|
o.vVertexColor.rgb = GammaToLinear( i.vVertexColor.rgb );
|
|
o.vVertexColor.a = i.vVertexColor.a;
|
|
}
|
|
#endif
|
|
|
|
float3 cSpecular1 = DoLighting( vWorldPosition, vWorldNormal, i.vSpecularN1, true, bDynamicLight, bHalfLambert );
|
|
float3 cSpecular2 = DoLighting( vWorldPosition, vWorldNormal, i.vSpecularN2, true, bDynamicLight, bHalfLambert );
|
|
float3 cSpecular3 = DoLighting( vWorldPosition, vWorldNormal, i.vSpecularN3, true, bDynamicLight, bHalfLambert );
|
|
|
|
// Packing the lighting information
|
|
o.vSpecularPack1.xyz = cSpecular1.xyz;
|
|
o.vSpecularPack2.xyz = cSpecular2.xyz;
|
|
o.vSpecularPack1.w = cSpecular3.x;
|
|
o.vSpecularPack2.w = cSpecular3.y;
|
|
o.vUv0.z = cSpecular3.z;
|
|
|
|
return o;
|
|
}
|