Files
UnrealEngineUWP/Engine/Shaders/ShadowDepthPixelShader.usf
2014-10-08 15:27:19 -04:00

117 lines
3.4 KiB
Plaintext

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
ShadowDepthPixelShader.usf: Pixel shader for writing shadow depth.
=============================================================================*/
#include "Common.usf"
#include "Material.usf"
#include "VertexFactory.usf"
#include "ShadowDepthCommon.usf"
#define SECONDARY_OCCLUSION 1
//@todo-rco: Remove this when reenabling for OpenGL
#if !COMPILER_GLSL
#if REFLECTIVE_SHADOW_MAP
#include "LPVWriteVplCommon.usf"
#if RSM_TRANSMISSION
float TransmissionStrength;
float2 ReflectiveShadowMapTextureResolution;
row_major float4x4 ProjectionMatrix;
#endif
#endif
#endif
float3 GetMaterialBounceColor(FMaterialPixelParameters MaterialParameters)
{
half3 BaseColor = GetMaterialBaseColor(MaterialParameters);
return BaseColor;
}
void Main(
FShadowDepthVSToPS Inputs,
out float4 OutColor : SV_Target0
#if REFLECTIVE_SHADOW_MAP
,out float4 OutReflectiveShadowMapDiffuse : SV_Target1
,bool IsFrontFace : SV_IsFrontFace
#endif
#if PERSPECTIVE_CORRECT_DEPTH
,out float OutDepth : SV_DEPTH
#endif
)
{
#if INTERPOLATE_VF_ATTRIBUTES
FMaterialPixelParameters MaterialParameters = GetMaterialPixelParameters(Inputs.FactoryInterpolants, float4(0,0,.00001f,1));
#if INTERPOLATE_POSITION
CalcMaterialParameters(MaterialParameters, 1, Inputs.PixelPosition);
#else
// Note: Using default values for PixelPosition to reduce interpolator cost
CalcMaterialParameters(MaterialParameters, 1, float4(0,0,.00001f,1));
#endif
// Evaluate the mask for masked materials
GetMaterialClippingShadowDepth(MaterialParameters);
#endif
#if PERSPECTIVE_CORRECT_DEPTH
float DepthBias = ShadowParams.x;
float InvMaxSubjectDepth = ShadowParams.y;
Inputs.ShadowDepth *= InvMaxSubjectDepth;
Inputs.ShadowDepth += DepthBias;
OutDepth = saturate(Inputs.ShadowDepth);
#endif
OutColor = 0;
#if REFLECTIVE_SHADOW_MAP
OutReflectiveShadowMapDiffuse = 0;
float3 normal = normalize( MaterialParameters.TangentToWorld[2] ); // Smooth normal
float3 flux = GetMaterialBounceColor(MaterialParameters);
//@todo-rco: Remove this when reenabling for OpenGL
#if !COMPILER_GLSL
#if MATERIAL_INJECT_EMISSIVE_INTO_LPV
float3 emissive = GetMaterialEmissive( MaterialParameters );
#endif
#if SECONDARY_OCCLUSION || MATERIAL_INJECT_EMISSIVE_INTO_LPV
// Optimisation: only add to GV/VPL if the fragment is within the grid
float3 grid = WorldToGrid( MaterialParameters.WorldPosition.xyz );
float minGrid = min( grid.x, min(grid.y,grid.z ) );
float maxGrid = max( grid.x, max(grid.y,grid.z ) );
[branch]
if ( minGrid >= 0.0f && maxGrid <= 32.0f )
{
#if SECONDARY_OCCLUSION && !( MATERIALBLENDING_TRANSLUCENT || MATERIALBLENDING_ALPHACOMPOSITE )
AddToGvList( MaterialParameters.WorldPosition - normal * LpvWrite.GeometryVolumeInjectionBias, flux, normal );
#endif
#if MATERIAL_INJECT_EMISSIVE_INTO_LPV
AddToVplList( MaterialParameters.WorldPosition, emissive * LpvWrite.EmissiveInjectionMultiplier, normal, true );
#endif
}
#endif
#endif
#if MATERIALBLENDING_TRANSLUCENT || MATERIALBLENDING_ALPHACOMPOSITE
OutColor = 0;
OutReflectiveShadowMapDiffuse = 0;
clip(-1);
#else
// Pass the LPV bias multiplier in the alpha channel of the normal
OutColor = float4(normal * .5 + .5, Primitive.LpvBiasMultiplier / 32.0f );
OutReflectiveShadowMapDiffuse = float4(flux, 0);
#endif
#endif
}