rendertargetcompositor.frag 4.92 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
        out_Color = getElement2DNormalized(_firstColor, _firstTexParams, ex_TexCoord.xy);
51
        gl_FragDepth = getElement2DNormalized(_firstDepth, _firstTexParams, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
52 53 54
    }
    else if (_compositingMethod == 1) {
        // only second
55
        out_Color = getElement2DNormalized(_secondColor, _secondTexParams, ex_TexCoord.xy);
56
        gl_FragDepth = getElement2DNormalized(_secondDepth, _secondTexParams, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
57 58 59
    }
    else if (_compositingMethod == 2) {
        // alpha blending
60
        vec4 firstColor = getElement2DNormalized(_firstColor, _firstTexParams, ex_TexCoord.xy);
61
        float firstDepth = getElement2DNormalized(_firstDepth, _firstTexParams, ex_TexCoord.xy).r;
62
        vec4 secondColor = getElement2DNormalized(_secondColor, _secondTexParams, ex_TexCoord.xy);
63
        float secondDepth = getElement2DNormalized(_secondDepth, _secondTexParams, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
64 65 66 67

        out_Color = mix(firstColor, secondColor, _alpha);
        gl_FragDepth = min(firstDepth, secondDepth);
    }
schultezub's avatar
schultezub committed
68 69
    else if (_compositingMethod == 3) {
        // difference
70
        vec4 firstColor = getElement2DNormalized(_firstColor, _firstTexParams, ex_TexCoord.xy);
71
        float firstDepth = getElement2DNormalized(_firstDepth, _firstTexParams, ex_TexCoord.xy).r;
72
        vec4 secondColor = getElement2DNormalized(_secondColor, _secondTexParams, ex_TexCoord.xy);
73
        float secondDepth = getElement2DNormalized(_secondDepth, _secondTexParams, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
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 = getElement2DNormalized(_firstDepth, _firstTexParams, ex_TexCoord.xy).r;
        float secondDepth = getElement2DNormalized(_secondDepth, _secondTexParams, ex_TexCoord.xy).r;
schultezub's avatar
schultezub committed
82 83

        if (firstDepth > secondDepth) {
84
            out_Color = getElement2DNormalized(_secondColor, _secondTexParams, ex_TexCoord.xy);
schultezub's avatar
schultezub committed
85 86 87
            gl_FragDepth = secondDepth;
        }
        else {
88
            out_Color = getElement2DNormalized(_firstColor, _firstTexParams, ex_TexCoord.xy);
schultezub's avatar
schultezub committed
89 90 91
            gl_FragDepth = firstDepth;
        }
    }
schultezub's avatar
schultezub committed
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);
    }
}