Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/integrator/integrator_intersect_volume_stack.h
| Show All 32 Lines | ccl_device void integrator_volume_stack_update_for_subsurface(INTEGRATOR_STATE_ARGS, | ||||
| ShaderData *stack_sd = AS_SHADER_DATA(&stack_sd_storage); | ShaderData *stack_sd = AS_SHADER_DATA(&stack_sd_storage); | ||||
| kernel_assert(kernel_data.integrator.use_volumes); | kernel_assert(kernel_data.integrator.use_volumes); | ||||
| Ray volume_ray ccl_optional_struct_init; | Ray volume_ray ccl_optional_struct_init; | ||||
| volume_ray.P = from_P; | volume_ray.P = from_P; | ||||
| volume_ray.D = normalize_len(to_P - from_P, &volume_ray.t); | volume_ray.D = normalize_len(to_P - from_P, &volume_ray.t); | ||||
| /* Store to avoid global fetches on every intersection step. */ | |||||
| const uint volume_stack_size = kernel_data.volume_stack_size; | |||||
| #ifdef __VOLUME_RECORD_ALL__ | #ifdef __VOLUME_RECORD_ALL__ | ||||
| Intersection hits[2 * VOLUME_STACK_SIZE + 1]; | Intersection hits[2 * volume_stack_size + 1]; | ||||
| uint num_hits = scene_intersect_volume_all( | uint num_hits = scene_intersect_volume_all( | ||||
| kg, &volume_ray, hits, 2 * VOLUME_STACK_SIZE, PATH_RAY_ALL_VISIBILITY); | kg, &volume_ray, hits, 2 * volume_stack_size, PATH_RAY_ALL_VISIBILITY); | ||||
| if (num_hits > 0) { | if (num_hits > 0) { | ||||
| Intersection *isect = hits; | Intersection *isect = hits; | ||||
| qsort(hits, num_hits, sizeof(Intersection), intersections_compare); | qsort(hits, num_hits, sizeof(Intersection), intersections_compare); | ||||
| for (uint hit = 0; hit < num_hits; ++hit, ++isect) { | for (uint hit = 0; hit < num_hits; ++hit, ++isect) { | ||||
| shader_setup_from_ray(kg, stack_sd, &volume_ray, isect); | shader_setup_from_ray(kg, stack_sd, &volume_ray, isect); | ||||
| volume_stack_enter_exit(INTEGRATOR_STATE_PASS, stack_sd); | volume_stack_enter_exit(INTEGRATOR_STATE_PASS, stack_sd); | ||||
| } | } | ||||
| } | } | ||||
| #else | #else | ||||
| Intersection isect; | Intersection isect; | ||||
| int step = 0; | int step = 0; | ||||
| while (step < 2 * VOLUME_STACK_SIZE && | while (step < 2 * volume_stack_size && | ||||
| scene_intersect_volume(kg, &volume_ray, &isect, PATH_RAY_ALL_VISIBILITY)) { | scene_intersect_volume(kg, &volume_ray, &isect, PATH_RAY_ALL_VISIBILITY)) { | ||||
| shader_setup_from_ray(kg, stack_sd, &volume_ray, &isect); | shader_setup_from_ray(kg, stack_sd, &volume_ray, &isect); | ||||
| volume_stack_enter_exit(INTEGRATOR_STATE_PASS, stack_sd); | volume_stack_enter_exit(INTEGRATOR_STATE_PASS, stack_sd); | ||||
| /* Move ray forward. */ | /* Move ray forward. */ | ||||
| volume_ray.P = ray_offset(stack_sd->P, -stack_sd->Ng); | volume_ray.P = ray_offset(stack_sd->P, -stack_sd->Ng); | ||||
| if (volume_ray.t != FLT_MAX) { | if (volume_ray.t != FLT_MAX) { | ||||
| volume_ray.D = normalize_len(to_P - volume_ray.P, &volume_ray.t); | volume_ray.D = normalize_len(to_P - volume_ray.P, &volume_ray.t); | ||||
| Show All 19 Lines | ccl_device void integrator_intersect_volume_stack(INTEGRATOR_STATE_ARGS) | ||||
| /* Write background shader. */ | /* Write background shader. */ | ||||
| if (kernel_data.background.volume_shader != SHADER_NONE) { | if (kernel_data.background.volume_shader != SHADER_NONE) { | ||||
| const VolumeStack new_entry = {OBJECT_NONE, kernel_data.background.volume_shader}; | const VolumeStack new_entry = {OBJECT_NONE, kernel_data.background.volume_shader}; | ||||
| integrator_state_write_volume_stack(INTEGRATOR_STATE_PASS, stack_index, new_entry); | integrator_state_write_volume_stack(INTEGRATOR_STATE_PASS, stack_index, new_entry); | ||||
| stack_index++; | stack_index++; | ||||
| } | } | ||||
| /* Store to avoid global fetches on every intersection step. */ | |||||
| const uint volume_stack_size = kernel_data.volume_stack_size; | |||||
| #ifdef __VOLUME_RECORD_ALL__ | #ifdef __VOLUME_RECORD_ALL__ | ||||
| Intersection hits[2 * VOLUME_STACK_SIZE + 1]; | Intersection hits[2 * volume_stack_size + 1]; | ||||
| uint num_hits = scene_intersect_volume_all( | uint num_hits = scene_intersect_volume_all( | ||||
| kg, &volume_ray, hits, 2 * VOLUME_STACK_SIZE, visibility); | kg, &volume_ray, hits, 2 * volume_stack_size, visibility); | ||||
| if (num_hits > 0) { | if (num_hits > 0) { | ||||
| int enclosed_volumes[VOLUME_STACK_SIZE]; | int enclosed_volumes[volume_stack_size]; | ||||
| Intersection *isect = hits; | Intersection *isect = hits; | ||||
| qsort(hits, num_hits, sizeof(Intersection), intersections_compare); | qsort(hits, num_hits, sizeof(Intersection), intersections_compare); | ||||
| for (uint hit = 0; hit < num_hits; ++hit, ++isect) { | for (uint hit = 0; hit < num_hits; ++hit, ++isect) { | ||||
| shader_setup_from_ray(kg, stack_sd, &volume_ray, isect); | shader_setup_from_ray(kg, stack_sd, &volume_ray, isect); | ||||
| if (stack_sd->flag & SD_BACKFACING) { | if (stack_sd->flag & SD_BACKFACING) { | ||||
| bool need_add = true; | bool need_add = true; | ||||
| for (int i = 0; i < enclosed_index && need_add; ++i) { | for (int i = 0; i < enclosed_index && need_add; ++i) { | ||||
| /* If ray exited the volume and never entered to that volume | /* If ray exited the volume and never entered to that volume | ||||
| * it means that camera is inside such a volume. | * it means that camera is inside such a volume. | ||||
| */ | */ | ||||
| if (enclosed_volumes[i] == stack_sd->object) { | if (enclosed_volumes[i] == stack_sd->object) { | ||||
| need_add = false; | need_add = false; | ||||
| } | } | ||||
| } | } | ||||
| for (int i = 0; i < stack_index && need_add; ++i) { | for (int i = 0; i < stack_index && need_add; ++i) { | ||||
| /* Don't add intersections twice. */ | /* Don't add intersections twice. */ | ||||
| VolumeStack entry = integrator_state_read_volume_stack(INTEGRATOR_STATE_PASS, i); | VolumeStack entry = integrator_state_read_volume_stack(INTEGRATOR_STATE_PASS, i); | ||||
| if (entry.object == stack_sd->object) { | if (entry.object == stack_sd->object) { | ||||
| need_add = false; | need_add = false; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (need_add && stack_index < VOLUME_STACK_SIZE - 1) { | if (need_add && stack_index < volume_stack_size - 1) { | ||||
| const VolumeStack new_entry = {stack_sd->object, stack_sd->shader}; | const VolumeStack new_entry = {stack_sd->object, stack_sd->shader}; | ||||
| integrator_state_write_volume_stack(INTEGRATOR_STATE_PASS, stack_index, new_entry); | integrator_state_write_volume_stack(INTEGRATOR_STATE_PASS, stack_index, new_entry); | ||||
| ++stack_index; | ++stack_index; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* If ray from camera enters the volume, this volume shouldn't | /* If ray from camera enters the volume, this volume shouldn't | ||||
| * be added to the stack on exit. | * be added to the stack on exit. | ||||
| */ | */ | ||||
| enclosed_volumes[enclosed_index++] = stack_sd->object; | enclosed_volumes[enclosed_index++] = stack_sd->object; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #else | #else | ||||
| int enclosed_volumes[VOLUME_STACK_SIZE]; | /* CUDA does not support defintion of a variable size arrays, so use the maximum possible. */ | ||||
| int enclosed_volumes[MAX_VOLUME_STACK_SIZE]; | |||||
| int step = 0; | int step = 0; | ||||
| while (stack_index < VOLUME_STACK_SIZE - 1 && enclosed_index < VOLUME_STACK_SIZE - 1 && | while (stack_index < volume_stack_size - 1 && enclosed_index < volume_stack_size - 1 && | ||||
| step < 2 * VOLUME_STACK_SIZE) { | step < 2 * volume_stack_size) { | ||||
| Intersection isect; | Intersection isect; | ||||
| if (!scene_intersect_volume(kg, &volume_ray, &isect, visibility)) { | if (!scene_intersect_volume(kg, &volume_ray, &isect, visibility)) { | ||||
| break; | break; | ||||
| } | } | ||||
| shader_setup_from_ray(kg, stack_sd, &volume_ray, &isect); | shader_setup_from_ray(kg, stack_sd, &volume_ray, &isect); | ||||
| if (stack_sd->flag & SD_BACKFACING) { | if (stack_sd->flag & SD_BACKFACING) { | ||||
| /* If ray exited the volume and never entered to that volume | /* If ray exited the volume and never entered to that volume | ||||
| ▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines | |||||