source: orange/orange/OrangeWidgets/plot/generator.gs @ 8786:5625ec1ac9e6

Revision 8786:5625ec1ac9e6, 3.0 KB checked in by matejd <matejd@…>, 3 years ago (diff)

Python part of the implementation mentioned below

Line 
1#version 150
2
3layout(points) in;
4layout(triangle_strip, max_vertices=144) out;
5
6uniform int x_index;
7uniform int y_index;
8uniform int z_index;
9uniform int color_index;
10uniform int symbol_index;
11uniform int size_index;
12
13uniform bool use_2d_symbols;
14
15uniform float jitter_size;
16uniform bool jitter_continuous;
17uniform bool x_discrete;
18uniform bool y_discrete;
19uniform bool z_discrete;
20
21uniform samplerBuffer symbol_buffer;
22uniform samplerBuffer data_buffer;
23
24uniform int num_symbols_used;
25uniform int[20] symbols_indices;
26uniform int[20] symbols_sizes;
27uniform int example_size;
28
29// Colors are specified in case of a discrete attribute.
30uniform int num_colors;
31uniform vec3[50] colors;
32
33out vec3 out_position;
34out vec3 out_offset;
35out vec3 out_color;
36out vec3 out_normal;
37out float out_index;
38
39// http://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl
40// Should return pseudo-random value [-0.5, 0.5]
41float rand(vec3 co){
42    return fract(sin(dot(co.xyz, vec3(12.9898, 78.233, 42.42))) * 43758.5453) - 0.5;
43}
44
45void main()
46{
47    vec4 position = gl_in[0].gl_Position;
48    const float scale = 0.001;
49
50    out_index = position.x;
51    int index = int(out_index * example_size);
52
53    out_position = vec3(texelFetch(data_buffer, index+x_index).x,
54                        texelFetch(data_buffer, index+y_index).x,
55                        texelFetch(data_buffer, index+z_index).x);
56
57    if (x_discrete || jitter_continuous)
58        out_position.x += rand(out_position * out_index) * jitter_size / 100.;
59    if (y_discrete || jitter_continuous)
60        out_position.y += rand(out_position * out_index) * jitter_size / 100.;
61    if (z_discrete || jitter_continuous)
62        out_position.z += rand(out_position * out_index) * jitter_size / 100.;
63
64    int symbol = 0;
65    if (num_symbols_used > 1 && symbol_index > -1)
66        symbol = clamp(int(texelFetch(data_buffer, index+symbol_index).x * num_symbols_used), 0, 9);
67    if (!use_2d_symbols)
68        symbol += 10;
69
70    float size = texelFetch(data_buffer, index+size_index).x;
71    if (size_index < 0 || size < 0.)
72        size = 1.;
73
74    float color = texelFetch(data_buffer, index+color_index).x;
75    if (num_colors > 0)
76        out_color = colors[int(color*num_colors)];
77    else if (color_index > -1)
78        out_color = vec3(0., 0., color);
79    else
80        out_color = vec3(0., 0., 0.8);
81
82    for (int i = 0; i < symbols_sizes[symbol]; ++i)
83    {
84        out_offset = texelFetch(symbol_buffer, symbols_indices[symbol]+i*6+0).xyz * size * scale;
85        out_normal = texelFetch(symbol_buffer, symbols_indices[symbol]+i*6+3).xyz;
86        EmitVertex();
87        out_offset = texelFetch(symbol_buffer, symbols_indices[symbol]+i*6+1).xyz * size * scale;
88        out_normal = texelFetch(symbol_buffer, symbols_indices[symbol]+i*6+4).xyz;
89        EmitVertex();
90        out_offset = texelFetch(symbol_buffer, symbols_indices[symbol]+i*6+2).xyz * size * scale;
91        out_normal = texelFetch(symbol_buffer, symbols_indices[symbol]+i*6+5).xyz;
92        EmitVertex();
93
94        EndPrimitive();
95    }
96}
Note: See TracBrowser for help on using the repository browser.