rendertargetcompositor.frag 4.42 KB
Newer Older
schultezub's avatar
schultezub committed
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
/**********************************************************************
 *                                                                    *
 * Voreen - The Volume Rendering Engine                               *
 *                                                                    *
 * Copyright (C) 2005-2012 Visualization and Computer Graphics Group, *
 * Department of Computer Science, University of Muenster, Germany.   *
 * <http://viscg.uni-muenster.de>                                     *
 *                                                                    *
 * This file is part of the Voreen software package. Voreen is free   *
 * software: you can redistribute it and/or modify it under the terms *
 * of the GNU General Public License version 2 as published by the    *
 * Free Software Foundation.                                          *
 *                                                                    *
 * Voreen is distributed in the hope that it will be useful,          *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
 * GNU General Public License for more details.                       *
 *                                                                    *
 * You should have received a copy of the GNU General Public License  *
 * in the file "LICENSE.txt" along with this program.                 *
 * If not, see <http://www.gnu.org/licenses/>.                        *
 *                                                                    *
 * The authors reserve all rights not expressly granted herein. For   *
 * non-commercial academic use see the license exception specified in *
 * the file "LICENSE-academic.txt". To get information about          *
 * commercial licensing please contact the authors.                   *
 *                                                                    *
 **********************************************************************/

in vec3 ex_TexCoord;
out vec4 out_Color;

#include "tools/texture2d.frag"
#include "tools/background.frag"

36
37
38
39
40
41
42
uniform sampler2D _firstColor;
uniform sampler2D _firstDepth;
uniform TextureParameters2D _firstTexParams;

uniform sampler2D _secondColor;
uniform sampler2D _secondDepth;
uniform TextureParameters2D _secondTexParams;
schultezub's avatar
schultezub committed
43
44
45
46
47
48
49

uniform int _compositingMethod;
uniform float _alpha;

void main() {
    if (_compositingMethod == 0) {
        // only first
50
51
        out_Color = texture(_firstColor, ex_TexCoord.xy);
        gl_FragDepth = texture(_firstDepth, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
52
53
54
    }
    else if (_compositingMethod == 1) {
        // only second
55
56
        out_Color = texture(_secondColor, ex_TexCoord.xy);
        gl_FragDepth = texture(_secondDepth, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
57
58
59
    }
    else if (_compositingMethod == 2) {
        // alpha blending
60
61
62
63
        vec4 firstColor = texture(_firstColor, ex_TexCoord.xy);
        float firstDepth = texture(_firstDepth, ex_TexCoord.xy).r;
        vec4 secondColor = texture(_secondColor, ex_TexCoord.xy);
        float secondDepth = texture(_secondDepth, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
64
65
66
67

        out_Color = mix(firstColor, secondColor, _alpha);
        gl_FragDepth = min(firstDepth, secondDepth);
    }
68
69
    else if (_compositingMethod == 3) {
        // difference
70
71
72
73
        vec4 firstColor = texture(_firstColor, ex_TexCoord.xy);
        float firstDepth = texture(_firstDepth, ex_TexCoord.xy).r;
        vec4 secondColor = texture(_secondColor, ex_TexCoord.xy);
        float secondDepth = texture(_secondDepth, ex_TexCoord.xy).r;
74
75
76
77

        out_Color = vec4(vec3(1.0) - abs(firstColor - secondColor).xyz, max(firstColor.w, secondColor.w));
        gl_FragDepth = min(firstDepth, secondDepth);
    }
schultezub's avatar
schultezub committed
78
79
    else if (_compositingMethod == 4) {
        // depth test
80
81
        float firstDepth = texture(_firstDepth, ex_TexCoord.xy).r;
        float secondDepth = texture(_secondDepth, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
82
83

        if (firstDepth > secondDepth) {
84
            out_Color = texture(_secondColor, ex_TexCoord.xy);
schultezub's avatar
schultezub committed
85
86
87
            gl_FragDepth = secondDepth;
        }
        else {
88
            out_Color = texture(_firstColor, ex_TexCoord.xy);
schultezub's avatar
schultezub committed
89
90
91
            gl_FragDepth = firstDepth;
        }
    }
92
93
94
95
    else {
        // should not occur, but makes the GLSL compiler happy
        out_Color = vec4(0.0);
    }
schultezub's avatar
schultezub committed
96
97
98
99
100
101

    if (out_Color.a == 0) {
        renderBackground(ex_TexCoord.xy, out_Color);
    }
}