diff options
Adapt existing channel example to new SDF-based rendering and voxelization
Diffstat (limited to 'template')
-rw-r--r-- | template/opengl.mako | 38 | ||||
-rw-r--r-- | template/sdf.lib.glsl.mako | 8 |
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); } |