diff options
Diffstat (limited to 'intern/cycles/kernel/light/light.h')
-rw-r--r-- | intern/cycles/kernel/light/light.h | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/intern/cycles/kernel/light/light.h b/intern/cycles/kernel/light/light.h index 1df1615ed99..12a6f21b58d 100644 --- a/intern/cycles/kernel/light/light.h +++ b/intern/cycles/kernel/light/light.h @@ -38,7 +38,7 @@ ccl_device_inline bool light_sample(KernelGlobals kg, const uint32_t path_flag, ccl_private LightSample *ls) { - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp); if (path_flag & PATH_RAY_SHADOW_CATCHER_PASS) { if (klight->shader_id & SHADER_EXCLUDE_SHADOW_CATCHER) { return false; @@ -86,7 +86,6 @@ ccl_device_inline bool light_sample(KernelGlobals kg, ls->pdf = invarea / (costheta * costheta * costheta); ls->eval_fac = ls->pdf; } -#ifdef __BACKGROUND_MIS__ else if (type == LIGHT_BACKGROUND) { /* infinite area light (e.g. light dome or env light) */ float3 D = -background_light_sample(kg, P, randu, randv, &ls->pdf); @@ -97,7 +96,6 @@ ccl_device_inline bool light_sample(KernelGlobals kg, ls->t = FLT_MAX; ls->eval_fac = 1.0f; } -#endif else { ls->P = make_float3(klight->co[0], klight->co[1], klight->co[2]); @@ -202,8 +200,12 @@ ccl_device_inline bool light_sample(KernelGlobals kg, inplane = ls->P - inplane; } - ls->u = dot(inplane, axisu) * (1.0f / dot(axisu, axisu)) + 0.5f; - ls->v = dot(inplane, axisv) * (1.0f / dot(axisv, axisv)) + 0.5f; + const float light_u = dot(inplane, axisu) * (1.0f / dot(axisu, axisu)); + const float light_v = dot(inplane, axisv) * (1.0f / dot(axisv, axisv)); + + /* NOTE: Return barycentric coordinates in the same notation as Embree and OptiX. */ + ls->u = light_v + 0.5f; + ls->v = -light_u - light_v; ls->Ng = Ng; ls->D = normalize_len(ls->P - P, &ls->t); @@ -237,7 +239,7 @@ ccl_device bool lights_intersect(KernelGlobals kg, const uint32_t path_flag) { for (int lamp = 0; lamp < kernel_data.integrator.num_all_lights; lamp++) { - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp); if (path_flag & PATH_RAY_CAMERA) { if (klight->shader_id & SHADER_EXCLUDE_CAMERA) { @@ -270,31 +272,26 @@ ccl_device bool lights_intersect(KernelGlobals kg, if (type == LIGHT_SPOT) { /* Spot/Disk light. */ - const float mis_ray_t = INTEGRATOR_STATE(state, path, mis_ray_t); - const float3 ray_P = ray->P - ray->D * mis_ray_t; - const float3 lightP = make_float3(klight->co[0], klight->co[1], klight->co[2]); const float radius = klight->spot.radius; if (radius == 0.0f) { continue; } /* disk oriented normal */ - const float3 lightN = normalize(ray_P - lightP); + const float3 lightN = normalize(ray->P - lightP); /* One sided. */ if (dot(ray->D, lightN) >= 0.0f) { continue; } float3 P; - if (!ray_disk_intersect(ray->P, ray->D, ray->t, lightP, lightN, radius, &P, &t)) { + if (!ray_disk_intersect( + ray->P, ray->D, ray->tmin, ray->tmax, lightP, lightN, radius, &P, &t)) { continue; } } else if (type == LIGHT_POINT) { /* Sphere light (aka, aligned disk light). */ - const float mis_ray_t = INTEGRATOR_STATE(state, path, mis_ray_t); - const float3 ray_P = ray->P - ray->D * mis_ray_t; - const float3 lightP = make_float3(klight->co[0], klight->co[1], klight->co[2]); const float radius = klight->spot.radius; if (radius == 0.0f) { @@ -302,9 +299,10 @@ ccl_device bool lights_intersect(KernelGlobals kg, } /* disk oriented normal */ - const float3 lightN = normalize(ray_P - lightP); + const float3 lightN = normalize(ray->P - lightP); float3 P; - if (!ray_disk_intersect(ray->P, ray->D, ray->t, lightP, lightN, radius, &P, &t)) { + if (!ray_disk_intersect( + ray->P, ray->D, ray->tmin, ray->tmax, lightP, lightN, radius, &P, &t)) { continue; } } @@ -330,8 +328,19 @@ ccl_device bool lights_intersect(KernelGlobals kg, const float3 light_P = make_float3(klight->co[0], klight->co[1], klight->co[2]); float3 P; - if (!ray_quad_intersect( - ray->P, ray->D, 0.0f, ray->t, light_P, axisu, axisv, Ng, &P, &t, &u, &v, is_round)) { + if (!ray_quad_intersect(ray->P, + ray->D, + ray->tmin, + ray->tmax, + light_P, + axisu, + axisv, + Ng, + &P, + &t, + &u, + &v, + is_round)) { continue; } } @@ -358,7 +367,7 @@ ccl_device bool light_sample_from_distant_ray(KernelGlobals kg, const int lamp, ccl_private LightSample *ccl_restrict ls) { - ccl_global const KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + ccl_global const KernelLight *klight = &kernel_data_fetch(lights, lamp); const int shader = klight->shader_id; const float radius = klight->distant.radius; const LightType type = (LightType)klight->type; @@ -433,7 +442,7 @@ ccl_device bool light_sample_from_intersection(KernelGlobals kg, ccl_private LightSample *ccl_restrict ls) { const int lamp = isect->prim; - ccl_global const KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + ccl_global const KernelLight *klight = &kernel_data_fetch(lights, lamp); LightType type = (LightType)klight->type; ls->type = type; ls->shader = klight->shader_id; @@ -562,7 +571,7 @@ ccl_device_inline bool triangle_world_space_vertices( KernelGlobals kg, int object, int prim, float time, float3 V[3]) { bool has_motion = false; - const int object_flag = kernel_tex_fetch(__object_flag, object); + const int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_HAS_VERTEX_MOTION && time >= 0.0f) { motion_triangle_vertices(kg, object, prim, time, V); @@ -699,12 +708,12 @@ ccl_device_forceinline void triangle_light_sample(KernelGlobals kg, float area = 0.5f * Nl; /* flip normal if necessary */ - const int object_flag = kernel_tex_fetch(__object_flag, object); + const int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) { ls->Ng = -ls->Ng; } ls->eval_fac = 1.0f; - ls->shader = kernel_tex_fetch(__tri_shader, prim); + ls->shader = kernel_data_fetch(tri_shader, prim); ls->object = object; ls->prim = prim; ls->lamp = LAMP_NONE; @@ -775,7 +784,8 @@ ccl_device_forceinline void triangle_light_sample(KernelGlobals kg, ls->D = z * B + safe_sqrtf(1.0f - z * z) * safe_normalize(C_ - dot(C_, B) * B); /* calculate intersection with the planar triangle */ - if (!ray_triangle_intersect(P, ls->D, FLT_MAX, V[0], V[1], V[2], &ls->u, &ls->v, &ls->t)) { + if (!ray_triangle_intersect( + P, ls->D, 0.0f, FLT_MAX, V[0], V[1], V[2], &ls->u, &ls->v, &ls->t)) { ls->pdf = 0.0f; return; } @@ -845,7 +855,7 @@ ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *ra int half_len = len >> 1; int middle = first + half_len; - if (r < kernel_tex_fetch(__light_distribution, middle).totarea) { + if (r < kernel_data_fetch(light_distribution, middle).totarea) { len = half_len; } else { @@ -860,8 +870,8 @@ ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *ra /* Rescale to reuse random number. this helps the 2D samples within * each area light be stratified as well. */ - float distr_min = kernel_tex_fetch(__light_distribution, index).totarea; - float distr_max = kernel_tex_fetch(__light_distribution, index + 1).totarea; + float distr_min = kernel_data_fetch(light_distribution, index).totarea; + float distr_max = kernel_data_fetch(light_distribution, index + 1).totarea; *randu = (r - distr_min) / (distr_max - distr_min); return index; @@ -871,7 +881,7 @@ ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *ra ccl_device_inline bool light_select_reached_max_bounces(KernelGlobals kg, int index, int bounce) { - return (bounce > kernel_tex_fetch(__lights, index).max_bounces); + return (bounce > kernel_data_fetch(lights, index).max_bounces); } template<bool in_volume_segment> @@ -886,8 +896,8 @@ ccl_device_noinline bool light_distribution_sample(KernelGlobals kg, { /* Sample light index from distribution. */ const int index = light_distribution_sample(kg, &randu); - ccl_global const KernelLightDistribution *kdistribution = &kernel_tex_fetch(__light_distribution, - index); + ccl_global const KernelLightDistribution *kdistribution = &kernel_data_fetch(light_distribution, + index); const int prim = kdistribution->prim; if (prim >= 0) { @@ -896,7 +906,7 @@ ccl_device_noinline bool light_distribution_sample(KernelGlobals kg, /* Exclude synthetic meshes from shadow catcher pass. */ if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) && - !(kernel_tex_fetch(__object_flag, object) & SD_OBJECT_SHADOW_CATCHER)) { + !(kernel_data_fetch(object_flag, object) & SD_OBJECT_SHADOW_CATCHER)) { return false; } |