Counter Strike : Global Offensive Source Code
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.
 
 
 
 
 
 

602 lines
21 KiB

//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
// STATIC: "SFM" "0..0" [vs20] [PC]
// STATIC: "SFM" "0..1" [vs30] [PC]
// STATIC: "SFM" "0..0" [CONSOLE]
// STATIC: "VERTEXCOLOR" "0..1"
// STATIC: "CUBEMAP" "0..1"
// STATIC: "HALFLAMBERT" "0..1"
// STATIC: "FLASHLIGHT" "0..1"
// disable separate detail UVs & seamless base/detail (does not appear to be used)
// STATIC: "SEPARATE_DETAIL_UVS" "0..0"
// STATIC: "SEAMLESS_BASE" "0..0"
// STATIC: "SEAMLESS_DETAIL" "0..0"
// STATIC: "DECAL" "0..1"
// STATIC: "LIGHTING_PREVIEW" "0..1" [PC] // Disabled. Unused on CS:GO --Thorsten
// STATIC: "LIGHTING_PREVIEW" "0..0" [CONSOLE]
// STATIC: "TREESWAY" "0..0" [vs20] [PC]
// STATIC: "TREESWAY" "0..2" [vs30] [PC]
// STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..1" [vs20] [PC]
// STATIC: "FLATTEN_STATIC_CONTROL_FLOW" "0..0" [CONSOLE]
// STATIC: "CASCADED_SHADOW_MAPPING" "0..1" [vs20] [PC]
// STATIC: "CASCADED_SHADOW_MAPPING" "0..0" [vs30] [PC]
// STATIC: "CSM_BLENDING" "0..1"
// DYNAMIC: "COMPRESSED_VERTS" "0..1"
// DYNAMIC: "DYNAMIC_LIGHT" "0..1"
// DYNAMIC: "SKINNING" "0..1"
// DYNAMIC: "MORPHING" "0..0" [ = false ]
// DYNAMIC: "TESSELLATION" "0..0" [vs30] [PC]
// DYNAMIC: "TESSELLATION" "0..0" [CONSOLE]
// DYNAMIC: "TESSELLATION" "0..0" [vs20] [PC]
// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] [PC]
// DYNAMIC: "NUM_LIGHTS" "0..0" [vs20] [CONSOLE]
// DYNAMIC: "STATICLIGHT3" "0..2"
// 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]
// SKIP: ($SEPARATE_DETAIL_UVS) && ($SEAMLESS_DETAIL)
// SKIP: ($TREESWAY) && ($MORPHING)
// SKIP: ($TREESWAY) && ($TESSELLATION)
// SKIP: ( $TREESWAY ) && ( $SEAMLESS_DETAIL || $SEAMLESS_BASE )
// SKIP: ( $SFM == 0 ) && ( $MORPHING )
// SKIP: ( $SFM == 0 ) && ( $TESSELLATION )
// This blows instruction limits and isn't used
// That is, non-static-control flow is only on MacOS, which doesn't use HARDWAREFOGBLEND
// SKIP: ( $FLATTEN_STATIC_CONTROL_FLOW == 1 ) && ( $HARDWAREFOGBLEND )
#include "common_fog_vs_supportsvertexfog_fxc.h"
// When tessellating, we don't have room in the super-prim vertices for more colors, tex coords or objects space positions
// SKIP: ( $STATICLIGHT3 || $VERTEXCOLOR || $SEAMLESS_BASE || $SEAMLESS_DETAIL || $SEPARATE_DETAIL_UVS || $MORPHING || $SKINNING || $COMPRESSED_VERTS ) && $TESSELLATION
#include "common_vs_fxc.h"
static const bool g_bSkinning = SKINNING ? true : false;
static const int g_FogType = DOWATERFOG;
static const bool g_bVertexColor = VERTEXCOLOR ? true : false;
static const bool g_bCubemap = CUBEMAP ? true : false;
static const bool g_bFlashlight = FLASHLIGHT ? true : false;
static const bool g_bHalfLambert = HALFLAMBERT ? true : false;
#if (defined( SHADER_MODEL_VS_3_0 ) && MORPHING && DECAL)
static const bool g_bDecalOffset = true;
#else
static const bool g_bDecalOffset = false;
#endif
const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); // 0 & 1
#if ( LIGHTING_PREVIEW == 3 )
const float4 g_vEyeVector : register( SHADER_SPECIFIC_CONST_2 );
#define g_flStaticLightEnabled 0
#else
const float4 g_flStaticLightEnabled_vCSMLightColor : register( SHADER_SPECIFIC_CONST_2 );
#define g_flStaticLightEnabled (g_flStaticLightEnabled_vCSMLightColor.x)
#define g_vCSMLightColor (g_flStaticLightEnabled_vCSMLightColor.yzw)
#endif
#if ( CASCADED_SHADOW_MAPPING == 0 )
const float4 g_vMiscParams1 : register( SHADER_SPECIFIC_CONST_3 );
#if ( SEAMLESS_DETAIL || SEAMLESS_BASE )
#define SEAMLESS_SCALE g_vMiscParams1.x
#elif TESSELLATION
#define g_SubDControls g_vMiscParams1
#endif
#endif // CASCADED_SHADOW_MAPPING
const float4 cDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); // 4 & 5
const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_6 ); // 6, 7, 8, 9
const float4 g_vMiscParams2 : register( SHADER_SPECIFIC_CONST_12 );
#define cSinglePassFlashlight g_vMiscParams2.x
const float4 g_vMiscParams3 : register( SHADER_SPECIFIC_CONST_10 );
const float4 g_vMiscParams4 : register( SHADER_SPECIFIC_CONST_11 );
#if ( CASCADED_SHADOW_MAPPING )
const float4x4 g_matWorldToShadowTexMatrices[2] : register( SHADER_SPECIFIC_CONST_CSM_0 );
const float4 g_matWorldToShadowTexMatrix0_z : register( SHADER_SPECIFIC_CONST_CSM_1 );
#endif
#if ( TREESWAY )
#define g_flTime g_vMiscParams2.y
#define g_vWindDir g_vMiscParams2.zw
#define g_flFastSwaySpeedScale g_vMiscParams1.x
#define g_flScrumbleFalloffCurve g_vMiscParams1.y
#define g_flSwayFalloffCurve g_vMiscParams1.z
#define g_flScrumbleSpeed g_vMiscParams1.w
#define g_flHeight g_vMiscParams3.x
#define g_flStartHeight g_vMiscParams3.y
#define g_flRadius g_vMiscParams3.z
#define g_flStartRadius g_vMiscParams3.w
#define g_flSwaySpeed g_vMiscParams4.x
#define g_flSwayIntensity g_vMiscParams4.y
#define g_flScrumbleWaveCount g_vMiscParams4.z
#define g_flScrumbleIntensity g_vMiscParams4.w
#define g_flWindSpeedLerpStart cDetailTexCoordTransform[0].x
#define g_flWindSpeedLerpEnd cDetailTexCoordTransform[0].y
#endif
#if ( MORPHING )
// NOTE: cMorphTargetTextureDim.xy = target dimensions,
// cMorphTargetTextureDim.z = 4tuples/morph
#define cMorphTargetTextureDim g_vMiscParams3
#define cMorphSubrect g_vMiscParams4
sampler2D morphSampler : register( s0 );
#endif
#if ( TESSELLATION )
// VS_INPUT defined in header
#include "tessellation_vs_fxc.h"
sampler2D BezierSampler : register( s1 );
sampler2D DispSampler : register( s2 );
#else // no TESSELLATION
struct VS_INPUT
{
float4 vPos : POSITION;
float4 vBoneWeights : BLENDWEIGHT;
float4 vBoneIndices : BLENDINDICES;
float4 vNormal : NORMAL;
#if VERTEXCOLOR
float4 vColor : COLOR0;
#else
#if DECAL
float4 vStaticLight : COLOR0;
#else
float4 vStaticLight : COLOR1;
#endif
#if STATICLIGHT3
float4 vStaticLight2 : COLOR2;
float4 vStaticLight3 : COLOR3;
#endif
#endif
// make these float2's and stick the [n n 0 1] in the dot math.
float4 vTexCoord0 : TEXCOORD0;
float4 vTexCoord1 : TEXCOORD1;
float4 vTexCoord2 : TEXCOORD2;
float4 vTexCoord3 : TEXCOORD3;
// Position and normal/tangent deltas
float3 vPosFlex : POSITION1;
float3 vNormalFlex : NORMAL1;
#if ( SFM )
float vVertexID : POSITION2;
#endif
};
#endif // TESSELLATION
struct VS_OUTPUT
{
// Stuff that isn't seen by the pixel shader
float4 projPos : POSITION;
#if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
float fog : FOG;
#endif
// Stuff that is seen by the pixel shader
float4 baseTexCoord_baseTexCoord2u : TEXCOORD0; // Base texture coordinates in .xy, seamless in .xyz, 2nd (decal) uv set 'u' in .w
float4 detailTexCoord_baseTexCoord2v : TEXCOORD1; // Detail texture coordinates in .xy, seamless in .xyz, 2nd (decal) uv set 'v' in .w
float4 vWorldNormal_fogFactorW : TEXCOORD2; // world space normal in .xyz, fog factor in .w
float4 vWorldPos_csmXform0z : TEXCOORD3; // world pos in .xyz, csm lightToWorldxformcascade0.z in .w
float4 directionalLightingColor_flShadowDimScalar : TEXCOORD4;
float4 csmXform0or1_csmXform2 : TEXCOORD5; // csm lightToWorldxformcascade0 or 1.xy in .xy lightToWorldxformcascade2.xy in .zw
float4 color : TEXCOORD6; // vertex color from lighting or unlit in .xyz
float4 vProjPos : TEXCOORD7; // proj pos .xyzw
#if FLASHLIGHT && defined( SHADER_MODEL_VS_3_0 )
float4 flashlightSpacePos : TEXCOORD8;
#endif
#if SEAMLESS_DETAIL || SEAMLESS_BASE
float3 SeamlessWeights : COLOR0; // x y z projection weights
#endif
};
#include "tree_sway.h"
float Luminance( float3 cColor )
{
// Formula for calculating luminance based on NTSC standard
return dot( cColor.rgb, float3( 0.2125, 0.7154, 0.0721 ) );
}
VS_OUTPUT main( const VS_INPUT v )
{
VS_OUTPUT o = ( VS_OUTPUT ) 0 ;
bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
bool bStaticLight = g_flStaticLightEnabled ? true : false;
bool bDoLighting = !g_bVertexColor && ( bDynamicLight || bStaticLight);
float3 worldPos;
#if ( TESSELLATION )
{
EvaluateSubdivisionSurface( v, g_SubDControls.x, g_SubDControls.y, g_SubDControls.z,
BezierSampler, DispSampler,
o.vWorldNormal_fogFactorW.xyz, worldPos,
o.baseTexCoord_baseTexCoord2u.xy, o.detailTexCoord_baseTexCoord2v.xy );
float3 vDummySpecular = float3(0,0,0);
o.color_csmXform0z.xyz = DoLighting( worldPos, o.vWorldNormal_fogFactorW.xyz, vDummySpecular, bStaticLight, bDynamicLight, g_bHalfLambert );
}
#else // no TESSELLATION
{
float4 vPosition = v.vPos;
float3 vNormal = 0;
if ( bDoLighting || FLASHLIGHT || SEAMLESS_BASE || SEAMLESS_DETAIL || LIGHTING_PREVIEW || g_bDecalOffset || CUBEMAP )
{
// The vertex only contains valid normals if they are actually needed (fetching them when absent makes D3D complain)
DecompressVertex_Normal( v.vNormal, vNormal );
}
else
{
if ( SEAMLESS_BASE || SEAMLESS_DETAIL || g_bDecalOffset || g_bFlashlight )
{
// The vertex only contains valid normals if they are actually needed (fetching them when absent makes D3D complain)
DecompressVertex_Normal( v.vNormal, vNormal );
}
}
#if ( SEAMLESS_BASE || SEAMLESS_DETAIL )
{
// compute blend weights in rgb
float3 NNormal = normalize( vNormal );
o.SeamlessWeights.xyz = NNormal * NNormal; // sums to 1.
}
#endif
#if ( !MORPHING )
{
ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal );
}
#else
{
ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, v.vTexCoord2, vPosition.xyz, vNormal );
}
#endif
#if ( TREESWAY )
{
vPosition.xyz = ComputeTreeSway( vPosition.xyz, g_flTime );
}
#endif
SkinPositionAndNormal( g_bSkinning, vPosition, vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, o.vWorldNormal_fogFactorW.xyz );
if ( !g_bVertexColor )
{
o.vWorldNormal_fogFactorW.xyz = normalize( o.vWorldNormal_fogFactorW.xyz );
}
#if ( MORPHING && DECAL )
{
// Avoid z precision errors
worldPos += o.vWorldNormal_fogFactorW.xyz * 0.05f * v.vTexCoord2.z;
}
#endif
o.color = float4( 0.0f, 0.0f, 0.0f, 0.0f );
#if ( !FLASHLIGHT ) && ( defined( _GAMECONSOLE ) || defined ( SHADER_MODEL_VS_3_0 ) || ( CASCADED_SHADOW_MAPPING == 1 ) )
{
o.directionalLightingColor_flShadowDimScalar = float4( 0.0f, 0.0f, 0.0f, 0.0f );
}
#endif
#if ( VERTEXCOLOR )
{
// Assume that this is unlitgeneric if you are using vertex color.
o.color.rgb = GammaToLinear( v.vColor.rgb );
o.color.a = v.vColor.a;
}
#else
{
float4 staticLightColor;
float3 vDirectLighting = float3(0.0f, 0.0f, 0.0f);
// Compute vertex lighting
#if ( STATICLIGHT3 != 0 )
{
// We always assume three incoming streams.
// They will not be equal if bumped data is taking this path as part of a lower gpu_level setting.
// They will be equal otherwise.
// Take the average of incoming streams for PS to use (after converting to linear space).
staticLightColor.rgb = GammaToLinear( v.vStaticLight.rgb * cOverbright );
staticLightColor.rgb += GammaToLinear( v.vStaticLight2.rgb * cOverbright );
staticLightColor.rgb += GammaToLinear( v.vStaticLight3.rgb * cOverbright );
// .a already in linear space
staticLightColor.a = ( v.vStaticLight.a + v.vStaticLight2.a + v.vStaticLight3.a );
staticLightColor /= 3.0f;
#if ( ( FLATTEN_STATIC_CONTROL_FLOW == 0 ) || defined ( SHADER_MODEL_VS_3_0 ) )
{
float3 dynamicLighting = float3( 0.0f, 0.0f, 0.0f );
#if ( STATICLIGHT3 == 1 )
// explicitly add dynamic lights (without adding ambient cube)
if ( bDynamicLight )
{
for ( int i = 0; i < g_nLightCount; i++ )
{
dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, i, g_bHalfLambert );
}
}
// Sunlight light baked into static light.
#if ( CSM_BLENDING == 1 )
// Remove sunlight from baked lighting, leaving only indirect.
o.directionalLightingColor_flShadowDimScalar.rgb = g_vCSMLightColor * staticLightColor.a;
staticLightColor.rgb -= o.directionalLightingColor_flShadowDimScalar.rgb;
#else
o.directionalLightingColor_flShadowDimScalar.rgb = float3( 0.0f, 0.0f, 0.0f );
#endif
#else
// STATICLIGHT3 == 2 => indirect lighting only is baked (model classified as phong as far as static lighting is concerned if any materials contain $phong)
// explicitly add dynamic lights (without adding ambient cube)
// dynamic lighting, 0th light is CSM light in this path. We skip it and apply in the pixel shader using baked direct lighting intensity
// stored in o.directionalLightingColor_flShadowDimScalar.a (from baked lighting data)
for ( int i = 0; i < g_nLightCount; i++ )
{
if (i > 0) // starting loop at i == 1 causes warning about forcing the loop to unroll
{
dynamicLighting.rgb += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, i, g_bHalfLambert );
}
}
o.directionalLightingColor_flShadowDimScalar.rgb = cLightInfo[0].color.rgb * staticLightColor.a;
#endif
o.color.rgb = staticLightColor.rgb + dynamicLighting.rgb;
}
#else
{
float3 dynamicLighting = float3( 0.0f, 0.0f, 0.0f );
#if ( STATICLIGHT3 == 1 )
// explicitly add dynamic lights (without adding ambient cube)
if( bDynamicLight ) // Ambient light
{
if ( NUM_LIGHTS >= 1 )
dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 0, g_bHalfLambert );
if ( NUM_LIGHTS >= 2 )
dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 1, g_bHalfLambert );
if ( NUM_LIGHTS >= 3 )
dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 2, g_bHalfLambert );
if ( NUM_LIGHTS >= 4 )
dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 3, g_bHalfLambert );
}
// Sunlight light baked into static light.
#if ( CSM_BLENDING == 1 )
// Remove sunlight from baked lighting, leaving only indirect.
o.directionalLightingColor_flShadowDimScalar.rgb = g_vCSMLightColor * staticLightColor.a;
staticLightColor.rgb -= o.directionalLightingColor_flShadowDimScalar.rgb;
#else
o.directionalLightingColor_flShadowDimScalar.rgb = float3( 0.0f, 0.0f, 0.0f );
#endif
#else
// STATICLIGHT3 == 2 => indirect lighting only is baked (model classified as phong as far as static lighting is concerned if any materials contain $phong)
// explicitly add dynamic lights (without adding ambient cube)
// dynamic lighting, 0th light is CSM light in this path. We skip it and apply in the pixel shader using baked direct lighting intensity
// stored in o.directionalLightingColor_flShadowDimScalar.a (from baked lighting data)
if ( NUM_LIGHTS >= 2 )
dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 1, g_bHalfLambert );
if ( NUM_LIGHTS >= 3 )
dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 2, g_bHalfLambert );
if ( NUM_LIGHTS >= 4 )
dynamicLighting += DoLightInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 3, g_bHalfLambert );
o.directionalLightingColor_flShadowDimScalar.rgb = cLightInfo[0].color.rgb * staticLightColor.a;
#endif
o.color.rgb = staticLightColor.rgb + dynamicLighting.rgb;
}
#endif
}
#else
{
// Single vertex light stream. Typically dynamic props and static props in very old maps.
staticLightColor = v.vStaticLight;
// Note: PS3 treats the color as a 4-vector, big-endian RGBA (as in .rgba <=> .xyzw), hence we need to build the color channels in correct order for PS3 (see e.g. imesh.h)
#if ( ( FLATTEN_STATIC_CONTROL_FLOW == 0 ) || defined ( SHADER_MODEL_VS_3_0 ) )
{
if ( bStaticLight )
{
o.color.xyz = DoLighting( worldPos, o.vWorldNormal_fogFactorW.xyz, staticLightColor.xyz, bStaticLight, bDynamicLight, g_bHalfLambert );
}
else
{
// dynamic lighting only => 0th dlight is the csm casting light
o.color.xyz = DoLightingSeparateDirectional( worldPos, o.vWorldNormal_fogFactorW.xyz, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, vDirectLighting.rgb );
#if ( DECAL==0 )
o.directionalLightingColor_flShadowDimScalar.rgb = vDirectLighting.rgb;
#endif
}
}
#else
{
o.color.xyz = DoLightingUnrolled( worldPos, o.vWorldNormal_fogFactorW.xyz, staticLightColor.xyz, bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS );
}
#endif
}
#endif
#if ( !FLASHLIGHT ) && ( defined( _GAMECONSOLE ) || defined ( SHADER_MODEL_VS_3_0 ) || ( CASCADED_SHADOW_MAPPING == 1 ) )
{
#if (DECAL)
#if ( CSM_BLENDING == 1 )
float flSunAmount = CosineTermInternal( worldPos, o.vWorldNormal_fogFactorW.xyz, 0, g_bHalfLambert ) * v.vStaticLight.w;
o.directionalLightingColor_flShadowDimScalar.rgb *= v.vStaticLight.w;
o.directionalLightingColor_flShadowDimScalar.a = flSunAmount;
#else
o.directionalLightingColor_flShadowDimScalar.a = 0.0;
#endif
#else
if ( bStaticLight )
{
#if ( CSM_BLENDING == 1 )
o.directionalLightingColor_flShadowDimScalar.a = staticLightColor.a;
#else
float flSunPercent = 1.0 - staticLightColor.a;
float flSunAmount = flSunPercent * Luminance( GammaToLinear( staticLightColor.rgb * cOverbright ) );
o.directionalLightingColor_flShadowDimScalar.a = flSunAmount;
#endif
}
else
{
o.directionalLightingColor_flShadowDimScalar.a = 0.0;
}
#endif
}
#endif
}
#endif
#if ( SEAMLESS_BASE )
{
o.baseTexCoord_baseTexCoord2u.xyz = SEAMLESS_SCALE * v.vPos.xyz;
}
#else
{
// Base texture coordinates
o.baseTexCoord_baseTexCoord2u.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
o.baseTexCoord_baseTexCoord2u.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
}
#endif
#if ( SEAMLESS_DETAIL )
{
// FIXME: detail texcoord as a 2d xform doesn't make much sense here, so I just do enough so
// that scale works. More smartness could allow 3d xform.
o.detailTexCoord_baseTexCoord2v.xyz = (SEAMLESS_SCALE*cDetailTexCoordTransform[0].x) * v.vPos.xyz;
}
#else
{
#if ( TREE_SWAY )
{
o.detailTexCoord_baseTexCoord2v.xy = v.vTexCoord0;
}
#else
{
// Detail texture coordinates
// FIXME: This shouldn't have to be computed all the time.
o.detailTexCoord_baseTexCoord2v.x = dot( v.vTexCoord0, cDetailTexCoordTransform[0] );
o.detailTexCoord_baseTexCoord2v.y = dot( v.vTexCoord0, cDetailTexCoordTransform[1] );
}
#endif
}
#endif
#if ( SEPARATE_DETAIL_UVS )
{
o.detailTexCoord_baseTexCoord2v.xy = v.vTexCoord1.xy;
}
#else
{
// 2nd uv set, pass through for now
o.baseTexCoord_baseTexCoord2u.w = v.vTexCoord1.x;
o.detailTexCoord_baseTexCoord2v.w = v.vTexCoord1.y;
}
#endif
}
#endif // TESSELLATION
#if ( !defined( _GAMECONSOLE ) && FLASHLIGHT )
{
//zero out the vertex color in additive two-pass flashlight mode
o.color.rgb *= cSinglePassFlashlight.x;
}
#endif
// Transform into projection space
o.projPos = mul( float4( worldPos, 1 ), cViewProj );
#ifdef _PS3
// Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
o.projPos.y = -o.projPos.y;
o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
#endif // _PS3
o.vProjPos = o.projPos;
o.vWorldPos_csmXform0z.xyz = worldPos;
#if ( LIGHTING_PREVIEW == 3 )
{
o.vProjPos.z = dot( g_vEyeVector, worldPos.xyz - cEyePos.xyz ); // Linear depth
}
#endif
#if ( LIGHTING_PREVIEW )
{
float d = 0.2 + abs( dot( normalize(worldPos.xyz - cEyePos.xyz), o.vWorldNormal_fogFactorW.xyz ) );
o.color.xyz = float3( d, d, d );
}
#endif
#if ( FLASHLIGHT ) && defined( SHADER_MODEL_VS_3_0 )
{
o.flashlightSpacePos = TransformFlashlightWorldToTexture( worldPos, g_FlashlightWorldToTexture );
}
#endif
#if ( HARDWAREFOGBLEND )
{
o.fog = CalcFixedFunctionFog( worldPos, g_FogType );
}
#endif
#if ( !DOPIXELFOG && !HARDWAREFOGBLEND )
{
o.vWorldNormal_fogFactorW.w = CalcNonFixedFunctionFog( worldPos, g_FogType );
}
#endif
#if( CASCADED_SHADOW_MAPPING )
{
float4 worldPos = float4( o.vWorldPos_csmXform0z.xyz, 1.0f );
o.csmXform0or1_csmXform2.xy = mul( worldPos, g_matWorldToShadowTexMatrices[0] ).xy;
o.csmXform0or1_csmXform2.zw = mul( worldPos, g_matWorldToShadowTexMatrices[1] ).xy;
o.vWorldPos_csmXform0z.w = mul( worldPos, g_matWorldToShadowTexMatrix0_z );
}
#endif
return o;
}