/*============================================================================= ModShadowMeshAttenuationPS.usf: Mesh attenutation PS for modulated shadows Copyright 1998-2010 Epic Games, Inc. All Rights Reserved. =============================================================================*/ #include "Common.usf" #include "Material.usf" #include "VertexFactory.usf" /** * r>0 allows for dot(n,l) attenuation * g>0 allows for emissive attenutation */ float2 AttenAllowed; static const float NdotLAttenAllowed = AttenAllowed.r; static const float EmissiveAttenAllowed = AttenAllowed.g; /** Used to update stencil values for areas we don't want modulated shadows */ void Main( in FVertexFactoryInterpolants FactoryInterpolants, // BIOSTART - September 15, 2010 - Wihlidal, Graham - PS3 Fragment and Vertex Shader Optimizations in half3 TangentLightVector : TEXCOORD4, in half4 CameraVectorOrVertexColor : TEXCOORD5, // BIOEND in float4 PixelPosition : TEXCOORD6, OPTIONAL_FacingSign out float4 OutColor : SV_Target0 ) { FMaterialPixelParameters MaterialParameters = GetMaterialPixelParameters(FactoryInterpolants); CalcMaterialParameters(MaterialParameters,FacingSign,CameraVectorOrVertexColor,PixelPosition,TangentLightVector); half Atten = 0; if(NdotLAttenAllowed > 0) { // N*L attenuation clamped to full. Only render if backfacing wrt light direction half NdotL = dot(MaterialParameters.TangentLightVector,MaterialParameters.TangentNormal); Atten += 1-ceil(saturate(NdotL)); } // On xbox the emissive masking is stored in one of the scene color alpha bits and looked up during the projection pass #if !XBOX if( EmissiveAttenAllowed > 0 ) { // if any emissive color channel is >= 1 then it will be rendered Atten += any(GetMaterialEmissive(MaterialParameters)) ? 1 : 0; } #endif // BW_START - Aug 7, 2020 - Chan, Patrick - [JIRA:METR-31200] Fix shadows casting through to backside of objects // kill the fragment if fully attenuated. Original using DX9 used to do this via Alpha Test clip( Atten < 0.001f ? -1:1 ); // BW_END // color writes are disabled but useful for debug OutColor.rgb = half3(0,Atten,0); // alpha test with a ref value of 0 is used to clip OutColor.a = Atten; }