You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
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 float4 InvertDepth(float4 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 float4(1, 1, 1, 1) - 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;
|
|
}
|