Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/integrator/shade_surface.h
| Show All 9 Lines | |||||
| #include "kernel/integrator/mnee.h" | #include "kernel/integrator/mnee.h" | ||||
| #include "kernel/integrator/guiding.h" | #include "kernel/integrator/guiding.h" | ||||
| #include "kernel/integrator/path_state.h" | #include "kernel/integrator/path_state.h" | ||||
| #include "kernel/integrator/subsurface.h" | #include "kernel/integrator/subsurface.h" | ||||
| #include "kernel/integrator/surface_shader.h" | #include "kernel/integrator/surface_shader.h" | ||||
| #include "kernel/integrator/volume_stack.h" | #include "kernel/integrator/volume_stack.h" | ||||
| #include "kernel/light/light.h" | |||||
| #include "kernel/light/sample.h" | #include "kernel/light/sample.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| ccl_device_forceinline void integrate_surface_shader_setup(KernelGlobals kg, | ccl_device_forceinline void integrate_surface_shader_setup(KernelGlobals kg, | ||||
| ConstIntegratorState state, | ConstIntegratorState state, | ||||
| ccl_private ShaderData *sd) | ccl_private ShaderData *sd) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | ccl_device_forceinline void integrate_surface_emission(KernelGlobals kg, | ||||
| render_buffer) | render_buffer) | ||||
| { | { | ||||
| const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag); | const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag); | ||||
| /* Evaluate emissive closure. */ | /* Evaluate emissive closure. */ | ||||
| Spectrum L = surface_shader_emission(sd); | Spectrum L = surface_shader_emission(sd); | ||||
| float mis_weight = 1.0f; | float mis_weight = 1.0f; | ||||
| const bool has_mis = !(path_flag & PATH_RAY_MIS_SKIP) && | |||||
| (sd->flag & ((sd->flag & SD_BACKFACING) ? SD_MIS_BACK : SD_MIS_FRONT)); | |||||
| #ifdef __HAIR__ | #ifdef __HAIR__ | ||||
| if (!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_USE_MIS) && | if (has_mis && (sd->type & PRIMITIVE_TRIANGLE)) | ||||
| (sd->type & PRIMITIVE_TRIANGLE)) | |||||
| #else | #else | ||||
| if (!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_USE_MIS)) | if (has_mis) | ||||
| #endif | #endif | ||||
| { | { | ||||
| const float bsdf_pdf = INTEGRATOR_STATE(state, path, mis_ray_pdf); | mis_weight = light_sample_mis_weight_forward_surface(kg, state, path_flag, sd); | ||||
| const float t = sd->ray_length; | |||||
| /* Multiple importance sampling, get triangle light pdf, | |||||
| * and compute weight with respect to BSDF pdf. */ | |||||
| float pdf = triangle_light_pdf(kg, sd, t); | |||||
| mis_weight = light_sample_mis_weight_forward(kg, bsdf_pdf, pdf); | |||||
| } | } | ||||
| guiding_record_surface_emission(kg, state, L, mis_weight); | guiding_record_surface_emission(kg, state, L, mis_weight); | ||||
| film_write_surface_emission( | film_write_surface_emission( | ||||
| kg, state, L, mis_weight, render_buffer, object_lightgroup(kg, sd->object)); | kg, state, L, mis_weight, render_buffer, object_lightgroup(kg, sd->object)); | ||||
| } | } | ||||
| /* Path tracing: sample point on light and evaluate light shader, then | /* Path tracing: sample point on light and evaluate light shader, then | ||||
| Show All 11 Lines | ccl_device_forceinline void integrate_surface_direct_light(KernelGlobals kg, | ||||
| /* Sample position on a light. */ | /* Sample position on a light. */ | ||||
| LightSample ls ccl_optional_struct_init; | LightSample ls ccl_optional_struct_init; | ||||
| { | { | ||||
| const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag); | const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag); | ||||
| const uint bounce = INTEGRATOR_STATE(state, path, bounce); | const uint bounce = INTEGRATOR_STATE(state, path, bounce); | ||||
| const float2 rand_light = path_state_rng_2D(kg, rng_state, PRNG_LIGHT); | const float2 rand_light = path_state_rng_2D(kg, rng_state, PRNG_LIGHT); | ||||
| if (!light_distribution_sample_from_position( | if (!light_sample_from_position(kg, | ||||
| kg, rand_light.x, rand_light.y, sd->time, sd->P, bounce, path_flag, &ls)) { | rng_state, | ||||
| rand_light.x, | |||||
| rand_light.y, | |||||
| sd->time, | |||||
| sd->P, | |||||
| sd->N, | |||||
| sd->flag, | |||||
| bounce, | |||||
| path_flag, | |||||
| &ls)) { | |||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| kernel_assert(ls.pdf != 0.0f); | kernel_assert(ls.pdf != 0.0f); | ||||
| /* Evaluate light shader. | /* Evaluate light shader. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | #endif | ||||
| /* Update path state */ | /* Update path state */ | ||||
| if (!(label & LABEL_TRANSPARENT)) { | if (!(label & LABEL_TRANSPARENT)) { | ||||
| INTEGRATOR_STATE_WRITE(state, path, mis_ray_pdf) = bsdf_pdf; | INTEGRATOR_STATE_WRITE(state, path, mis_ray_pdf) = bsdf_pdf; | ||||
| INTEGRATOR_STATE_WRITE(state, path, min_ray_pdf) = fminf( | INTEGRATOR_STATE_WRITE(state, path, min_ray_pdf) = fminf( | ||||
| unguided_bsdf_pdf, INTEGRATOR_STATE(state, path, min_ray_pdf)); | unguided_bsdf_pdf, INTEGRATOR_STATE(state, path, min_ray_pdf)); | ||||
| } | } | ||||
| path_state_next(kg, state, label); | path_state_next(kg, state, label, sd->flag); | ||||
| guiding_record_surface_bounce(kg, | guiding_record_surface_bounce(kg, | ||||
| state, | state, | ||||
| sd, | sd, | ||||
| bsdf_weight, | bsdf_weight, | ||||
| bsdf_pdf, | bsdf_pdf, | ||||
| sd->N, | sd->N, | ||||
| normalize(bsdf_omega_in), | normalize(bsdf_omega_in), | ||||
| ▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines | |||||