particleflowrenderer.vert 3.84 KB
Newer Older
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
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================

#include "tools/texture3d.frag"

subroutine void RenderPassType();
subroutine uniform RenderPassType RenderPass;

layout(location = 0) in vec3 in_Position;
layout(location = 1) in vec3 in_Velocity;
layout(location = 2) in float in_StartTime;
layout(location = 3) in vec3 in_InitialPosition;

out vec3 ex_Position;
out vec3 ex_Velocity;
out float ex_StartTime;

out float ex_Transparency;

/// Matrix defining model-to-world transformation
uniform mat4 _modelMatrix = mat4(
    1.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0);

/// Matrix defining view transformation
uniform mat4 _viewMatrix = mat4(
    1.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0);

/// Matrix defining projection transformation
uniform mat4 _projectionMatrix = mat4(
    1.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0);


uniform float _time;
uniform float _frameLength;
uniform float _lifetime;
66
uniform float _scale;
67
uniform vec2 _threshold;
68
69
70
71
72
73
74
75

uniform sampler3D _volume;
uniform TextureParameters3D _volumeTextureParams;


subroutine (RenderPassType)
void update() {
    if (_time > in_StartTime) {
76
        float age = _time - in_StartTime;
77
        if (age > _lifetime || length(in_Velocity) < _threshold.x || length(in_Velocity) > _threshold.y) {
78
79
            // particle expired, recycle
            ex_Position = in_InitialPosition;
80
            ex_Velocity = texture(_volume, (ex_Position / _volumeTextureParams._size).xyz).xyz;
81
82
83
84
            ex_StartTime = _time;
        }
        else {
            // particle alive, advance
85
            ex_Position = in_Position + (in_Velocity * _frameLength * 0.05 * _scale);
86
87

            // compute new velocity by mixture of old velocity and flow at current location, model some inertia
88
            vec3 v = texture(_volume, (ex_Position / _volumeTextureParams._size).xyz).xyz;
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
            ex_Velocity = mix(in_Velocity, v, 0.5);//smoothstep(0.5, 2.0, v/in_Velocity));
            ex_StartTime = in_StartTime;
        }
    }
    else {
        ex_Position = in_Position;
        ex_Velocity = in_Velocity;
        ex_StartTime = in_StartTime;
    }
}


subroutine (RenderPassType)
void render() {
    float age = _time - in_StartTime;
104
    ex_Transparency = (age >= 0.0) ? 1.0 - (age / _lifetime) : 0.0;
105
106
107
108
109
110
111
112
113
114
115
116
117

    gl_Position = _projectionMatrix * (_viewMatrix * (_modelMatrix * vec4(in_Position, 1.0)));
    //ex_Position = in_Position;
    mat4 normalMatrix = transpose(inverse(_modelMatrix));

    //vec4 normalTmp = (normalMatrix * vec4(in_Normal, 0.0));
    // ex_Normal = normalize((normalTmp).xyz);
}

void main() {
    // call the current subroutine
    RenderPass();
}