Implement reverse z
This commit is contained in:
@@ -506,10 +506,10 @@ void Matrix::OrthoOffCenter(float left, float right, float bottom, float top, fl
|
||||
result = Identity;
|
||||
result.M11 = 2.0f / (right - left);
|
||||
result.M22 = 2.0f / (top - bottom);
|
||||
result.M33 = zRange;
|
||||
result.M33 = -zRange;
|
||||
result.M41 = (left + right) / (left - right);
|
||||
result.M42 = (top + bottom) / (bottom - top);
|
||||
result.M43 = -zNear * zRange;
|
||||
result.M43 = zFar * zRange;
|
||||
}
|
||||
|
||||
void Matrix::PerspectiveFov(float fov, float aspect, float zNear, float zFar, Matrix& result)
|
||||
@@ -525,16 +525,16 @@ void Matrix::PerspectiveFov(float fov, float aspect, float zNear, float zFar, Ma
|
||||
|
||||
void Matrix::PerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, Matrix& result)
|
||||
{
|
||||
const float zRange = zFar / (zFar - zNear);
|
||||
const float zRange = zNear / (zFar - zNear);
|
||||
|
||||
result = Zero;
|
||||
result.M11 = 2.0f * zNear / (right - left);
|
||||
result.M22 = 2.0f * zNear / (top - bottom);
|
||||
result.M31 = (left + right) / (left - right);
|
||||
result.M32 = (top + bottom) / (bottom - top);
|
||||
result.M33 = zRange;
|
||||
result.M33 = -zRange;
|
||||
result.M34 = 1.0f;
|
||||
result.M43 = -zNear * zRange;
|
||||
result.M43 = zFar * zRange;
|
||||
}
|
||||
|
||||
void Matrix::RotationX(float angle, Matrix& result)
|
||||
|
||||
@@ -2176,10 +2176,10 @@ namespace FlaxEngine
|
||||
result = Identity;
|
||||
result.M11 = 2.0f / (right - left);
|
||||
result.M22 = 2.0f / (top - bottom);
|
||||
result.M33 = zRange;
|
||||
result.M33 = -zRange;
|
||||
result.M41 = (left + right) / (left - right);
|
||||
result.M42 = (top + bottom) / (bottom - top);
|
||||
result.M43 = -znear * zRange;
|
||||
result.M43 = zfar * zRange;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2238,14 +2238,14 @@ namespace FlaxEngine
|
||||
public static void PerspectiveFov(float fov, float aspect, float znear, float zfar, out Matrix result)
|
||||
{
|
||||
var yScale = (float)(1.0f / Math.Tan(fov * 0.5f));
|
||||
var q = zfar / (zfar - znear);
|
||||
var zRange = znear / (zfar - znear);
|
||||
result = new Matrix
|
||||
{
|
||||
M11 = yScale / aspect,
|
||||
M22 = yScale,
|
||||
M33 = q,
|
||||
M33 = -zRange,
|
||||
M34 = 1.0f,
|
||||
M43 = -q * znear,
|
||||
M43 = zRange * zfar,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2275,16 +2275,16 @@ namespace FlaxEngine
|
||||
/// <param name="result">When the method completes, contains the created projection matrix.</param>
|
||||
public static void PerspectiveOffCenter(float left, float right, float bottom, float top, float znear, float zfar, out Matrix result)
|
||||
{
|
||||
float zRange = zfar / (zfar - znear);
|
||||
float zRange = znear / (zfar - znear);
|
||||
result = new Matrix
|
||||
{
|
||||
M11 = 2.0f * znear / (right - left),
|
||||
M22 = 2.0f * znear / (top - bottom),
|
||||
M31 = (left + right) / (left - right),
|
||||
M32 = (top + bottom) / (bottom - top),
|
||||
M33 = zRange,
|
||||
M33 = -zRange,
|
||||
M34 = 1.0f,
|
||||
M43 = -znear * zRange,
|
||||
M43 = zfar * zRange,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public:
|
||||
/// </summary>
|
||||
/// <param name="depthBuffer">The depth buffer to clear.</param>
|
||||
/// <param name="depthValue">The clear depth value.</param>
|
||||
API_FUNCTION() virtual void ClearDepth(GPUTextureView* depthBuffer, float depthValue = 1.0f) = 0;
|
||||
API_FUNCTION() virtual void ClearDepth(GPUTextureView* depthBuffer, float depthValue = 0.0f) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Clears an unordered access buffer with a float value.
|
||||
|
||||
@@ -130,7 +130,7 @@ GPUPipelineState::Description GPUPipelineState::Description::Default =
|
||||
true, // DepthEnable
|
||||
true, // DepthWriteEnable
|
||||
true, // DepthClipEnable
|
||||
ComparisonFunc::Less, // DepthFunc
|
||||
ComparisonFunc::Greater, // DepthFunc
|
||||
false, // StencilEnable
|
||||
0xff, // StencilReadMask
|
||||
0xff, // StencilWriteMask
|
||||
@@ -154,7 +154,7 @@ GPUPipelineState::Description GPUPipelineState::Description::DefaultNoDepth =
|
||||
false, // DepthEnable
|
||||
false, // DepthWriteEnable
|
||||
false, // DepthClipEnable
|
||||
ComparisonFunc::Less, // DepthFunc
|
||||
ComparisonFunc::Greater, // DepthFunc
|
||||
false, // StencilEnable
|
||||
0xff, // StencilReadMask
|
||||
0xff, // StencilWriteMask
|
||||
@@ -178,7 +178,7 @@ GPUPipelineState::Description GPUPipelineState::Description::DefaultFullscreenTr
|
||||
false, // DepthEnable
|
||||
false, // DepthWriteEnable
|
||||
false, // DepthClipEnable
|
||||
ComparisonFunc::Less, // DepthFunc
|
||||
ComparisonFunc::Greater, // DepthFunc
|
||||
false, // StencilEnable
|
||||
0xff, // StencilReadMask
|
||||
0xff, // StencilWriteMask
|
||||
|
||||
@@ -27,13 +27,13 @@ Texture2D GBuffer3 : register(t4);
|
||||
// Linearize raw device depth
|
||||
float LinearizeZ(GBufferData gBuffer, float depth)
|
||||
{
|
||||
return gBuffer.ViewInfo.w / (depth - gBuffer.ViewInfo.z);
|
||||
return gBuffer.ViewInfo.w / ((1-depth) - gBuffer.ViewInfo.z);
|
||||
}
|
||||
|
||||
// Convert linear depth to device depth
|
||||
float LinearZ2DeviceDepth(GBufferData gBuffer, float linearDepth)
|
||||
{
|
||||
return (gBuffer.ViewInfo.w / linearDepth) + gBuffer.ViewInfo.z;
|
||||
return 1 - ((gBuffer.ViewInfo.w / linearDepth) + gBuffer.ViewInfo.z);
|
||||
}
|
||||
|
||||
// Get view space position at given pixel coordinate with given device depth
|
||||
|
||||
Reference in New Issue
Block a user