Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/bvh/bvh_nodes.h
| Show All 10 Lines | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| // TODO(sergey): Look into avoid use of full Transform and use 3x3 matrix and | // TODO(sergey): Look into avoid use of full Transform and use 3x3 matrix and | ||||
| // 3-vector which might be faster. | // 3-vector which might be faster. | ||||
| ccl_device_forceinline Transform bvh_unaligned_node_fetch_space(ccl_global const KernelGlobals *kg, | ccl_device_forceinline Transform bvh_unaligned_node_fetch_space(KernelGlobals kg, | ||||
| int node_addr, | int node_addr, | ||||
| int child) | int child) | ||||
| { | { | ||||
| Transform space; | Transform space; | ||||
| const int child_addr = node_addr + child * 3; | const int child_addr = node_addr + child * 3; | ||||
| space.x = kernel_tex_fetch(__bvh_nodes, child_addr + 1); | space.x = kernel_tex_fetch(__bvh_nodes, child_addr + 1); | ||||
| space.y = kernel_tex_fetch(__bvh_nodes, child_addr + 2); | space.y = kernel_tex_fetch(__bvh_nodes, child_addr + 2); | ||||
| space.z = kernel_tex_fetch(__bvh_nodes, child_addr + 3); | space.z = kernel_tex_fetch(__bvh_nodes, child_addr + 3); | ||||
| return space; | return space; | ||||
| } | } | ||||
| ccl_device_forceinline int bvh_aligned_node_intersect(ccl_global const KernelGlobals *kg, | ccl_device_forceinline int bvh_aligned_node_intersect(KernelGlobals kg, | ||||
| const float3 P, | const float3 P, | ||||
| const float3 idir, | const float3 idir, | ||||
| const float t, | const float t, | ||||
| const int node_addr, | const int node_addr, | ||||
| const uint visibility, | const uint visibility, | ||||
| float dist[2]) | float dist[2]) | ||||
| { | { | ||||
| Show All 31 Lines | #ifdef __VISIBILITY_FLAG__ | ||||
| /* this visibility test gives a 5% performance hit, how to solve? */ | /* this visibility test gives a 5% performance hit, how to solve? */ | ||||
| return (((c0max >= c0min) && (__float_as_uint(cnodes.x) & visibility)) ? 1 : 0) | | return (((c0max >= c0min) && (__float_as_uint(cnodes.x) & visibility)) ? 1 : 0) | | ||||
| (((c1max >= c1min) && (__float_as_uint(cnodes.y) & visibility)) ? 2 : 0); | (((c1max >= c1min) && (__float_as_uint(cnodes.y) & visibility)) ? 2 : 0); | ||||
| #else | #else | ||||
| return ((c0max >= c0min) ? 1 : 0) | ((c1max >= c1min) ? 2 : 0); | return ((c0max >= c0min) ? 1 : 0) | ((c1max >= c1min) ? 2 : 0); | ||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device_forceinline bool bvh_unaligned_node_intersect_child(ccl_global const KernelGlobals *kg, | ccl_device_forceinline bool bvh_unaligned_node_intersect_child(KernelGlobals kg, | ||||
| const float3 P, | const float3 P, | ||||
| const float3 dir, | const float3 dir, | ||||
| const float t, | const float t, | ||||
| int node_addr, | int node_addr, | ||||
| int child, | int child, | ||||
| float dist[2]) | float dist[2]) | ||||
| { | { | ||||
| Transform space = bvh_unaligned_node_fetch_space(kg, node_addr, child); | Transform space = bvh_unaligned_node_fetch_space(kg, node_addr, child); | ||||
| Show All 9 Lines | ccl_device_forceinline bool bvh_unaligned_node_intersect_child(KernelGlobals kg, | ||||
| const float far_y = max(lower_xyz.y, upper_xyz.y); | const float far_y = max(lower_xyz.y, upper_xyz.y); | ||||
| const float far_z = max(lower_xyz.z, upper_xyz.z); | const float far_z = max(lower_xyz.z, upper_xyz.z); | ||||
| const float tnear = max4(0.0f, near_x, near_y, near_z); | const float tnear = max4(0.0f, near_x, near_y, near_z); | ||||
| const float tfar = min4(t, far_x, far_y, far_z); | const float tfar = min4(t, far_x, far_y, far_z); | ||||
| *dist = tnear; | *dist = tnear; | ||||
| return tnear <= tfar; | return tnear <= tfar; | ||||
| } | } | ||||
| ccl_device_forceinline int bvh_unaligned_node_intersect(ccl_global const KernelGlobals *kg, | ccl_device_forceinline int bvh_unaligned_node_intersect(KernelGlobals kg, | ||||
| const float3 P, | const float3 P, | ||||
| const float3 dir, | const float3 dir, | ||||
| const float3 idir, | const float3 idir, | ||||
| const float t, | const float t, | ||||
| const int node_addr, | const int node_addr, | ||||
| const uint visibility, | const uint visibility, | ||||
| float dist[2]) | float dist[2]) | ||||
| { | { | ||||
| Show All 15 Lines | |||||
| #endif | #endif | ||||
| { | { | ||||
| mask |= 2; | mask |= 2; | ||||
| } | } | ||||
| } | } | ||||
| return mask; | return mask; | ||||
| } | } | ||||
| ccl_device_forceinline int bvh_node_intersect(ccl_global const KernelGlobals *kg, | ccl_device_forceinline int bvh_node_intersect(KernelGlobals kg, | ||||
| const float3 P, | const float3 P, | ||||
| const float3 dir, | const float3 dir, | ||||
| const float3 idir, | const float3 idir, | ||||
| const float t, | const float t, | ||||
| const int node_addr, | const int node_addr, | ||||
| const uint visibility, | const uint visibility, | ||||
| float dist[2]) | float dist[2]) | ||||
| { | { | ||||
| float4 node = kernel_tex_fetch(__bvh_nodes, node_addr); | float4 node = kernel_tex_fetch(__bvh_nodes, node_addr); | ||||
| if (__float_as_uint(node.x) & PATH_RAY_NODE_UNALIGNED) { | if (__float_as_uint(node.x) & PATH_RAY_NODE_UNALIGNED) { | ||||
| return bvh_unaligned_node_intersect(kg, P, dir, idir, t, node_addr, visibility, dist); | return bvh_unaligned_node_intersect(kg, P, dir, idir, t, node_addr, visibility, dist); | ||||
| } | } | ||||
| else { | else { | ||||
| return bvh_aligned_node_intersect(kg, P, idir, t, node_addr, visibility, dist); | return bvh_aligned_node_intersect(kg, P, idir, t, node_addr, visibility, dist); | ||||
| } | } | ||||
| } | } | ||||