aboutsummaryrefslogtreecommitdiff
path: root/template/streamline.mako
blob: adf5efd475881fc65efd2db5b1ae3893e792f109 (plain)
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
<%
def gid():
    return {
        2: 'get_global_id(1)*%d + get_global_id(0)' % memory.size_x,
        3: 'get_global_id(2)*%d + get_global_id(1)*%d + get_global_id(0)' % (memory.size_x*memory.size_y, memory.size_x)
    }.get(descriptor.d)
%>

__kernel void dillute(__global int* material,
                      __read_write image2d_t streamlines)
{
    const unsigned int gid = ${gid()};
    const int2 pos = (int2)(get_global_id(0), get_global_id(1));

    float4 color = read_imagef(streamlines, pos);

    if (material[gid] == 1) {
        color.xyz *= 0.975;
    } else {
        color.xyz = 0.2;
    }

    write_imagef(streamlines, pos, color);
}

float3 blueRedPalette(float x) {
    return mix(
        (float3)(0.0, 0.0, 1.0),
        (float3)(1.0, 0.0, 0.0),
        x
    );
}

__kernel void draw_streamline(__global float*  moments,
                              __global int*    material,
                              __global float2* origins,
                              __read_write image2d_t streamlines)
{
    float2 particle = origins[get_global_id(0)];

    for (int i = 0; i < ${2*memory.size_x}; ++i) {
    const unsigned int gid = round(particle.y)*${memory.size_x} + round(particle.x);
        if (material[gid] != 1) {
            break;
        }

        particle.x += 0.5 * moments[${1*memory.volume}+gid] / 0.01;
        particle.y += 0.5 * moments[${2*memory.volume}+gid] / 0.01;

        const int2 pos = (int2)(round(particle.x), round(particle.y));

        float4 color = read_imagef(streamlines, pos);
        color.xyz += 0.05;

        write_imagef(streamlines, pos, color);
    }
}