// STATIC: "ENVMAP_MASK" "0..1" // STATIC: "TANGENTSPACE" "0..1" // STATIC: "BUMPMAP" "0..1" // STATIC: "DIFFUSEBUMPMAP" "0..1" // STATIC: "VERTEXCOLOR" "0..1" // STATIC: "VERTEXALPHATEXBLENDFACTOR" "0..1" // DYNAMIC: "FASTPATH" "0..1" // DYNAMIC: "DOWATERFOG" "0..1" // DYNAMIC: "LIGHTING_PREVIEW" "0..1" // This should not be a combo since I'm a moron with the tangent space and the flashlight. #include "common_vs_fxc.h" // SKIP: !$BUMPMAP && $DIFFUSEBUMPMAP 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; const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); const float4 cDetailOrBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_2 ); // 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 ); const float4 cBlendMaskTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_6 ); struct VS_INPUT { float3 vPos : POSITION; float3 vNormal : NORMAL; float2 vBaseTexCoord : TEXCOORD0; float2 vLightmapTexCoord : TEXCOORD1; float2 vLightmapTexCoordOffset : TEXCOORD2; float3 vTangentS : TANGENT; float3 vTangentT : BINORMAL; float4 vColor : COLOR0; }; struct VS_OUTPUT { float4 projPos : POSITION; float fog : FOG; float2 baseTexCoord : TEXCOORD0; // detail textures and bumpmaps are mutually exclusive so that we have enough texcoords. float4 detailOrBumpAndEnvmapMaskTexCoord : TEXCOORD1; float4 lightmapTexCoord1And2 : TEXCOORD2; float4 lightmapTexCoord3 : TEXCOORD3; // and basetexcoord*mask_scale float4 worldPos_projPosZ : TEXCOORD4; #if TANGENTSPACE || (LIGHTING_PREVIEW) float3x3 tangentSpaceTranspose : TEXCOORD5; // and 6 and 7 #endif float4 vertexColor : COLOR; float4 vertexBlendX_fogFactorW : COLOR1; }; VS_OUTPUT main( const VS_INPUT v ) { VS_OUTPUT o = ( VS_OUTPUT )0; float4 projPos; float3 worldPos; projPos = mul( float4( v.vPos, 1 ), cModelViewProj ); o.projPos = projPos; worldPos = mul( float4( v.vPos, 1 ), cModel[0] ); #if DOWATERFOG o.worldPos_projPosZ = float4( worldPos, projPos.z ); #else o.worldPos_projPosZ = float4( worldPos, projPos.x ); #endif #if TANGENTSPACE || (LIGHTING_PREVIEW) float3 worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] ); float3 worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] ); float3 worldNormal = mul( v.vNormal, ( float3x3 )cModel[0] ); o.tangentSpaceTranspose[0] = worldTangentS; o.tangentSpaceTranspose[1] = worldTangentT; o.tangentSpaceTranspose[2] = worldNormal; #endif float3 worldVertToEyeVector = VSHADER_VECT_SCALE * (cEyePos - worldPos); #if FASTPATH o.baseTexCoord.xy = v.vBaseTexCoord; o.detailOrBumpAndEnvmapMaskTexCoord.xy = v.vBaseTexCoord.xy; o.lightmapTexCoord3.zw = v.vBaseTexCoord; #else o.baseTexCoord.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0] ) + cBaseTexCoordTransform[0].w; o.baseTexCoord.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1] ) + cBaseTexCoordTransform[1].w; o.detailOrBumpAndEnvmapMaskTexCoord.x = dot( v.vBaseTexCoord, cDetailOrBumpTexCoordTransform[0] ) + cDetailOrBumpTexCoordTransform[0].w; o.detailOrBumpAndEnvmapMaskTexCoord.y = dot( v.vBaseTexCoord, cDetailOrBumpTexCoordTransform[1] ) + cDetailOrBumpTexCoordTransform[1].w; o.lightmapTexCoord3.z = dot( v.vBaseTexCoord, cBlendMaskTexCoordTransform[0] ) + cBlendMaskTexCoordTransform[0].w; o.lightmapTexCoord3.w = dot( v.vBaseTexCoord, cBlendMaskTexCoordTransform[1] ) + cBlendMaskTexCoordTransform[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 ) { // reversed component order # if FASTPATH o.detailOrBumpAndEnvmapMaskTexCoord.wz = v.vBaseTexCoord.xy; # else o.detailOrBumpAndEnvmapMaskTexCoord.w = dot( v.vBaseTexCoord, cEnvmapMaskTexCoordTransform[0] ) + cEnvmapMaskTexCoordTransform[0].w; o.detailOrBumpAndEnvmapMaskTexCoord.z = dot( v.vBaseTexCoord, cEnvmapMaskTexCoordTransform[1] ) + cEnvmapMaskTexCoordTransform[1].w; # endif } o.vertexBlendX_fogFactorW = o.fog = CalcFog( worldPos, projPos, g_FogType ); if (!g_bVertexColor) { #if FASTPATH o.vertexColor = float4( 1.0f, 1.0f, 1.0f, 1.0f ); #else o.vertexColor = cModulationColor; #endif } else { #if FASTPATH o.vertexColor = v.vColor; #else if ( g_bVertexAlphaTexBlendFactor ) { o.vertexColor.rgb = v.vColor.rgb * cModulationColor.rgb; o.vertexColor.a = cModulationColor.a; } else { o.vertexColor = v.vColor * cModulationColor; } #endif } if ( g_bVertexAlphaTexBlendFactor ) { o.vertexBlendX_fogFactorW.r = v.vColor.a; } return o; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5821 | Knut Wikstrom |
Added Valve Source code. This is NOT to be commited to other than new code from Valve. |