rendertargetcompositor.frag 4.57 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
/**********************************************************************
 *                                                                    *
 * 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.                   *
 *                                                                    *
 **********************************************************************/
 
#version 330

in vec3 ex_TexCoord;
out vec4 out_Color;

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

uniform Texture2D _firstColor;
uniform Texture2D _firstDepth;
uniform Texture2D _secondColor;
uniform Texture2D _secondDepth;

uniform int _compositingMethod;
uniform float _alpha;

void main() {
    if (_compositingMethod == 0) {
        // only first
        out_Color = getElement2DNormalized(_firstColor, ex_TexCoord.xy);
        gl_FragDepth = getElement2DNormalized(_firstDepth, ex_TexCoord.xy).z;
    }
    else if (_compositingMethod == 1) {
        // only second
        out_Color = getElement2DNormalized(_secondColor, ex_TexCoord.xy);
        gl_FragDepth = getElement2DNormalized(_secondDepth, ex_TexCoord.xy).z;
    }
    else if (_compositingMethod == 2) {
        // alpha blending
        vec4 firstColor = getElement2DNormalized(_firstColor, ex_TexCoord.xy);
        float firstDepth = getElement2DNormalized(_firstDepth, ex_TexCoord.xy).z;
        vec4 secondColor = getElement2DNormalized(_secondColor, ex_TexCoord.xy);
        float secondDepth = getElement2DNormalized(_secondDepth, ex_TexCoord.xy).z;

        out_Color = mix(firstColor, secondColor, _alpha);
        gl_FragDepth = min(firstDepth, secondDepth);
    }
schultezub's avatar
schultezub committed
67 68 69 70 71 72 73 74 75 76
    else if (_compositingMethod == 3) {
        // difference
        vec4 firstColor = getElement2DNormalized(_firstColor, ex_TexCoord.xy);
        float firstDepth = getElement2DNormalized(_firstDepth, ex_TexCoord.xy).z;
        vec4 secondColor = getElement2DNormalized(_secondColor, ex_TexCoord.xy);
        float secondDepth = getElement2DNormalized(_secondDepth, ex_TexCoord.xy).z;

        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
77 78 79 80 81 82 83 84 85 86 87 88 89 90
    else if (_compositingMethod == 4) {
        // depth test
        float firstDepth = getElement2DNormalized(_firstDepth, ex_TexCoord.xy).z;
        float secondDepth = getElement2DNormalized(_secondDepth, ex_TexCoord.xy).z;

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

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