Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/bvh/bvh_util.h
| Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | #ifdef __INTERSECTION_REFINE__ | ||||
| return res; | return res; | ||||
| #else | #else | ||||
| const float epsilon_f = 1e-4f; | const float epsilon_f = 1e-4f; | ||||
| return P + epsilon_f * Ng; | return P + epsilon_f * Ng; | ||||
| #endif | #endif | ||||
| } | } | ||||
| #if defined(__VOLUME_RECORD_ALL__) || (defined(__SHADOW_RECORD_ALL__) && defined(__KERNEL_CPU__)) | #if defined(__KERNEL_CPU__) | ||||
| /* TODO: Move to another file? */ | |||||
| ccl_device int intersections_compare(const void *a, const void *b) | ccl_device int intersections_compare(const void *a, const void *b) | ||||
| { | { | ||||
| const Intersection *isect_a = (const Intersection *)a; | const Intersection *isect_a = (const Intersection *)a; | ||||
| const Intersection *isect_b = (const Intersection *)b; | const Intersection *isect_b = (const Intersection *)b; | ||||
| if (isect_a->t < isect_b->t) | if (isect_a->t < isect_b->t) | ||||
| return -1; | return -1; | ||||
| else if (isect_a->t > isect_b->t) | else if (isect_a->t > isect_b->t) | ||||
| return 1; | return 1; | ||||
| else | else | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| #endif | #endif | ||||
| #if defined(__SHADOW_RECORD_ALL__) | |||||
| ccl_device_inline void sort_intersections(ccl_private Intersection *hits, uint num_hits) | |||||
| { | |||||
| kernel_assert(num_hits > 0); | |||||
| # ifdef __KERNEL_GPU__ | |||||
| /* Use bubble sort which has more friendly memory pattern on GPU. */ | |||||
| bool swapped; | |||||
| do { | |||||
| swapped = false; | |||||
| for (int j = 0; j < num_hits - 1; ++j) { | |||||
| if (hits[j].t > hits[j + 1].t) { | |||||
| struct Intersection tmp = hits[j]; | |||||
| hits[j] = hits[j + 1]; | |||||
| hits[j + 1] = tmp; | |||||
| swapped = true; | |||||
| } | |||||
| } | |||||
| --num_hits; | |||||
| } while (swapped); | |||||
| # else | |||||
| qsort(hits, num_hits, sizeof(Intersection), intersections_compare); | |||||
| # endif | |||||
| } | |||||
| #endif /* __SHADOW_RECORD_ALL__ | __VOLUME_RECORD_ALL__ */ | |||||
| /* For subsurface scattering, only sorting a small amount of intersections | /* For subsurface scattering, only sorting a small amount of intersections | ||||
| * so bubble sort is fine for CPU and GPU. */ | * so bubble sort is fine for CPU and GPU. */ | ||||
| ccl_device_inline void sort_intersections_and_normals(ccl_private Intersection *hits, | ccl_device_inline void sort_intersections_and_normals(ccl_private Intersection *hits, | ||||
| ccl_private float3 *Ng, | ccl_private float3 *Ng, | ||||
| uint num_hits) | uint num_hits) | ||||
| { | { | ||||
| bool swapped; | bool swapped; | ||||
| do { | do { | ||||
| ▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines | |||||