|
| 1 | +// From Source SDK 2013 https://github.com/ValveSoftware/source-sdk-2013/blob/master/sp/src/materialsystem/stdshaders/Eyes_vs20.fxc |
| 2 | + |
| 3 | +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== |
| 4 | +// $SHADER_SPECIFIC_CONST_0 = eyeball origin |
| 5 | +// $SHADER_SPECIFIC_CONST_1 = eyeball up * 0.5 |
| 6 | +// $SHADER_SPECIFIC_CONST_2 = iris projection U |
| 7 | +// $SHADER_SPECIFIC_CONST_3 = iris projection V |
| 8 | +// $SHADER_SPECIFIC_CONST_4 = glint projection U |
| 9 | +// $SHADER_SPECIFIC_CONST_5 = glint projection V |
| 10 | +//============================================================================= |
| 11 | + |
| 12 | +// STATIC: "INTRO" "0..1" |
| 13 | +// STATIC: "HALFLAMBERT" "0..1" |
| 14 | +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] |
| 15 | + |
| 16 | +// DYNAMIC: "COMPRESSED_VERTS" "0..1" |
| 17 | +// DYNAMIC: "SKINNING" "0..1" |
| 18 | +// DYNAMIC: "DOWATERFOG" "0..1" |
| 19 | +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" |
| 20 | +// DYNAMIC: "STATIC_LIGHT" "0..1" |
| 21 | +// DYNAMIC: "MORPHING" "0..1" [vs30] |
| 22 | +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] |
| 23 | + |
| 24 | +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo |
| 25 | +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] |
| 26 | + |
| 27 | +#include "vortwarp_vs20_helper.h" |
| 28 | + |
| 29 | +static const int g_bSkinning = SKINNING ? true : false; |
| 30 | +static const int g_FogType = DOWATERFOG; |
| 31 | +static const bool g_bHalfLambert = HALFLAMBERT ? true : false; |
| 32 | + |
| 33 | +const float3 cEyeOrigin : register( SHADER_SPECIFIC_CONST_0 ); |
| 34 | +const float3 cHalfEyeballUp : register( SHADER_SPECIFIC_CONST_1 ); |
| 35 | +const float4 cIrisProjectionU : register( SHADER_SPECIFIC_CONST_2 ); |
| 36 | +const float4 cIrisProjectionV : register( SHADER_SPECIFIC_CONST_3 ); |
| 37 | +const float4 cGlintProjectionU : register( SHADER_SPECIFIC_CONST_4 ); |
| 38 | +const float4 cGlintProjectionV : register( SHADER_SPECIFIC_CONST_5 ); |
| 39 | +#if INTRO |
| 40 | +const float4 const4 : register( SHADER_SPECIFIC_CONST_6 ); |
| 41 | +#define g_Time const4.w |
| 42 | +#define modelOrigin const4.xyz |
| 43 | +#endif |
| 44 | + |
| 45 | +#ifdef SHADER_MODEL_VS_3_0 |
| 46 | +// NOTE: cMorphTargetTextureDim.xy = target dimensions, |
| 47 | +// cMorphTargetTextureDim.z = 4tuples/morph |
| 48 | +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_7 ); |
| 49 | +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_8 ); |
| 50 | + |
| 51 | +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); |
| 52 | +#endif |
| 53 | + |
| 54 | +struct VS_INPUT |
| 55 | +{ |
| 56 | + float4 vPos : POSITION; // Position |
| 57 | + float4 vBoneWeights : BLENDWEIGHT; // Skin weights |
| 58 | + float4 vBoneIndices : BLENDINDICES; // Skin indices |
| 59 | + float4 vTexCoord0 : TEXCOORD0; // Base (sclera) texture coordinates |
| 60 | + |
| 61 | + float3 vPosFlex : POSITION1; // Delta positions for flexing |
| 62 | +#ifdef SHADER_MODEL_VS_3_0 |
| 63 | + float vVertexID : POSITION2; |
| 64 | +#endif |
| 65 | +}; |
| 66 | + |
| 67 | +struct VS_OUTPUT |
| 68 | +{ |
| 69 | + float4 projPos : POSITION; // Projection-space position |
| 70 | +#if !defined( _X360 ) |
| 71 | + float fog : FOG; // Fixed-function fog factor |
| 72 | +#endif |
| 73 | + float2 baseTC : TEXCOORD0; // Base texture coordinate |
| 74 | + float2 irisTC : TEXCOORD1; // Iris texture coordinates |
| 75 | + float2 glintTC : TEXCOORD2; // Glint texture coordinates |
| 76 | + float3 vColor : TEXCOORD3; // Vertex-lit color |
| 77 | + |
| 78 | + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog |
| 79 | + |
| 80 | +}; |
| 81 | + |
| 82 | +VS_OUTPUT main( const VS_INPUT v ) |
| 83 | +{ |
| 84 | + VS_OUTPUT o; |
| 85 | + |
| 86 | + bool bDynamicLight = DYNAMIC_LIGHT ? true : false; |
| 87 | + bool bStaticLight = STATIC_LIGHT ? true : false; |
| 88 | + |
| 89 | + float4 vPosition = v.vPos; |
| 90 | + float3 dummy = v.vPos.xyz; // dummy values that can't be optimized out |
| 91 | + |
| 92 | +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING |
| 93 | + ApplyMorph( v.vPosFlex, vPosition.xyz ); |
| 94 | +#else |
| 95 | + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, dummy, vPosition.xyz ); |
| 96 | +#endif |
| 97 | + |
| 98 | + // Transform the position and dummy normal (not doing the dummy normal causes invariance issues with the flashlight!) |
| 99 | + float3 worldNormal, worldPos; |
| 100 | + SkinPositionAndNormal( |
| 101 | + g_bSkinning, |
| 102 | + vPosition, dummy, |
| 103 | + v.vBoneWeights, v.vBoneIndices, |
| 104 | + worldPos, worldNormal ); |
| 105 | + |
| 106 | +#if INTRO |
| 107 | + WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, dummy, dummy, dummy ); |
| 108 | +#endif |
| 109 | + |
| 110 | + // Transform into projection space |
| 111 | + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); |
| 112 | + o.projPos = vProjPos; |
| 113 | + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); |
| 114 | + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); |
| 115 | + |
| 116 | +#if !defined( _X360 ) |
| 117 | + // Set fixed-function fog factor |
| 118 | + o.fog = CalcFog( worldPos, vProjPos, g_FogType ); |
| 119 | +#endif |
| 120 | + |
| 121 | + // Normal = (Pos - Eye origin) - just step on dummy normal created above |
| 122 | + worldNormal = worldPos - cEyeOrigin; |
| 123 | + |
| 124 | + // Normal -= 0.5f * (Normal dot Eye Up) * Eye Up |
| 125 | + float normalDotUp = -dot( worldNormal, cHalfEyeballUp) * 0.5f; |
| 126 | + worldNormal = normalize(normalDotUp * cHalfEyeballUp + worldNormal); |
| 127 | + |
| 128 | + // Vertex lighting |
| 129 | +#if ( USE_STATIC_CONTROL_FLOW || defined ( SHADER_MODEL_VS_3_0 ) ) |
| 130 | + o.vColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert ); |
| 131 | +#else |
| 132 | + o.vColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS ); |
| 133 | +#endif |
| 134 | + |
| 135 | + // Texture 0 is the base texture |
| 136 | + // Texture 1 is a planar projection used for the iris |
| 137 | + // Texture 2 is a planar projection used for the glint |
| 138 | + o.baseTC = v.vTexCoord0; |
| 139 | + o.irisTC.x = dot( cIrisProjectionU, float4(worldPos, 1) ); |
| 140 | + o.irisTC.y = dot( cIrisProjectionV, float4(worldPos, 1) ); |
| 141 | + o.glintTC.x = dot( cGlintProjectionU, float4(worldPos, 1) ); |
| 142 | + o.glintTC.y = dot( cGlintProjectionV, float4(worldPos, 1) ); |
| 143 | + |
| 144 | + return o; |
| 145 | +} |
0 commit comments