/*============================================================================= DOFAndBloomCommon.usf: Code which is common to depth of field shaders. Copyright 1998-2007 Epic Games, Inc. All Rights Reserved. =============================================================================*/ /** The packed parameters. */ half4 PackedParameters; /** The distance which is 100% focused. */ static half FocusDistance = PackedParameters.r; /** One over the minimum distance from the focal which is 0% focused. */ static half InverseFocusRadius = PackedParameters.g; /** The focus falloff exponent. */ static half FocusExponent = PackedParameters.b; /** clamp for min/max blur amount values - default would be [1,1] */ float2 MinMaxBlurClamp; /** * Computes the unfocused percent for a scene depth. * @param SceneDepth - The scene depth. * @return A unfocused percent for the depth. */ half CalcUnfocusedPercent(float SceneDepth) { // Blur amount based on ratio of distance to focus plane to the focus radius // it is clamped to [-1,1]. Note that FocusDistance can be negative if it // falls behind the near plane. half RelativeDistance = SceneDepth - FocusDistance; half MaxUnfocusedPercent = RelativeDistance < 0 ? MinMaxBlurClamp.x : MinMaxBlurClamp.y; return min( MaxUnfocusedPercent, pow( saturate(abs(RelativeDistance) * InverseFocusRadius), FocusExponent ) ); }