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/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/light.h" | |||||||||||
| #include "kernel/light/light_tree.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 94 Lines • ▼ Show 20 Lines | ||||||||||||
| #endif | #endif | |||||||||||
| { | { | |||||||||||
| const float bsdf_pdf = INTEGRATOR_STATE(state, path, mis_ray_pdf); | const float bsdf_pdf = INTEGRATOR_STATE(state, path, mis_ray_pdf); | |||||||||||
| const float t = sd->ray_length; | const float t = sd->ray_length; | |||||||||||
| /* Multiple importance sampling, get triangle light pdf, | /* Multiple importance sampling, get triangle light pdf, | |||||||||||
| * and compute weight with respect to BSDF pdf. */ | * and compute weight with respect to BSDF pdf. */ | |||||||||||
| float pdf = triangle_light_pdf(kg, sd, t); | float pdf = triangle_light_pdf(kg, sd, t); | |||||||||||
| mis_weight = light_sample_mis_weight_forward(kg, bsdf_pdf, pdf); | if (kernel_data.integrator.use_light_tree) { | |||||||||||
| float3 ray_P = INTEGRATOR_STATE(state, ray, P); | ||||||||||||
| const float3 ray_D = INTEGRATOR_STATE(state, ray, D); | ||||||||||||
| const float3 N = INTEGRATOR_STATE(state, path, mis_origin_n); | ||||||||||||
| uint lookup_offset = kernel_data_fetch(object_lookup_offset, sd->object); | ||||||||||||
| uint prim_offset = kernel_data_fetch(object_prim_offset, sd->object); | ||||||||||||
| pdf *= light_tree_pdf(kg, state, ray_P, N, sd->prim - prim_offset + lookup_offset); | ||||||||||||
| } | ||||||||||||
| float mis_weight = light_sample_mis_weight_forward(kg, bsdf_pdf, pdf); | ||||||||||||
AlaskaUnsubmitted Not Done Inline Actions
Alaska: | ||||||||||||
| } | } | |||||||||||
| 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 | |||||||||||
| * queue shadow ray to be traced. */ | * queue shadow ray to be traced. */ | |||||||||||
| Show All 10 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 (kg->data.integrator.use_light_tree) { | ||||||||||||
AlaskaUnsubmitted Not Done Inline ActionsSwapping this out for if (kernel_data.integrator.use_light_tree) { resolves some build issues for the GPU. Alaska: Swapping this out for `if (kernel_data.integrator.use_light_tree) {` resolves some build issues… | ||||||||||||
| if (!light_tree_sample_from_position( | ||||||||||||
| kg, rng_state, rand_light.x, rand_light.y, sd->time, sd->P, sd->N, bounce, path_flag, &ls)) { | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| else { | ||||||||||||
| if (!light_distribution_sample_from_position( | if (!light_distribution_sample_from_position( | |||||||||||
| kg, rand_light.x, rand_light.y, sd->time, sd->P, bounce, path_flag, &ls)) { | kg, rand_light.x, rand_light.y, sd->time, sd->P, bounce, path_flag, &ls)) { | |||||||||||
| return; | return; | |||||||||||
| } | } | |||||||||||
| } | } | |||||||||||
| } | ||||||||||||
| kernel_assert(ls.pdf != 0.0f); | kernel_assert(ls.pdf != 0.0f); | |||||||||||
| /* Evaluate light shader. | /* Evaluate light shader. | |||||||||||
| * | * | |||||||||||
| * TODO: can we reuse sd memory? In theory we can move this after | * TODO: can we reuse sd memory? In theory we can move this after | |||||||||||
| * integrate_surface_bounce, evaluate the BSDF, and only then evaluate | * integrate_surface_bounce, evaluate the BSDF, and only then evaluate | |||||||||||
| * the light shader. This could also move to its own kernel, for | * the light shader. This could also move to its own kernel, for | |||||||||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | if (INTEGRATOR_STATE(state, path, bounce) == 0) { | |||||||||||
| INTEGRATOR_STATE_WRITE(state, path, pass_glossy_weight) = bsdf_eval_pass_glossy_weight( | INTEGRATOR_STATE_WRITE(state, path, pass_glossy_weight) = bsdf_eval_pass_glossy_weight( | |||||||||||
| &bsdf_eval); | &bsdf_eval); | |||||||||||
| } | } | |||||||||||
| } | } | |||||||||||
| /* 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, mis_origin_n) = sd->N; | ||||||||||||
| INTEGRATOR_STATE_WRITE(state, path, min_ray_pdf) = fminf( | INTEGRATOR_STATE_WRITE(state, path, min_ray_pdf) = fminf( | |||||||||||
| bsdf_pdf, INTEGRATOR_STATE(state, path, min_ray_pdf)); | bsdf_pdf, INTEGRATOR_STATE(state, path, min_ray_pdf)); | |||||||||||
| } | } | |||||||||||
| path_state_next(kg, state, label); | path_state_next(kg, state, label); | |||||||||||
| return label; | return label; | |||||||||||
| } | } | |||||||||||
| ▲ Show 20 Lines • Show All 270 Lines • Show Last 20 Lines | ||||||||||||