summaryrefslogtreecommitdiffstats
path: root/shaders_inc/ReconstructCameraSpaceZ.fx.h
blob: 5583f3fbd807bae366e6870e0afb2fea1e39cde3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"// ReconstructCameraSpaceZ.fx\n"
"// Reconstructs camera space z from depth\n"
"\n"
"#include \"BasicStructures.fxh\"\n"
"#include \"AtmosphereShadersCommon.fxh\"\n"
"\n"
"Texture2D<float>  g_tex2DDepthBuffer;\n"
"\n"
"cbuffer cbCameraAttribs\n"
"{\n"
"    CameraAttribs g_CameraAttribs;\n"
"}\n"
"\n"
"float DepthToCameraZ(in float fDepth, in matrix mProj)\n"
"{\n"
"    // Transformations to/from normalized device coordinates are the\n"
"    // same in both APIs.\n"
"    // However, in GL, depth must be transformed to NDC Z first\n"
"\n"
"    float z = DepthToNormalizedDeviceZ(fDepth);\n"
"    return MATRIX_ELEMENT(mProj,3,2) / (z - MATRIX_ELEMENT(mProj,2,2));\n"
"}\n"
"\n"
"void ReconstructCameraSpaceZPS(FullScreenTriangleVSOutput VSOut,\n"
"                               // IMPORTANT: non-system generated pixel shader input\n"
"                               // arguments must have the exact same name as vertex shader \n"
"                               // outputs and must go in the same order.\n"
"                               // Moreover, even if the shader is not using the argument,\n"
"                               // it still must be declared.\n"
"\n"
"                               out float fCamSpaceZ : SV_Target)\n"
"{\n"
"    float fDepth = g_tex2DDepthBuffer.Load( int3(VSOut.f4PixelPos.xy,0) );\n"
"    fCamSpaceZ = DepthToCameraZ(fDepth, g_CameraAttribs.mProj);\n"
"}\n"