summaryrefslogtreecommitdiffstats
path: root/src/graphs3d/engine/shaders/texture3d.vert
blob: 7339ecf9f6a82a92995b33d862211545f801967c (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
36
37
38
39
40
41
VARYING vec3 pos;
VARYING vec3 rayDir;

void MAIN() {
    POSITION = MODELVIEWPROJECTION_MATRIX * vec4(VERTEX, 1.0);

    highp vec3 minBoundsNorm = minBounds;
    highp vec3 maxBoundsNorm = maxBounds;

    // Y and Z are flipped in bounds to be directly usable in texture calculations,
    // so flip them back to normal for position calculations
    minBoundsNorm.yz = -minBoundsNorm.yz;
    maxBoundsNorm.yz = -maxBoundsNorm.yz;

    minBoundsNorm = 0.5 * (minBoundsNorm + 1.0);
    maxBoundsNorm = 0.5 * (maxBoundsNorm + 1.0);

    pos = VERTEX
            + ((1.0 - VERTEX) * minBoundsNorm)
            - ((1.0 + VERTEX) * (1.0 - maxBoundsNorm));

    if (useOrtho) {
        vec3 camPos = (inverse(MODELVIEWPROJECTION_MATRIX) * vec4(0.0, 0.0, 1.0, 1.0)).xyz;
        camPos = -(camPos
                    + ((1.0 - camPos) * minBoundsNorm)
                    - ((1.0 + camPos) * (1.0 - maxBoundsNorm)));

        rayDir = -(camPos - pos);
    } else {
        vec3 camPos = (inverse(MODEL_MATRIX) * vec4(CAMERA_POSITION, 1.0)).xyz;
        camPos = camPos
                    + ((1.0 - camPos) * minBoundsNorm)
                    - ((1.0 + camPos) * (1.0 - maxBoundsNorm));

        rayDir = -(camPos - pos);
    }

    // Flip Y and Z so QImage bits work directly for texture and first image is in the front
    rayDir.yz = -rayDir.yz;
    pos.yz = -pos.yz;
}