Max patches for displaying energy distribution of ambisonic signals as point clouds in OpenGL
Marlon Schumacher
07.07.24 8041897857c9e03ecdd647588c060884ec09e019
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<jittershader name="Connect_Close_Vertices">
    <description>Default Connect Close Vertices </description>
 
    <param name="position" type="vec3" state="POSITION" />
    <param name="modelViewProjectionMatrix" type="mat4" state="MODELVIEW_PROJECTION_MATRIX" />
    <param name="color" type="vec4" state="COLOR" />
 
    <param name="posBuffer" type="int" default="0" />
    <param name="distThreshold" type="float" default="0.1" />
 
    <language name="glsl" version="1.5">
 
        <bind param="position" program="vp" />
        <bind param="modelViewProjectionMatrix" program="vp" />
        <bind param="color" program="vp" />
 
        <bind param="posBuffer" program="vp" />
        <bind param="distThreshold" program="vp" />
 
        <program name="vp" type="vertex">
<![CDATA[
#version 330 core
uniform mat4 modelViewProjectionMatrix;
in vec3 position;
in vec4 color;
 
uniform samplerBuffer posBuffer;
uniform float distThreshold;
 
const int arrayLength = 6;
 
out jit_PerVertex {
    flat vec4 color;    
    flat vec4 closeParticlePosition[arrayLength];
} jit_out;
 
void main() {    
    int iterations = 1000;
 
    gl_Position = modelViewProjectionMatrix * vec4(position, 1.);    
    jit_out.color = color;
 
    // initialize close particles position to this particle position
    for (int i=0; i<arrayLength; i++)
    {
        jit_out.closeParticlePosition[i] = modelViewProjectionMatrix * vec4(position, 1.);
    }
 
    int counter = 0; 
    for (int i=gl_VertexID+1; i<iterations; i++)
    {
        vec3 otherPosition = texelFetch(posBuffer, i).xyz;
 
        float dist = length(position - otherPosition);
 
        if (dist < distThreshold && dist > 0.0)
        {
            jit_out.closeParticlePosition[counter] = modelViewProjectionMatrix * vec4(otherPosition, 1.);
            counter++; 
            if (counter >= arrayLength)
            {
                break;
            }
        }
    }
}
]]>
        </program>
        <program name="gp" type="geometry">
<![CDATA[
#version 330 core
 
layout (points) in;
layout (line_strip, max_vertices=12) out;
 
const int arrayLength = 6;
 
in jit_PerVertex {
    flat vec4 color;    
    flat vec4 closeParticlePosition[arrayLength];
} jit_in[];
 
out jit_PerVertex {
    flat vec4 color;    
};
 
void main() {
    for (int i = 0; i<arrayLength; i++)
    {
        gl_Position = gl_in[0].gl_Position;
        color = jit_in[0].color;
        EmitVertex();
 
        gl_Position = jit_in[0].closeParticlePosition[i];
        color = jit_in[0].color;
        EmitVertex();
        
        EndPrimitive();
    }
}
]]>
        </program>
        <program name="fp" type="fragment">
<![CDATA[
#version 330 core
 
in jit_PerVertex {
    flat vec4 color;
} jit_in;
 
out vec4 color;
 
void main() {
    color = jit_in.color;
 
    // if (length(gl_PointCoord-0.5)>0.5)
    // discard;
}    
]]>
        </program>
    </language>
</jittershader>