Files
o3de/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/DepthOfField.azsli
T
2021-03-08 14:30:57 -08:00

47 lines
1.6 KiB
Plaintext

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
inline float InvertDepth(float depth)
{
// Convert depth from [1.0 - 0.0] to [0.0 - 1.0].
// Set the front(near side) to 0.0 and the back(far side) to 1.0.
return 1.0f - depth;
}
inline float ConvertDofFactor(float depth, float far, float near, float focusDistance)
{
// dofFactor : The value Calculated from depth.
// This is used to calculate blend ratio from dofFactor when combining buffers.
// dofFactor = (z-L)/z
// = ((far-near)*L/far*near) * depth + (1-L/near)
// = cameraFactor.x * depth + cameraFactor.y
// L : target object distance.
// z : camera (depthLinear)
// z = -far*near / (far*depth - near*depth - far) [from (depth[0-1] = (far*(z-near)/(far-near)/z))]
float z = -far*near / (far*depth - near*depth - far);
float dofFactor = (z - focusDistance) / z;
return dofFactor;
}
inline float ConvertBlend(float dofFactor, float2 blendFactor)
{
return dofFactor * blendFactor.x + blendFactor.y;
}
inline float4 ConvertBlendsFloat4(float4 dofFactors, float2 blendFactor)
{
return dofFactors * blendFactor.x + blendFactor.y;
}