Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_path.h
| Context not available. | |||||
| #if defined(__BRANCHED_PATH__) || defined(__SUBSURFACE__) | #if defined(__BRANCHED_PATH__) || defined(__SUBSURFACE__) | ||||
| ccl_device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, Ray ray, ccl_global float *buffer, | ccl_device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, Ray ray, ccl_global float *buffer, | ||||
| float3 throughput, int num_samples, PathState state, PathRadiance *L) | float3 throughput, int num_samples, float pass_samples, PathState state, PathRadiance *L) | ||||
| { | { | ||||
| /* path iteration */ | /* path iteration */ | ||||
| for(;;) { | for(;;) { | ||||
| Context not available. | |||||
| if(kernel_data.integrator.use_direct_light) { | if(kernel_data.integrator.use_direct_light) { | ||||
| /* sample illumination from lights to find path contribution */ | /* sample illumination from lights to find path contribution */ | ||||
| if(sd.flag & SD_BSDF_HAS_EVAL) { | if(sd.flag & SD_BSDF_HAS_EVAL) { | ||||
| float light_t = path_state_rng_1D(kg, rng, &state, PRNG_LIGHT); | |||||
| #ifdef __MULTI_CLOSURE__ | |||||
| float light_o = 0.0f; | |||||
| #else | |||||
| float light_o = path_state_rng_1D(kg, rng, &state, PRNG_LIGHT_F); | |||||
| #endif | |||||
| float light_u, light_v; | |||||
| path_state_rng_2D(kg, rng, &state, PRNG_LIGHT_U, &light_u, &light_v); | |||||
| Ray light_ray; | Ray light_ray; | ||||
| BsdfEval L_light; | BsdfEval L_light; | ||||
| bool is_lamp; | bool is_lamp; | ||||
| Context not available. | |||||
| light_ray.time = sd.time; | light_ray.time = sd.time; | ||||
| #endif | #endif | ||||
| /* sample random light */ | int num_samples_adjust = 1.0f; | ||||
| if(direct_emission(kg, &sd, -1, light_t, light_o, light_u, light_v, &light_ray, &L_light, &is_lamp, state.bounce)) { | |||||
| /* trace shadow ray */ | |||||
| float3 shadow; | |||||
| if(!shadow_blocked(kg, &state, &light_ray, &shadow)) { | /* lamp sampling */ | ||||
| /* accumulate */ | for(int i = 0; i < kernel_data.integrator.num_all_lights; i++) { | ||||
| path_radiance_accum_light(L, throughput, &L_light, shadow, 1.0f, state.bounce, is_lamp); | int num_samples = ceil_to_int(num_samples_adjust*light_select_num_samples(kg, i)); | ||||
| //float num_samples_inv = num_samples_adjust/(num_samples*kernel_data.integrator.num_all_lights); // FIX | |||||
| float num_samples_inv = pass_samples; | |||||
| RNG lamp_rng = cmj_hash(*rng, i); | |||||
| if(kernel_data.integrator.pdf_triangles != 0.0f) | |||||
| num_samples_inv *= 0.5f; | |||||
| for(int j = 0; j < num_samples; j++) { | |||||
| float light_u, light_v; | |||||
| path_branched_rng_2D(kg, &lamp_rng, &state, j, num_samples, PRNG_LIGHT_U, &light_u, &light_v); | |||||
| #ifdef __MULTI_CLOSURE__ | |||||
| float light_o = 0.0f; | |||||
| #else | |||||
| float light_o = path_branched_rng_1D(kg, rng, &state, j, num_samples, PRNG_LIGHT_F); | |||||
| #endif | |||||
| if(direct_emission(kg, &sd, i, 0.0f, light_o, light_u, light_v, &light_ray, &L_light, &is_lamp, state.bounce)) { | |||||
| /* trace shadow ray */ | |||||
| float3 shadow; | |||||
| if(!shadow_blocked(kg, &state, &light_ray, &shadow)) { | |||||
| /* accumulate */ | |||||
| path_radiance_accum_light(L, throughput*num_samples_inv, &L_light, shadow, num_samples_inv, state.bounce, is_lamp); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| /* mesh light sampling */ | |||||
| if(kernel_data.integrator.pdf_triangles != 0.0f) { | |||||
| int num_samples = ceil_to_int(num_samples_adjust*kernel_data.integrator.mesh_light_samples); | |||||
| float num_samples_inv = num_samples_adjust/num_samples; | |||||
| if(kernel_data.integrator.num_all_lights) | |||||
| num_samples_inv *= 0.5f; | |||||
| for(int j = 0; j < num_samples; j++) { | |||||
| float light_t = path_branched_rng_1D(kg, rng, &state, j, num_samples, PRNG_LIGHT); | |||||
| #ifdef __MULTI_CLOSURE__ | |||||
| float light_o = 0.0f; | |||||
| #else | |||||
| float light_o = path_branched_rng_1D(kg, rng, &state, j, num_samples, PRNG_LIGHT_F); | |||||
| #endif | |||||
| float light_u, light_v; | |||||
| path_branched_rng_2D(kg, rng, &state, j, num_samples, PRNG_LIGHT_U, &light_u, &light_v); | |||||
| /* only sample triangle lights */ | |||||
| if(kernel_data.integrator.num_all_lights) | |||||
| light_t = 0.5f*light_t; | |||||
| if(direct_emission(kg, &sd, -1, light_t, light_o, light_u, light_v, &light_ray, &L_light, &is_lamp, state.bounce)) { | |||||
| /* trace shadow ray */ | |||||
| float3 shadow; | |||||
| if(!shadow_blocked(kg, &state, &light_ray, &shadow)) { | |||||
| /* accumulate */ | |||||
| path_radiance_accum_light(L, throughput*num_samples_inv, &L_light, shadow, num_samples_inv, state.bounce, is_lamp); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| hit_state.ray_t = 0.0f; | hit_state.ray_t = 0.0f; | ||||
| #endif | #endif | ||||
| kernel_path_indirect(kg, rng, hit_ray, buffer, tp, state.num_samples, hit_state, &L); | kernel_path_indirect(kg, rng, hit_ray, buffer, tp, state.num_samples, 1.0f, hit_state, &L); | ||||
| /* for render passes, sum and reset indirect light pass variables | /* for render passes, sum and reset indirect light pass variables | ||||
| * for the next samples */ | * for the next samples */ | ||||
| Context not available. | |||||
| RNG *rng, ShaderData *sd, float3 throughput, float num_samples_adjust, | RNG *rng, ShaderData *sd, float3 throughput, float num_samples_adjust, | ||||
| PathState *state, PathRadiance *L, ccl_global float *buffer) | PathState *state, PathRadiance *L, ccl_global float *buffer) | ||||
| { | { | ||||
| float pass_samples; /* XXX, need to pass this properly */ | |||||
| #ifdef __EMISSION__ | #ifdef __EMISSION__ | ||||
| /* sample illumination from lights to find path contribution */ | /* sample illumination from lights to find path contribution */ | ||||
| if(sd->flag & SD_BSDF_HAS_EVAL) { | if(sd->flag & SD_BSDF_HAS_EVAL) { | ||||
| Context not available. | |||||
| for(int i = 0; i < kernel_data.integrator.num_all_lights; i++) { | for(int i = 0; i < kernel_data.integrator.num_all_lights; i++) { | ||||
| int num_samples = ceil_to_int(num_samples_adjust*light_select_num_samples(kg, i)); | int num_samples = ceil_to_int(num_samples_adjust*light_select_num_samples(kg, i)); | ||||
| float num_samples_inv = num_samples_adjust/(num_samples*kernel_data.integrator.num_all_lights); | float num_samples_inv = num_samples_adjust/(num_samples*kernel_data.integrator.num_all_lights); | ||||
| pass_samples = num_samples_inv; | |||||
| RNG lamp_rng = cmj_hash(*rng, i); | RNG lamp_rng = cmj_hash(*rng, i); | ||||
| if(kernel_data.integrator.pdf_triangles != 0.0f) | if(kernel_data.integrator.pdf_triangles != 0.0f) | ||||
| Context not available. | |||||
| ps.ray_t = 0.0f; | ps.ray_t = 0.0f; | ||||
| #endif | #endif | ||||
| kernel_path_indirect(kg, rng, bsdf_ray, buffer, tp*num_samples_inv, num_samples, ps, L); | kernel_path_indirect(kg, rng, bsdf_ray, buffer, tp*num_samples_inv, num_samples, pass_samples, ps, L); | ||||
| /* for render passes, sum and reset indirect light pass variables | /* for render passes, sum and reset indirect light pass variables | ||||
| * for the next samples */ | * for the next samples */ | ||||
| Context not available. | |||||
| if(result == VOLUME_PATH_SCATTERED) { | if(result == VOLUME_PATH_SCATTERED) { | ||||
| /* todo: use all-light sampling */ | /* todo: use all-light sampling */ | ||||
| if(kernel_path_integrate_scatter_lighting(kg, rng, &volume_sd, &tp, &ps, &L, &pray, num_samples_inv)) { | if(kernel_path_integrate_scatter_lighting(kg, rng, &volume_sd, &tp, &ps, &L, &pray, num_samples_inv)) { | ||||
| kernel_path_indirect(kg, rng, pray, buffer, tp*num_samples_inv, num_samples, ps, &L); | kernel_path_indirect(kg, rng, pray, buffer, tp*num_samples_inv, num_samples, 1.0f, ps, &L); | ||||
| /* for render passes, sum and reset indirect light pass variables | /* for render passes, sum and reset indirect light pass variables | ||||
| * for the next samples */ | * for the next samples */ | ||||
| Context not available. | |||||