"// ReconstructCameraSpaceZ.fx\n" "// Reconstructs camera space z from depth\n" "\n" "#include \"BasicStructures.fxh\"\n" "#include \"AtmosphereShadersCommon.fxh\"\n" "\n" "Texture2D 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"