aboutsummaryrefslogtreecommitdiff
path: root/src/shaders/src/LinearizeDepth_PS.hlsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/shaders/src/LinearizeDepth_PS.hlsl')
-rw-r--r--src/shaders/src/LinearizeDepth_PS.hlsl49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/shaders/src/LinearizeDepth_PS.hlsl b/src/shaders/src/LinearizeDepth_PS.hlsl
new file mode 100644
index 0000000..d0881db
--- /dev/null
+++ b/src/shaders/src/LinearizeDepth_PS.hlsl
@@ -0,0 +1,49 @@
+/*
+#permutation RESOLVE_DEPTH 0 1
+*/
+
+/*
+* Copyright (c) 2008-2016, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "FullScreenTriangle_VS.hlsl"
+#include "ConstantBuffers.hlsl"
+
+#if API_GL
+#define DepthTexture g_t0
+#define DepthTextureMS g_t0
+#endif
+
+#if RESOLVE_DEPTH
+Texture2DMS<float> DepthTextureMS : register(t0);
+#else
+Texture2D<float> DepthTexture : register(t0);
+#endif
+
+//----------------------------------------------------------------------------------
+float ConvertToViewDepth(float HardwareDepth)
+{
+ float NormalizedDepth = saturate(g_fInverseDepthRangeA * HardwareDepth + g_fInverseDepthRangeB);
+
+ return 1.0 / (NormalizedDepth * g_fLinearizeDepthA + g_fLinearizeDepthB);
+}
+
+//----------------------------------------------------------------------------------
+float LinearizeDepth_PS(PostProc_VSOut IN) : SV_TARGET
+{
+ AddViewportOrigin(IN);
+
+#if RESOLVE_DEPTH
+ float HardwareDepth = DepthTextureMS.Load(int2(IN.pos.xy), g_iSampleIndex);
+#else
+ float HardwareDepth = DepthTexture.Load(int3(IN.pos.xy, 0));
+#endif
+
+ return ConvertToViewDepth(HardwareDepth);
+}