diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-02-03 16:54:39 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-02-03 16:54:39 +0300 |
commit | 5920de9247f2094b88716feca4811b7aa6f60505 (patch) | |
tree | abfe491bd016f2e67cd801ec3eeb0b4bbe4ac2ea /intern | |
parent | b4e06bd7d4389a9f69b1754d7de7cc88d00ba801 (diff) | |
parent | e4c179f1d87075bad65f320168dd8552c0d847d1 (diff) |
Merge branch 'blender-v3.1-release'
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/kernel/light/light.h | 86 |
1 files changed, 56 insertions, 30 deletions
diff --git a/intern/cycles/kernel/light/light.h b/intern/cycles/kernel/light/light.h index b9c0b533518..d05fe47cc2c 100644 --- a/intern/cycles/kernel/light/light.h +++ b/intern/cycles/kernel/light/light.h @@ -113,22 +113,30 @@ ccl_device_inline bool light_sample(KernelGlobals kg, ls->P = make_float3(klight->co[0], klight->co[1], klight->co[2]); if (type == LIGHT_SPOT) { - ls->Ng = make_float3(klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]); - float radius = klight->spot.radius; + const float3 center = make_float3(klight->co[0], klight->co[1], klight->co[2]); + const float radius = klight->spot.radius; + const float3 dir = make_float3( + klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]); + /* disk oriented normal */ + const float3 lightN = normalize(P - center); + ls->P = center; if (radius > 0.0f) - /* sphere light */ - ls->P += disk_light_sample(ls->Ng, randu, randv) * radius; + /* disk light */ + ls->P += disk_light_sample(lightN, randu, randv) * radius; + + const float invarea = klight->spot.invarea; + ls->pdf = invarea; ls->D = normalize_len(ls->P - P, &ls->t); + /* we set the light normal to the outgoing direction to support texturing */ + ls->Ng = -ls->D; - float invarea = klight->spot.invarea; ls->eval_fac = (0.25f * M_1_PI_F) * invarea; - ls->pdf = invarea; /* spot light attenuation */ ls->eval_fac *= spot_light_attenuation( - ls->Ng, klight->spot.spot_angle, klight->spot.spot_smooth, -ls->D); + dir, klight->spot.spot_angle, klight->spot.spot_smooth, -ls->D); if (!in_volume_segment && ls->eval_fac == 0.0f) { return false; } @@ -137,32 +145,33 @@ ccl_device_inline bool light_sample(KernelGlobals kg, ls->u = uv.x; ls->v = uv.y; - ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t); + ls->pdf *= lamp_light_pdf(kg, lightN, -ls->D, ls->t); } else if (type == LIGHT_POINT) { float3 center = make_float3(klight->co[0], klight->co[1], klight->co[2]); float radius = klight->spot.radius; + /* disk oriented normal */ + const float3 lightN = normalize(P - center); ls->P = center; - float pdf = 1.0; if (radius > 0.0f) { - ls->Ng = normalize(P - center); - ls->P += disk_light_sample(ls->Ng, randu, randv) * radius; - pdf = klight->spot.invarea; - ls->D = normalize_len(ls->P - P, &ls->t); - } - else { - ls->Ng = normalize(P - center); + ls->P += disk_light_sample(lightN, randu, randv) * radius; } + ls->pdf = klight->spot.invarea; ls->D = normalize_len(ls->P - P, &ls->t); - ls->pdf = pdf; + /* we set the light normal to the outgoing direction to support texturing */ + ls->Ng = -ls->D; + ls->eval_fac = M_1_PI_F * 0.25f * klight->spot.invarea; + if (!in_volume_segment && ls->eval_fac == 0.0f) { + return false; + } float2 uv = map_to_sphere(ls->Ng); ls->u = uv.x; ls->v = uv.y; - ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t); + ls->pdf *= lamp_light_pdf(kg, lightN, -ls->D, ls->t); } else { /* area light */ @@ -263,14 +272,16 @@ 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 float3 lightN = make_float3( - klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]); const float radius = klight->spot.radius; if (radius == 0.0f) { continue; } - + /* disk oriented normal */ + const float3 lightN = normalize(ray_P - lightP); /* One sided. */ if (dot(ray->D, lightN) >= 0.0f) { continue; @@ -292,9 +303,10 @@ ccl_device bool lights_intersect(KernelGlobals kg, continue; } + /* disk oriented normal */ + const float3 lightN = normalize(ray_P - lightP); float3 P; - const float3 lsN = normalize(ray_P - lightP); - if (!ray_disk_intersect(ray->P, ray->D, ray->t, lightP, lsN, radius, &P, &t)) { + if (!ray_disk_intersect(ray->P, ray->D, ray->t, lightP, lightN, radius, &P, &t)) { continue; } } @@ -427,7 +439,12 @@ ccl_device bool light_sample_from_intersection(KernelGlobals kg, ls->D = ray_D; if (type == LIGHT_SPOT) { - ls->Ng = make_float3(klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]); + const float3 center = make_float3(klight->co[0], klight->co[1], klight->co[2]); + const float3 dir = make_float3(klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]); + /* the normal of the oriented disk */ + const float3 lightN = normalize(ray_P - center); + /* we set the light normal to the outgoing direction to support texturing*/ + ls->Ng = -ls->D; float invarea = klight->spot.invarea; ls->eval_fac = (0.25f * M_1_PI_F) * invarea; @@ -435,7 +452,7 @@ ccl_device bool light_sample_from_intersection(KernelGlobals kg, /* spot light attenuation */ ls->eval_fac *= spot_light_attenuation( - ls->Ng, klight->spot.spot_angle, klight->spot.spot_smooth, -ls->D); + dir, klight->spot.spot_angle, klight->spot.spot_smooth, -ls->D); if (ls->eval_fac == 0.0f) { return false; @@ -447,23 +464,32 @@ ccl_device bool light_sample_from_intersection(KernelGlobals kg, /* compute pdf */ if (ls->t != FLT_MAX) - ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t); + ls->pdf *= lamp_light_pdf(kg, lightN, -ls->D, ls->t); + else + ls->pdf = 0.f; } else if (type == LIGHT_POINT) { - float3 center = make_float3(klight->co[0], klight->co[1], klight->co[2]); + const float3 center = make_float3(klight->co[0], klight->co[1], klight->co[2]); + const float3 lighN = normalize(ray_P - center); + + /* we set the light normal to the outgoing direction to support texturing*/ + ls->Ng = -ls->D; - ls->Ng = normalize(ray_P - center); float invarea = klight->spot.invarea; ls->eval_fac = (0.25f * M_1_PI_F) * invarea; ls->pdf = invarea; + if (ls->eval_fac == 0.0f) { + return false; + } + float2 uv = map_to_sphere(ls->Ng); ls->u = uv.x; ls->v = uv.y; /* compute pdf */ if (ls->t != FLT_MAX) - ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t); + ls->pdf *= lamp_light_pdf(kg, lighN, -ls->D, ls->t); else ls->pdf = 0.f; } @@ -921,4 +947,4 @@ ccl_device_inline bool light_distribution_sample_new_position(KernelGlobals kg, } } -CCL_NAMESPACE_END +CCL_NAMESPACE_END
\ No newline at end of file |