aboutsummaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-12-28 23:18:23 +0100
committerAdrian Kummerlaender2019-12-28 23:18:23 +0100
commite399841b70683013ebdc9f6bcb31a871fef33db2 (patch)
tree15e013be6ebc5f28793f5ba1a378fd8f53dfde18 /template
parent342d554e2da1f80aa93d5d28d2d87573db87bbb0 (diff)
downloadsymlbm_playground-e399841b70683013ebdc9f6bcb31a871fef33db2.tar
symlbm_playground-e399841b70683013ebdc9f6bcb31a871fef33db2.tar.gz
symlbm_playground-e399841b70683013ebdc9f6bcb31a871fef33db2.tar.bz2
symlbm_playground-e399841b70683013ebdc9f6bcb31a871fef33db2.tar.lz
symlbm_playground-e399841b70683013ebdc9f6bcb31a871fef33db2.tar.xz
symlbm_playground-e399841b70683013ebdc9f6bcb31a871fef33db2.tar.zst
symlbm_playground-e399841b70683013ebdc9f6bcb31a871fef33db2.zip
Adapt existing channel example to new SDF-based rendering and voxelization
Diffstat (limited to 'template')
-rw-r--r--template/opengl.mako38
-rw-r--r--template/sdf.lib.glsl.mako8
2 files changed, 14 insertions, 32 deletions
diff --git a/template/opengl.mako b/template/opengl.mako
index 181101c..47264e8 100644
--- a/template/opengl.mako
+++ b/template/opengl.mako
@@ -65,7 +65,6 @@ def neighbor_offset(c_i):
%>
__kernel void collect_gl_moments_to_texture(__global ${float_type}* f,
- __global int* material,
% if descriptor.d == 2:
__write_only image2d_t moments)
% elif descriptor.d == 3:
@@ -86,38 +85,17 @@ __kernel void collect_gl_moments_to_texture(__global ${float_type}* f,
float4 data;
- if (material[gid] != 5) {
% if descriptor.d == 2:
- data.x = ${ccode(moments_assignment[0].rhs)};
- data.y = ${ccode(moments_assignment[1].rhs)};
- data.z = ${ccode(moments_assignment[2].rhs)};
- data.w = sqrt(data.y*data.y + data.z*data.z);
+ data.x = ${ccode(moments_assignment[0].rhs)};
+ data.y = ${ccode(moments_assignment[1].rhs)};
+ data.z = ${ccode(moments_assignment[2].rhs)};
+ data.w = sqrt(data.y*data.y + data.z*data.z);
% elif descriptor.d == 3:
- data.x = ${ccode(moments_assignment[0].rhs)};
- data.y = ${ccode(moments_assignment[1].rhs)};
- data.z = ${ccode(moments_assignment[2].rhs)};
- data.w = ${ccode(moments_assignment[3].rhs)};
+ data.x = ${ccode(moments_assignment[0].rhs)};
+ data.y = ${ccode(moments_assignment[1].rhs)};
+ data.z = ${ccode(moments_assignment[2].rhs)};
+ data.w = ${ccode(moments_assignment[3].rhs)};
% endif
- } else {
- const int material_west = material[gid + ${neighbor_offset((-1,0,0))}];
- const int material_east = material[gid + ${neighbor_offset((1,0,0))}];
- const int material_north = material[gid + ${neighbor_offset((0,1,0))}];
- const int material_south = material[gid + ${neighbor_offset((0,-1,0))}];
- const int material_up = material[gid + ${neighbor_offset((0,0, 1))}];
- const int material_down = material[gid + ${neighbor_offset((0,0,-1))}];
-
- // recover surface normal approximation using surrounding materials
- float3 n;
- if (material_west != 5) { n.x = 1; }
- if (material_east != 5) { n.x = -1; }
- if (material_north != 5) { n.y = -1; }
- if (material_south != 5) { n.y = 1; }
- if (material_up != 5) { n.z = -1; }
- if (material_down != 5) { n.z = 1; }
-
- data.xyz = normalize(n);
- data.w = 1.0; // signal impermeable material to raytracer
- }
write_imagef(moments, ${moments_cell()}, data);
}
diff --git a/template/sdf.lib.glsl.mako b/template/sdf.lib.glsl.mako
index 515f959..c58cc7b 100644
--- a/template/sdf.lib.glsl.mako
+++ b/template/sdf.lib.glsl.mako
@@ -12,6 +12,10 @@ float box(vec3 v, vec3 b) {
return length(max(q,0.0)) + min(max(q.x,max(q.y,q.z)),0.0);
}
+float cylinder(vec3 v, float r, float h) {
+ return max(length(v.xy) - r, fabs(v.z) - 0.5*h);
+}
+
vec3 flip_xy(vec3 v) {
return v3(v.y, v.x, v.z);
}
@@ -43,7 +47,7 @@ float rounded(float a, float r) {
return a - r;
}
-float sunify(float a, float b, float k) {
+float sadd(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);
}
@@ -62,7 +66,7 @@ float sub(float a, float b) {
return max(-b, a);
}
-float unify(float a, float b) {
+float add(float a, float b) {
return min(a, b);
}