diff options
author | Stan Seibert <stan@mtrr.org> | 2012-01-30 17:00:06 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:38 -0700 |
commit | 9562e103e310d7861676d88a711a51ebce5fb4ea (patch) | |
tree | 5037bd2d2f17f77997de1c5c3174383d4d0f9bf5 | |
parent | f6fa4739cc476b21b755522e252ebfbb81c6fd13 (diff) | |
download | chroma-9562e103e310d7861676d88a711a51ebce5fb4ea.tar.gz chroma-9562e103e310d7861676d88a711a51ebce5fb4ea.tar.bz2 chroma-9562e103e310d7861676d88a711a51ebce5fb4ea.zip |
Fix the rendering code to use the new geometry and BVH definition.
-rw-r--r-- | chroma/cuda/render.cu | 127 |
1 files changed, 66 insertions, 61 deletions
diff --git a/chroma/cuda/render.cu b/chroma/cuda/render.cu index d4ed443..bbb7383 100644 --- a/chroma/cuda/render.cu +++ b/chroma/cuda/render.cu @@ -59,82 +59,86 @@ render(int nthreads, float3 *_origin, float3 *_direction, Geometry *g, float distance; - if (n < 1 && !intersect_node(origin, direction, g, g->start_node)) { + Node root = get_node(g, 0); + + float3 neg_origin_inv_dir = -origin / direction; + float3 inv_dir = 1.0f / direction; + + if (n < 1 && !intersect_node(neg_origin_inv_dir, inv_dir, g, root)) { pixels[id] = 0; return; } - unsigned int stack[STACK_SIZE]; + unsigned int child_ptr_stack[STACK_SIZE]; + child_ptr_stack[0] = root.child; - unsigned int *head = &stack[0]; - unsigned int *node = &stack[1]; - unsigned int *tail = &stack[STACK_SIZE-1]; - *node = g->start_node; + int curr = 0; + + unsigned int count = 0; + unsigned int tri_count = 0; float *dx = _dx + id*alpha_depth; float4 *color_a = _color + id*alpha_depth; - unsigned int i; + while (curr >= 0) { + unsigned int first_child = child_ptr_stack[curr]; + curr--; - do { - unsigned int first_child = g->node_map[*node]; - unsigned int stop = g->node_map_end[*node]; - - while (*node >= g->first_node && stop == first_child+1) { - *node = first_child; - first_child = g->node_map[*node]; - stop = g->node_map_end[*node]; - } - - if (*node >= g->first_node) { - for (i=first_child; i < stop; i++) { - if (intersect_node(origin, direction, g, i)) { - *node = i; - node++; - } - } - - node--; - } - else { - // node is a leaf - for (i=first_child; i < stop; i++) { - Triangle t = get_triangle(g, i); - - if (intersect_triangle(origin, direction, t, distance)) { - if (n < 1) { - dx[0] = distance; - - unsigned int rgba = g->colors[i]; - float4 color = get_color(direction, t, rgba); + for (unsigned int i=first_child; i < first_child + g->branch_degree; i++) { + Node node = get_node(g, i); + count++; - color_a[0] = color; - } - else { - unsigned long j = searchsorted(n, dx, distance); + if (node.kind == PADDING_NODE) + break; // this node and rest of children are padding - if (j <= alpha_depth-1) { - insert(alpha_depth, dx, j, distance); + if (intersect_node(neg_origin_inv_dir, inv_dir, g, node)) { - unsigned int rgba = g->colors[i]; - float4 color = get_color(direction, t, rgba); + if (node.kind == LEAF_NODE) { - insert(alpha_depth, color_a, j, color); - } + // This node wraps a triangle + tri_count++; + Triangle t = get_triangle(g, node.child); + if (intersect_triangle(origin, direction, t, distance)) { + if (n < 1) { + dx[0] = distance; + + unsigned int rgba = g->colors[node.child]; + float4 color = get_color(direction, t, rgba); + + color_a[0] = color; + } + else { + unsigned long j = searchsorted(n, dx, distance); + + if (j <= alpha_depth-1) { + insert(alpha_depth, dx, j, distance); + + unsigned int rgba = g->colors[node.child]; + float4 color = get_color(direction, t, rgba); + + insert(alpha_depth, color_a, j, color); } - - if (n < alpha_depth) - n++; - } - - } // triangle loop - - node--; + } + + if (n < alpha_depth) + n++; + + } // if hit triangle + + } else { + curr++; + child_ptr_stack[curr] = node.child; + } // leaf or internal node? + } // hit node? - } // node is a leaf + //if (curr >= STACK_SIZE) { + // printf("warning: intersect_mesh() aborted; node > tail\n"); + // break; + //} + } // loop over children, starting with first_child - } // while loop - while (node != head); + } // while nodes on stack + if (n < 1) { pixels[id] = 0; @@ -147,9 +151,9 @@ render(int nthreads, float3 *_origin, float3 *_direction, Geometry *g, float fr = 0.0f; float fg = 0.0f; float fb = 0.0f; - for (i=0; i < n; i++) { + for (int i=0; i < n; i++) { float alpha = color_a[i].w; - + fr += scale*color_a[i].x*alpha; fg += scale*color_a[i].y*alpha; fb += scale*color_a[i].z*alpha; @@ -161,6 +165,7 @@ render(int nthreads, float3 *_origin, float3 *_direction, Geometry *g, a = floorf(255*(1.0f-scale)); else a = 255; + unsigned int red = floorf(fr/(1.0f-scale)); unsigned int green = floorf(fg/(1.0f-scale)); unsigned int blue = floorf(fb/(1.0f-scale)); |