aboutsummaryrefslogtreecommitdiff
path: root/template/streamline.mako
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-10-08 20:17:46 +0200
committerAdrian Kummerlaender2019-10-08 20:17:46 +0200
commit7a79d49dd27b3ec923cc70daadeae6f0e48a7590 (patch)
tree6533c504db31097f039e6ef3a28009397f186f2c /template/streamline.mako
parent02c245236aef90552601e82197f0738fa34d9e89 (diff)
downloadsymlbm_playground-7a79d49dd27b3ec923cc70daadeae6f0e48a7590.tar
symlbm_playground-7a79d49dd27b3ec923cc70daadeae6f0e48a7590.tar.gz
symlbm_playground-7a79d49dd27b3ec923cc70daadeae6f0e48a7590.tar.bz2
symlbm_playground-7a79d49dd27b3ec923cc70daadeae6f0e48a7590.tar.lz
symlbm_playground-7a79d49dd27b3ec923cc70daadeae6f0e48a7590.tar.xz
symlbm_playground-7a79d49dd27b3ec923cc70daadeae6f0e48a7590.tar.zst
symlbm_playground-7a79d49dd27b3ec923cc70daadeae6f0e48a7590.zip
Play around with 2d streamlines
Diffstat (limited to 'template/streamline.mako')
-rw-r--r--template/streamline.mako59
1 files changed, 59 insertions, 0 deletions
diff --git a/template/streamline.mako b/template/streamline.mako
new file mode 100644
index 0000000..73c80e2
--- /dev/null
+++ b/template/streamline.mako
@@ -0,0 +1,59 @@
+<%
+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 float4* 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);
+ const float4 moment = moments[gid];
+
+ if (material[gid] != 1) {
+ break;
+ }
+
+ particle.x += 0.5 * moment.y / 0.01;
+ particle.y += 0.5 * moment.z / 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);
+ }
+}