Max patches for displaying energy distribution of ambisonic signals as point clouds in OpenGL
Marlon Schumacher
07.07.24 8041897857c9e03ecdd647588c060884ec09e019
commit | author | age
9dafdb 1 <jittershader name="Connect_Close_Vertices">
MS 2     <description>Default Connect Close Vertices </description>
3
4     <param name="position" type="vec3" state="POSITION" />
5     <param name="modelViewProjectionMatrix" type="mat4" state="MODELVIEW_PROJECTION_MATRIX" />
6     <param name="color" type="vec4" state="COLOR" />
7
8     <param name="posBuffer" type="int" default="0" />
9     <param name="distThreshold" type="float" default="0.1" />
10
11     <language name="glsl" version="1.5">
12
13         <bind param="position" program="vp" />
14         <bind param="modelViewProjectionMatrix" program="vp" />
15         <bind param="color" program="vp" />
16
17         <bind param="posBuffer" program="vp" />
18         <bind param="distThreshold" program="vp" />
19
20         <program name="vp" type="vertex">
21 <![CDATA[
22 #version 330 core
23 uniform mat4 modelViewProjectionMatrix;
24 in vec3 position;
25 in vec4 color;
26
27 uniform samplerBuffer posBuffer;
28 uniform float distThreshold;
29
30 const int arrayLength = 6;
31
32 out jit_PerVertex {
33     flat vec4 color;    
34     flat vec4 closeParticlePosition[arrayLength];
35 } jit_out;
36
37 void main() {    
38     int iterations = 1000;
39
40     gl_Position = modelViewProjectionMatrix * vec4(position, 1.);    
41     jit_out.color = color;
42
43     // initialize close particles position to this particle position
44     for (int i=0; i<arrayLength; i++)
45     {
46         jit_out.closeParticlePosition[i] = modelViewProjectionMatrix * vec4(position, 1.);
47     }
48
49     int counter = 0; 
50     for (int i=gl_VertexID+1; i<iterations; i++)
51     {
52         vec3 otherPosition = texelFetch(posBuffer, i).xyz;
53
54         float dist = length(position - otherPosition);
55
56         if (dist < distThreshold && dist > 0.0)
57         {
58             jit_out.closeParticlePosition[counter] = modelViewProjectionMatrix * vec4(otherPosition, 1.);
59             counter++; 
60             if (counter >= arrayLength)
61             {
62                 break;
63             }
64         }
65     }
66 }
67 ]]>
68         </program>
69         <program name="gp" type="geometry">
70 <![CDATA[
71 #version 330 core
72
73 layout (points) in;
74 layout (line_strip, max_vertices=12) out;
75
76 const int arrayLength = 6;
77
78 in jit_PerVertex {
79     flat vec4 color;    
80     flat vec4 closeParticlePosition[arrayLength];
81 } jit_in[];
82
83 out jit_PerVertex {
84     flat vec4 color;    
85 };
86
87 void main() {
88     for (int i = 0; i<arrayLength; i++)
89     {
90         gl_Position = gl_in[0].gl_Position;
91         color = jit_in[0].color;
92         EmitVertex();
93
94         gl_Position = jit_in[0].closeParticlePosition[i];
95         color = jit_in[0].color;
96         EmitVertex();
97         
98         EndPrimitive();
99     }
100 }
101 ]]>
102         </program>
103         <program name="fp" type="fragment">
104 <![CDATA[
105 #version 330 core
106
107 in jit_PerVertex {
108     flat vec4 color;
109 } jit_in;
110
111 out vec4 color;
112
113 void main() {
114     color = jit_in.color;
115
116     // if (length(gl_PointCoord-0.5)>0.5)
117     // discard;
118 }    
119 ]]>
120         </program>
121     </language>
122 </jittershader>