aboutsummaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
Diffstat (limited to 'template')
-rw-r--r--template/sdf.cl.mako56
-rw-r--r--template/sdf.lib.glsl.mako71
2 files changed, 127 insertions, 0 deletions
diff --git a/template/sdf.cl.mako b/template/sdf.cl.mako
new file mode 100644
index 0000000..b98b35f
--- /dev/null
+++ b/template/sdf.cl.mako
@@ -0,0 +1,56 @@
+typedef float3 vec3;
+typedef float2 vec2;
+
+float3 v3(float x, float y, float z) {
+ return (float3)(x,y,z);
+}
+
+float2 v2(float x, float y) {
+ return (float2)(x,y);
+}
+
+__constant float3 center = (float3)(${geometry.size_x/2.5}, ${geometry.size_y/2}, ${geometry.size_z/2});
+
+<%include file="sdf.lib.glsl.mako"/>
+
+float sdf(vec3 v) {
+ ${sdf_src}
+}
+
+__kernel void setup_channel_with_sdf_obstacle(__global int* material) {
+ const unsigned x = get_global_id(0);
+ const unsigned y = get_global_id(1);
+ const unsigned z = get_global_id(2);
+
+ const unsigned gid = z*${geometry.size_x*geometry.size_y} + y*${geometry.size_x} + x;
+
+ if (x == 0 || x == ${geometry.size_x-1} ||
+ y == 0 || y == ${geometry.size_y-1} ||
+ z == 0 || z == ${geometry.size_z-1}) {
+ material[gid] = 0;
+ return;
+ }
+
+ if (x == 1) {
+ material[gid] = 3;
+ return;
+ }
+
+ if (x == ${geometry.size_x-2}) {
+ material[gid] = 4;
+ return;
+ }
+
+ if (y == 1 || y == ${geometry.size_y-2} ||
+ z == 1 || z == ${geometry.size_z-2}) {
+ material[gid] = 2;
+ return;
+ }
+
+ if (sdf((float3)(x,y,z)) < 0.0) {
+ material[gid] = 2;
+ return;
+ }
+
+ material[gid] = 1;
+}
diff --git a/template/sdf.lib.glsl.mako b/template/sdf.lib.glsl.mako
new file mode 100644
index 0000000..515f959
--- /dev/null
+++ b/template/sdf.lib.glsl.mako
@@ -0,0 +1,71 @@
+float sphere(vec3 v, float r) {
+ return length(v) - r;
+}
+
+float torus(vec3 v, vec2 t) {
+ vec2 q = v2(length(v.xz)-t.x,v.y);
+ return length(q)-t.y;
+}
+
+float box(vec3 v, vec3 b) {
+ vec3 q = fabs(v) - b;
+ return length(max(q,0.0)) + min(max(q.x,max(q.y,q.z)),0.0);
+}
+
+vec3 flip_xy(vec3 v) {
+ return v3(v.y, v.x, v.z);
+}
+
+vec3 flip_yz(vec3 v) {
+ return v3(v.x, v.z, v.y);
+}
+
+vec3 rotate_x(vec3 v, float r) {
+ v.yz = cos(r)*v.yz + sin(r)*v2(v.z, -v.y);
+ return v;
+}
+
+vec3 rotate_y(vec3 v, float r) {
+ v.xz = cos(r)*v.xz + sin(r)*v2(v.z, -v.x);
+ return v;
+}
+
+vec3 rotate_z(vec3 v, float r) {
+ v.xy = cos(r)*v.xy + sin(r)*v2(v.y, -v.x);
+ return v;
+}
+
+vec3 translate(vec3 v, vec3 w) {
+ return v - w;
+}
+
+float rounded(float a, float r) {
+ return a - r;
+}
+
+float sunify(float a, float b, float k) {
+ float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
+ return mix(b, a, h) - k * h * (1 - h);
+}
+
+float ssub(float b, float a, float k) {
+ float h = clamp(0.5 - 0.5*(b+a)/k, 0.0, 1.0);
+ return mix(b, -a, h) + k*h*(1.0-h);
+}
+
+float sintersect(float a, float b, float k) {
+ float h = clamp(0.5 - 0.5*(b-a)/k, 0.0, 1.0);
+ return mix(b, a, h) + k*h*(1.0-h);
+}
+
+float sub(float a, float b) {
+ return max(-b, a);
+}
+
+float unify(float a, float b) {
+ return min(a, b);
+}
+
+float intersect(float a, float b) {
+ return max(a, b);
+}