diff options
Diffstat (limited to 'intern/cycles/kernel/bvh/shadow_all.h')
-rw-r--r-- | intern/cycles/kernel/bvh/shadow_all.h | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/intern/cycles/kernel/bvh/shadow_all.h b/intern/cycles/kernel/bvh/shadow_all.h index 2f58929c1e5..db3c91569aa 100644 --- a/intern/cycles/kernel/bvh/shadow_all.h +++ b/intern/cycles/kernel/bvh/shadow_all.h @@ -49,6 +49,7 @@ ccl_device_inline float3 P = ray->P; float3 dir = bvh_clamp_direction(ray->D); float3 idir = bvh_inverse_direction(dir); + float tmin = ray->tmin; int object = OBJECT_NONE; uint num_hits = 0; @@ -59,12 +60,12 @@ ccl_device_inline /* Max distance in world space. May be dynamically reduced when max number of * recorded hits is exceeded and we no longer need to find hits beyond the max * distance found. */ - float t_max_world = ray->t; + float t_max_world = ray->tmax; /* Current maximum distance to the intersection. * Is calculated as a ray length, transformed to an object space when entering * instance node. */ - float t_max_current = ray->t; + float t_max_current = ray->tmax; /* Conversion from world to local space for the current instance if any, 1.0 * otherwise. */ @@ -80,7 +81,7 @@ ccl_device_inline while (node_addr >= 0 && node_addr != ENTRYPOINT_SENTINEL) { int node_addr_child1, traverse_mask; float dist[2]; - float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr + 0); + float4 cnodes = kernel_data_fetch(bvh_nodes, node_addr + 0); traverse_mask = NODE_INTERSECT(kg, P, @@ -88,6 +89,7 @@ ccl_device_inline dir, #endif idir, + tmin, t_max_current, node_addr, visibility, @@ -124,7 +126,7 @@ ccl_device_inline /* if node is leaf, fetch triangle list */ if (node_addr < 0) { - float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1)); + float4 leaf = kernel_data_fetch(bvh_leaf_nodes, (-node_addr - 1)); int prim_addr = __float_as_int(leaf.x); if (prim_addr >= 0) { @@ -137,7 +139,7 @@ ccl_device_inline /* primitive intersection */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert((kernel_tex_fetch(__prim_type, prim_addr) & PRIMITIVE_ALL) == + kernel_assert((kernel_data_fetch(prim_type, prim_addr) & PRIMITIVE_ALL) == (type & PRIMITIVE_ALL)); bool hit; @@ -147,17 +149,25 @@ ccl_device_inline Intersection isect ccl_optional_struct_init; const int prim_object = (object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, prim_addr) : + kernel_data_fetch(prim_object, prim_addr) : object; - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self_shadow(ray->self, prim_object, prim)) { continue; } switch (type & PRIMITIVE_ALL) { case PRIMITIVE_TRIANGLE: { - hit = triangle_intersect( - kg, &isect, P, dir, t_max_current, visibility, prim_object, prim, prim_addr); + hit = triangle_intersect(kg, + &isect, + P, + dir, + tmin, + t_max_current, + visibility, + prim_object, + prim, + prim_addr); break; } #if BVH_FEATURE(BVH_MOTION) @@ -166,6 +176,7 @@ ccl_device_inline &isect, P, dir, + tmin, t_max_current, ray->time, visibility, @@ -181,16 +192,24 @@ ccl_device_inline case PRIMITIVE_CURVE_RIBBON: case PRIMITIVE_MOTION_CURVE_RIBBON: { if ((type & PRIMITIVE_MOTION) && kernel_data.bvh.use_bvh_steps) { - const float2 prim_time = kernel_tex_fetch(__prim_time, prim_addr); + const float2 prim_time = kernel_data_fetch(prim_time, prim_addr); if (ray->time < prim_time.x || ray->time > prim_time.y) { hit = false; break; } } - const int curve_type = kernel_tex_fetch(__prim_type, prim_addr); - hit = curve_intersect( - kg, &isect, P, dir, t_max_current, prim_object, prim, ray->time, curve_type); + const int curve_type = kernel_data_fetch(prim_type, prim_addr); + hit = curve_intersect(kg, + &isect, + P, + dir, + tmin, + t_max_current, + prim_object, + prim, + ray->time, + curve_type); break; } @@ -199,16 +218,24 @@ ccl_device_inline case PRIMITIVE_POINT: case PRIMITIVE_MOTION_POINT: { if ((type & PRIMITIVE_MOTION) && kernel_data.bvh.use_bvh_steps) { - const float2 prim_time = kernel_tex_fetch(__prim_time, prim_addr); + const float2 prim_time = kernel_data_fetch(prim_time, prim_addr); if (ray->time < prim_time.x || ray->time > prim_time.y) { hit = false; break; } } - const int point_type = kernel_tex_fetch(__prim_type, prim_addr); - hit = point_intersect( - kg, &isect, P, dir, t_max_current, prim_object, prim, ray->time, point_type); + const int point_type = kernel_data_fetch(prim_type, prim_addr); + hit = point_intersect(kg, + &isect, + P, + dir, + tmin, + t_max_current, + prim_object, + prim, + ray->time, + point_type); break; } #endif /* BVH_FEATURE(BVH_POINTCLOUD) */ @@ -291,7 +318,7 @@ ccl_device_inline } else { /* instance push */ - object = kernel_tex_fetch(__prim_object, -prim_addr - 1); + object = kernel_data_fetch(prim_object, -prim_addr - 1); #if BVH_FEATURE(BVH_MOTION) t_world_to_instance = bvh_instance_motion_push( @@ -302,12 +329,13 @@ ccl_device_inline /* Convert intersection to object space. */ t_max_current *= t_world_to_instance; + tmin *= t_world_to_instance; ++stack_ptr; kernel_assert(stack_ptr < BVH_STACK_SIZE); traversal_stack[stack_ptr] = ENTRYPOINT_SENTINEL; - node_addr = kernel_tex_fetch(__object_node, object); + node_addr = kernel_data_fetch(object_node, object); } } } while (node_addr != ENTRYPOINT_SENTINEL); @@ -323,7 +351,8 @@ ccl_device_inline #endif /* Restore world space ray length. */ - t_max_current = ray->t; + tmin = ray->tmin; + t_max_current = ray->tmax; object = OBJECT_NONE; t_world_to_instance = 1.0f; |