Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_emission.h
| Show All 19 Lines | |||||
| #include "kernel/kernel_montecarlo.h" | #include "kernel/kernel_montecarlo.h" | ||||
| #include "kernel/kernel_path_state.h" | #include "kernel/kernel_path_state.h" | ||||
| #include "kernel/kernel_shader.h" | #include "kernel/kernel_shader.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| /* Evaluate shader on light. */ | /* Evaluate shader on light. */ | ||||
| ccl_device_noinline_cpu float3 | ccl_device_noinline_cpu float3 | ||||
| light_sample_shader_eval(INTEGRATOR_STATE_ARGS, | light_sample_shader_eval(KernelGlobals kg, | ||||
| IntegratorState state, | |||||
| ccl_private ShaderData *ccl_restrict emission_sd, | ccl_private ShaderData *ccl_restrict emission_sd, | ||||
| ccl_private LightSample *ccl_restrict ls, | ccl_private LightSample *ccl_restrict ls, | ||||
| float time) | float time) | ||||
| { | { | ||||
| /* setup shading at emitter */ | /* setup shading at emitter */ | ||||
| float3 eval = zero_float3(); | float3 eval = zero_float3(); | ||||
| if (shader_constant_emission_eval(kg, ls->shader, &eval)) { | if (shader_constant_emission_eval(kg, ls->shader, &eval)) { | ||||
| Show All 31 Lines | #endif | ||||
| } | } | ||||
| PROFILING_SHADER(emission_sd->object, emission_sd->shader); | PROFILING_SHADER(emission_sd->object, emission_sd->shader); | ||||
| PROFILING_EVENT(PROFILING_SHADE_LIGHT_EVAL); | PROFILING_EVENT(PROFILING_SHADE_LIGHT_EVAL); | ||||
| /* No proper path flag, we're evaluating this for all closures. that's | /* No proper path flag, we're evaluating this for all closures. that's | ||||
| * weak but we'd have to do multiple evaluations otherwise. */ | * weak but we'd have to do multiple evaluations otherwise. */ | ||||
| shader_eval_surface<KERNEL_FEATURE_NODE_MASK_SURFACE_LIGHT>( | shader_eval_surface<KERNEL_FEATURE_NODE_MASK_SURFACE_LIGHT>( | ||||
| INTEGRATOR_STATE_PASS, emission_sd, NULL, PATH_RAY_EMISSION); | kg, state, emission_sd, NULL, PATH_RAY_EMISSION); | ||||
| /* Evaluate closures. */ | /* Evaluate closures. */ | ||||
| #ifdef __BACKGROUND_MIS__ | #ifdef __BACKGROUND_MIS__ | ||||
| if (ls->type == LIGHT_BACKGROUND) { | if (ls->type == LIGHT_BACKGROUND) { | ||||
| eval = shader_background_eval(emission_sd); | eval = shader_background_eval(emission_sd); | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| Show All 15 Lines | |||||
| /* Test if light sample is from a light or emission from geometry. */ | /* Test if light sample is from a light or emission from geometry. */ | ||||
| ccl_device_inline bool light_sample_is_light(ccl_private const LightSample *ccl_restrict ls) | ccl_device_inline bool light_sample_is_light(ccl_private const LightSample *ccl_restrict ls) | ||||
| { | { | ||||
| /* return if it's a lamp for shadow pass */ | /* return if it's a lamp for shadow pass */ | ||||
| return (ls->prim == PRIM_NONE && ls->type != LIGHT_BACKGROUND); | return (ls->prim == PRIM_NONE && ls->type != LIGHT_BACKGROUND); | ||||
| } | } | ||||
| /* Early path termination of shadow rays. */ | /* Early path termination of shadow rays. */ | ||||
| ccl_device_inline bool light_sample_terminate(ccl_global const KernelGlobals *ccl_restrict kg, | ccl_device_inline bool light_sample_terminate(KernelGlobals kg, | ||||
| ccl_private const LightSample *ccl_restrict ls, | ccl_private const LightSample *ccl_restrict ls, | ||||
| ccl_private BsdfEval *ccl_restrict eval, | ccl_private BsdfEval *ccl_restrict eval, | ||||
| const float rand_terminate) | const float rand_terminate) | ||||
| { | { | ||||
| if (bsdf_eval_is_zero(eval)) { | if (bsdf_eval_is_zero(eval)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| Show All 11 Lines | ccl_device_inline bool light_sample_terminate(KernelGlobals kg, | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* This function should be used to compute a modified ray start position for | /* This function should be used to compute a modified ray start position for | ||||
| * rays leaving from a surface. The algorithm slightly distorts flat surface | * rays leaving from a surface. The algorithm slightly distorts flat surface | ||||
| * of a triangle. Surface is lifted by amount h along normal n in the incident | * of a triangle. Surface is lifted by amount h along normal n in the incident | ||||
| * point. */ | * point. */ | ||||
| ccl_device_inline float3 | ccl_device_inline float3 shadow_ray_smooth_surface_offset( | ||||
| shadow_ray_smooth_surface_offset(ccl_global const KernelGlobals *ccl_restrict kg, | KernelGlobals kg, ccl_private const ShaderData *ccl_restrict sd, float3 Ng) | ||||
| ccl_private const ShaderData *ccl_restrict sd, | |||||
| float3 Ng) | |||||
| { | { | ||||
| float3 V[3], N[3]; | float3 V[3], N[3]; | ||||
| triangle_vertices_and_normals(kg, sd->prim, V, N); | triangle_vertices_and_normals(kg, sd->prim, V, N); | ||||
| const float u = sd->u, v = sd->v; | const float u = sd->u, v = sd->v; | ||||
| const float w = 1 - u - v; | const float w = 1 - u - v; | ||||
| float3 P = V[0] * u + V[1] * v + V[2] * w; /* Local space */ | float3 P = V[0] * u + V[1] * v + V[2] * w; /* Local space */ | ||||
| float3 n = N[0] * u + N[1] * v + N[2] * w; /* We get away without normalization */ | float3 n = N[0] * u + N[1] * v + N[2] * w; /* We get away without normalization */ | ||||
| Show All 27 Lines | else { | ||||
| h = min(-min(min(h0, h1), h2), h * 0.5f); | h = min(-min(min(h0, h1), h2), h * 0.5f); | ||||
| } | } | ||||
| return n * h; | return n * h; | ||||
| } | } | ||||
| /* Ray offset to avoid shadow terminator artifact. */ | /* Ray offset to avoid shadow terminator artifact. */ | ||||
| ccl_device_inline float3 shadow_ray_offset(ccl_global const KernelGlobals *ccl_restrict kg, | ccl_device_inline float3 shadow_ray_offset(KernelGlobals kg, | ||||
| ccl_private const ShaderData *ccl_restrict sd, | ccl_private const ShaderData *ccl_restrict sd, | ||||
| float3 L) | float3 L) | ||||
| { | { | ||||
| float NL = dot(sd->N, L); | float NL = dot(sd->N, L); | ||||
| bool transmit = (NL < 0.0f); | bool transmit = (NL < 0.0f); | ||||
| float3 Ng = (transmit ? -sd->Ng : sd->Ng); | float3 Ng = (transmit ? -sd->Ng : sd->Ng); | ||||
| float3 P = ray_offset(sd->P, Ng); | float3 P = ray_offset(sd->P, Ng); | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | ccl_device_inline void shadow_ray_setup(ccl_private const ShaderData *ccl_restrict sd, | ||||
| ray->dP = differential_make_compact(sd->dP); | ray->dP = differential_make_compact(sd->dP); | ||||
| ray->dD = differential_zero_compact(); | ray->dD = differential_zero_compact(); | ||||
| ray->time = sd->time; | ray->time = sd->time; | ||||
| } | } | ||||
| /* Create shadow ray towards light sample. */ | /* Create shadow ray towards light sample. */ | ||||
| ccl_device_inline void light_sample_to_surface_shadow_ray( | ccl_device_inline void light_sample_to_surface_shadow_ray( | ||||
| ccl_global const KernelGlobals *ccl_restrict kg, | KernelGlobals kg, | ||||
| ccl_private const ShaderData *ccl_restrict sd, | ccl_private const ShaderData *ccl_restrict sd, | ||||
| ccl_private const LightSample *ccl_restrict ls, | ccl_private const LightSample *ccl_restrict ls, | ||||
| ccl_private Ray *ray) | ccl_private Ray *ray) | ||||
| { | { | ||||
| const float3 P = shadow_ray_offset(kg, sd, ls->D); | const float3 P = shadow_ray_offset(kg, sd, ls->D); | ||||
| shadow_ray_setup(sd, ls, P, ray); | shadow_ray_setup(sd, ls, P, ray); | ||||
| } | } | ||||
| /* Create shadow ray towards light sample. */ | /* Create shadow ray towards light sample. */ | ||||
| ccl_device_inline void light_sample_to_volume_shadow_ray( | ccl_device_inline void light_sample_to_volume_shadow_ray( | ||||
| ccl_global const KernelGlobals *ccl_restrict kg, | KernelGlobals kg, | ||||
| ccl_private const ShaderData *ccl_restrict sd, | ccl_private const ShaderData *ccl_restrict sd, | ||||
| ccl_private const LightSample *ccl_restrict ls, | ccl_private const LightSample *ccl_restrict ls, | ||||
| const float3 P, | const float3 P, | ||||
| ccl_private Ray *ray) | ccl_private Ray *ray) | ||||
| { | { | ||||
| shadow_ray_setup(sd, ls, P, ray); | shadow_ray_setup(sd, ls, P, ray); | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||