summaryrefslogtreecommitdiffstats
path: root/Shaders/PostProcess/EpipolarLightScattering/private/ReconstructCameraSpaceZ.fx
blob: d57c66865021ea797f8bc7fd52fff7ea8baf9f15 (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
// Reconstructs camera space z from depth

#include "BasicStructures.fxh"
#include "AtmosphereShadersCommon.fxh"

Texture2D<float>  g_tex2DDepthBuffer;

cbuffer cbCameraAttribs
{
    CameraAttribs g_CameraAttribs;
}

float DepthToCameraZ(in float fDepth, in matrix mProj)
{
    // Transformations to/from normalized device coordinates are the
    // same in both APIs.
    // However, in GL, depth must be transformed to NDC Z first

    float z = DepthToNormalizedDeviceZ(fDepth);
    return MATRIX_ELEMENT(mProj,3,2) / (z - MATRIX_ELEMENT(mProj,2,2));
}

void ReconstructCameraSpaceZPS(FullScreenTriangleVSOutput VSOut,
                               // IMPORTANT: non-system generated pixel shader input
                               // arguments must have the exact same name as vertex shader 
                               // outputs and must go in the same order.
                               // Moreover, even if the shader is not using the argument,
                               // it still must be declared.

                               out float fCamSpaceZ : SV_Target)
{
    float fDepth = g_tex2DDepthBuffer.Load( int3(VSOut.f4PixelPos.xy,0) );
    fCamSpaceZ = DepthToCameraZ(fDepth, g_CameraAttribs.mProj);
}