Files
cool-source-archive/materialsystem/stdshaders/vertexlitPBR_vs30.fxc
2021-10-10 19:41:28 +05:00

132 lines
4.4 KiB
Plaintext

//===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
//
// Example vertex shader that can be applied to models
//
//==================================================================================================
// STATIC: "VERTEXCOLOR" "0..1"
// STATIC: "CUBEMAP" "0..1"
// STATIC: "DONT_GAMMA_CONVERT_VERTEX_COLOR" "0..1"
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
// DYNAMIC: "DOWATERFOG" "0..1"
// DYNAMIC: "SKINNING" "0..1"
// DYNAMIC: "LIGHTING_PREVIEW" "0..1"
// DYNAMIC: "NUM_LIGHTS" "0..4"
// DYNAMIC: "DYNAMIC_LIGHT" "0..1"
// DYNAMIC: "STATIC_LIGHT" "0..1"
#include "common_vs_fxc.h"
static const bool g_bSkinning = SKINNING ? true : false;
static const bool g_bVertexColor = VERTEXCOLOR ? true : false;
static const int g_FogType = DOWATERFOG;
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
//-----------------------------------------------------------------------------
// Input vertex format
//-----------------------------------------------------------------------------
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;
float2 vTexCoord0 : TEXCOORD0;
float4 vColor : COLOR0;
float3 vTangentS : TANGENT;
float3 vTangentT : BINORMAL;
float4 vUserData : TANGENT;
};
struct VS_OUTPUT
{
// Stuff that isn't seen by the pixel shader
float4 projPosSetup : POSITION;
float fog : FOG;
// Stuff that is seen by the pixel shader
float2 baseTexCoord : TEXCOORD0;
float4 lightAtten : TEXCOORD1;
float3 worldNormal : TEXCOORD2;
float3 worldPos : TEXCOORD3;
float4 projPos : TEXCOORD4;
float4 color : TEXCOORD5; // Vertex color (from lighting or unlit)
float3 localPos : TEXCOORD6; // for Irradiance calculations
float4 vWorldTangent : TEXCOORD7;
float3 vWorldBinormal : TEXCOORD8;
};
//-----------------------------------------------------------------------------
// Main shader entry point
//-----------------------------------------------------------------------------
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT )0;
bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
bool bStaticLight = STATIC_LIGHT ? true : false;
bool bDoLighting = !g_bVertexColor && (bDynamicLight || bStaticLight);
float4 vPosition = v.vPos;
float3 vNormal;
float4 vTangent;
DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent );
// Perform skinning
float3 worldNormal, worldPos, worldTangentS, worldTangentT;
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 );
// Transform into projection space
float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
o.projPosSetup = vProjPos;
vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ );
o.projPos = vProjPos;
o.fog = CalcFog( worldPos, vProjPos.xyz, g_FogType );
// Needed for water fog alpha and diffuse lighting
o.worldPos = worldPos;
o.worldNormal.xyz = worldNormal.xyz;
o.vWorldTangent = float4( worldTangentS.xyz, vTangent.w ); // Propagate binormal sign in world tangent.w
o.vWorldBinormal.xyz = worldTangentT.xyz;
if ( g_bVertexColor )
{
// Assume that this is unlitgeneric if you are using vertex color.
o.color.rgb = ( DONT_GAMMA_CONVERT_VERTEX_COLOR ) ? v.vColor.rgb : GammaToLinear( v.vColor.rgb );
o.color.a = v.vColor.a;
}
// Scalar attenuations for four lights
o.lightAtten.xyz = float4(0,0,0,0);
#if ( NUM_LIGHTS > 0 )
o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false );
#endif
#if ( NUM_LIGHTS > 1 )
o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false );
#endif
#if ( NUM_LIGHTS > 2 )
o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false );
#endif
#if ( NUM_LIGHTS > 3 )
o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, false );
#endif
// Base texture coordinate transform
o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
return o;
}