Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_shadow.h
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if(kernel_data.integrator.transparent_shadows) { | ||||
| /* check transparent bounces here, for volume scatter which can do | /* check transparent bounces here, for volume scatter which can do | ||||
| * lighting before surface path termination is checked */ | * lighting before surface path termination is checked */ | ||||
| if(state->transparent_bounce >= kernel_data.integrator.transparent_max_bounce) | if(state->transparent_bounce >= kernel_data.integrator.transparent_max_bounce) | ||||
| return true; | return true; | ||||
| /* intersect to find an opaque surface, or record all transparent surface hits */ | /* intersect to find an opaque surface, or record all transparent surface hits */ | ||||
| Intersection hits_stack[STACK_MAX_HITS]; | Intersection hits_stack[STACK_MAX_HITS]; | ||||
| Intersection *hits = hits_stack; | Intersection *hits = hits_stack; | ||||
| uint max_hits = kernel_data.integrator.transparent_max_bounce - state->transparent_bounce - 1; | const int transparent_max_bounce = kernel_data.integrator.transparent_max_bounce; | ||||
| uint max_hits = transparent_max_bounce - state->transparent_bounce - 1; | |||||
| /* prefer to use stack but use dynamic allocation if too deep max hits | /* prefer to use stack but use dynamic allocation if too deep max hits | ||||
| * we need max_hits + 1 storage space due to the logic in | * we need max_hits + 1 storage space due to the logic in | ||||
| * scene_intersect_shadow_all which will first store and then check if | * scene_intersect_shadow_all which will first store and then check if | ||||
| * the limit is exceeded */ | * the limit is exceeded */ | ||||
| if(max_hits + 1 > STACK_MAX_HITS) | if(max_hits + 1 > STACK_MAX_HITS) { | ||||
| hits = (Intersection*)malloc(sizeof(Intersection)*(max_hits + 1)); | if (kg->transparent_shadow_intersections == NULL) { | ||||
| kg->transparent_shadow_intersections = | |||||
| (Intersection*)malloc(sizeof(Intersection)*(transparent_max_bounce + 1)); | |||||
| } | |||||
brecht: We need to reallocate if `max_hits` is larger than the previously allocated `max_hits`? Or… | |||||
Not Done Inline ActionsUh, the intention was to allocate transparent_max_bounce intersections straight away. Doing re-allocations is more costly that 1024 preallocated hits. That's a good catch :) sergey: Uh, the intention was to allocate `transparent_max_bounce` intersections straight away. Doing… | |||||
| hits = kg->transparent_shadow_intersections; | |||||
| } | |||||
| uint num_hits; | uint num_hits; | ||||
| blocked = scene_intersect_shadow_all(kg, ray, hits, max_hits, &num_hits); | blocked = scene_intersect_shadow_all(kg, ray, hits, max_hits, &num_hits); | ||||
| /* if no opaque surface found but we did find transparent hits, shade them */ | /* if no opaque surface found but we did find transparent hits, shade them */ | ||||
| if(!blocked && num_hits > 0) { | if(!blocked && num_hits > 0) { | ||||
| float3 throughput = make_float3(1.0f, 1.0f, 1.0f); | float3 throughput = make_float3(1.0f, 1.0f, 1.0f); | ||||
| float3 Pend = ray->P + ray->D*ray->t; | float3 Pend = ray->P + ray->D*ray->t; | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
| #ifdef __VOLUME__ | #ifdef __VOLUME__ | ||||
| /* attenuation for last line segment towards light */ | /* attenuation for last line segment towards light */ | ||||
| if(ps.volume_stack[0].shader != SHADER_NONE) | if(ps.volume_stack[0].shader != SHADER_NONE) | ||||
| kernel_volume_shadow(kg, &ps, ray, &throughput); | kernel_volume_shadow(kg, &ps, ray, &throughput); | ||||
| #endif | #endif | ||||
| *shadow = throughput; | *shadow = throughput; | ||||
| if(hits != hits_stack) | |||||
| free(hits); | |||||
| return is_zero(throughput); | return is_zero(throughput); | ||||
| } | } | ||||
| /* free dynamic storage */ | |||||
| if(hits != hits_stack) | |||||
| free(hits); | |||||
| } | } | ||||
| else { | else { | ||||
| Intersection isect; | Intersection isect; | ||||
| blocked = scene_intersect(kg, ray, PATH_RAY_SHADOW_OPAQUE, &isect, NULL, 0.0f, 0.0f); | blocked = scene_intersect(kg, ray, PATH_RAY_SHADOW_OPAQUE, &isect, NULL, 0.0f, 0.0f); | ||||
| } | } | ||||
| #ifdef __VOLUME__ | #ifdef __VOLUME__ | ||||
| if(!blocked && state->volume_stack[0].shader != SHADER_NONE) { | if(!blocked && state->volume_stack[0].shader != SHADER_NONE) { | ||||
| ▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines | |||||
We need to reallocate if max_hits is larger than the previously allocated max_hits? Or maybe just allocate with size kernel_data.integrator.transparent_max_bounce immediately.