aboutsummaryrefslogtreecommitdiffstats
path: root/tests/baseline/data/custommaterial/custom_unshaded_depth_array.frag
blob: ba25ff00332cd4fe704e6e0a4fdabf07168e4c4e (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
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

void MAIN()
{
    // not really using the texture array version, unless multiview rendering is active,
    // nonetheless this test verifies that QSHADER_VIEW_COUNT is defined etc.
#if QSHADER_VIEW_COUNT >= 2
    vec2 uv = (gl_FragCoord.xy) / vec2(textureSize(DEPTH_TEXTURE_ARRAY, 0).xy);
    vec4 depthSample = texture(DEPTH_TEXTURE_ARRAY, vec3(uv, VIEW_INDEX));
#else
    vec2 uv = (gl_FragCoord.xy) / vec2(textureSize(DEPTH_TEXTURE, 0));
    vec4 depthSample = texture(DEPTH_TEXTURE, uv);
#endif

    float zNear = CAMERA_PROPERTIES.x;
    float zFar = CAMERA_PROPERTIES.y;
    float zRange = zFar - zNear;

    float z_n = 2.0 * depthSample.r - 1.0;
    float d = 2.0 * zNear * zFar / (zFar + zNear - z_n * zRange);
    d /= zFar;

    FRAGCOLOR = vec4(d, d, d, 1.0);
}