Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/light/light.h
| Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | ccl_device_inline bool light_sample(KernelGlobals kg, | ||||
| if (in_volume_segment && (type == LIGHT_DISTANT || type == LIGHT_BACKGROUND)) { | if (in_volume_segment && (type == LIGHT_DISTANT || type == LIGHT_BACKGROUND)) { | ||||
| /* Distant lights in a volume get a dummy sample, position will not actually | /* Distant lights in a volume get a dummy sample, position will not actually | ||||
| * be used in that case. Only when sampling from a specific scatter position | * be used in that case. Only when sampling from a specific scatter position | ||||
| * do we actually need to evaluate these. */ | * do we actually need to evaluate these. */ | ||||
| ls->P = zero_float3(); | ls->P = zero_float3(); | ||||
| ls->Ng = zero_float3(); | ls->Ng = zero_float3(); | ||||
| ls->D = zero_float3(); | ls->D = zero_float3(); | ||||
| ls->pdf = true; | ls->pdf = 1.0f; | ||||
| ls->t = FLT_MAX; | ls->t = FLT_MAX; | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (type == LIGHT_DISTANT) { | if (type == LIGHT_DISTANT) { | ||||
| /* distant light */ | /* distant light */ | ||||
| float3 lightD = make_float3(klight->co[0], klight->co[1], klight->co[2]); | float3 lightD = make_float3(klight->co[0], klight->co[1], klight->co[2]); | ||||
| float3 D = lightD; | float3 D = lightD; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (type == LIGHT_POINT || type == LIGHT_SPOT) { | ||||
| ls->eval_fac = (0.25f * M_1_PI_F) * invarea; | ls->eval_fac = (0.25f * M_1_PI_F) * invarea; | ||||
| ls->pdf = invarea; | ls->pdf = invarea; | ||||
| if (type == LIGHT_SPOT) { | if (type == LIGHT_SPOT) { | ||||
| /* spot light attenuation */ | /* spot light attenuation */ | ||||
| float3 dir = make_float3(klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]); | float3 dir = make_float3(klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]); | ||||
| ls->eval_fac *= spot_light_attenuation( | ls->eval_fac *= spot_light_attenuation( | ||||
| dir, klight->spot.spot_angle, klight->spot.spot_smooth, ls->Ng); | dir, klight->spot.spot_angle, klight->spot.spot_smooth, ls->Ng); | ||||
| if (ls->eval_fac == 0.0f) { | if (!in_volume_segment && ls->eval_fac == 0.0f) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| float2 uv = map_to_sphere(ls->Ng); | float2 uv = map_to_sphere(ls->Ng); | ||||
| ls->u = uv.x; | ls->u = uv.x; | ||||
| ls->v = uv.y; | ls->v = uv.y; | ||||
| ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t); | ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t); | ||||
| Show All 22 Lines | else { | ||||
| ls->pdf = invarea; | ls->pdf = invarea; | ||||
| } | } | ||||
| else { | else { | ||||
| inplane = ls->P; | inplane = ls->P; | ||||
| float3 sample_axisu = axisu; | float3 sample_axisu = axisu; | ||||
| float3 sample_axisv = axisv; | float3 sample_axisv = axisv; | ||||
| if (klight->area.tan_spread > 0.0f) { | if (!in_volume_segment && klight->area.tan_spread > 0.0f) { | ||||
| if (!light_spread_clamp_area_light( | if (!light_spread_clamp_area_light( | ||||
| P, Ng, &ls->P, &sample_axisu, &sample_axisv, klight->area.tan_spread)) { | P, Ng, &ls->P, &sample_axisu, &sample_axisv, klight->area.tan_spread)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| ls->pdf = rect_light_sample(P, &ls->P, sample_axisu, sample_axisv, randu, randv, true); | ls->pdf = rect_light_sample(P, &ls->P, sample_axisu, sample_axisv, randu, randv, true); | ||||
| inplane = ls->P - inplane; | inplane = ls->P - inplane; | ||||
| Show All 16 Lines | else { | ||||
| if (is_round) { | if (is_round) { | ||||
| ls->pdf *= lamp_light_pdf(kg, Ng, -ls->D, ls->t); | ls->pdf *= lamp_light_pdf(kg, Ng, -ls->D, ls->t); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ls->pdf *= kernel_data.integrator.pdf_lights; | ls->pdf *= kernel_data.integrator.pdf_lights; | ||||
| return (ls->pdf > 0.0f); | return in_volume_segment || (ls->pdf > 0.0f); | ||||
| } | } | ||||
| ccl_device bool lights_intersect(KernelGlobals kg, | ccl_device bool lights_intersect(KernelGlobals kg, | ||||
| ccl_private const Ray *ccl_restrict ray, | ccl_private const Ray *ccl_restrict ray, | ||||
| ccl_private Intersection *ccl_restrict isect, | ccl_private Intersection *ccl_restrict isect, | ||||
| const int last_prim, | const int last_prim, | ||||
| const int last_object, | const int last_object, | ||||
| const int last_type, | const int last_type, | ||||
| ▲ Show 20 Lines • Show All 456 Lines • ▼ Show 20 Lines | if (!in_volume_segment && (longest_edge_squared > distance_to_plane * distance_to_plane)) { | ||||
| const float3 C_ = safe_normalize(q * A + sqrtf(temp) * U); | const float3 C_ = safe_normalize(q * A + sqrtf(temp) * U); | ||||
| /* Finally, select a random point along the edge of the new triangle | /* Finally, select a random point along the edge of the new triangle | ||||
| * That point on the spherical triangle is the sampled ray direction */ | * That point on the spherical triangle is the sampled ray direction */ | ||||
| const float z = 1.0f - randv * (1.0f - dot(C_, B)); | const float z = 1.0f - randv * (1.0f - dot(C_, B)); | ||||
| ls->D = z * B + safe_sqrtf(1.0f - z * z) * safe_normalize(C_ - dot(C_, B) * B); | ls->D = z * B + safe_sqrtf(1.0f - z * z) * safe_normalize(C_ - dot(C_, B) * B); | ||||
| /* calculate intersection with the planar triangle */ | /* calculate intersection with the planar triangle */ | ||||
| if (!ray_triangle_intersect(P, | if (!ray_triangle_intersect(P, ls->D, FLT_MAX, V[0], V[1], V[2], &ls->u, &ls->v, &ls->t)) { | ||||
| ls->D, | |||||
| FLT_MAX, | |||||
| #if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__) | |||||
| (ssef *)V, | |||||
| #else | |||||
| V[0], | |||||
| V[1], | |||||
| V[2], | |||||
| #endif | |||||
| &ls->u, | |||||
| &ls->v, | |||||
| &ls->t)) { | |||||
| ls->pdf = 0.0f; | ls->pdf = 0.0f; | ||||
| return; | return; | ||||
| } | } | ||||
| ls->P = P + ls->D * ls->t; | ls->P = P + ls->D * ls->t; | ||||
| /* pdf_triangles is calculated over triangle area, but we're sampling over solid angle */ | /* pdf_triangles is calculated over triangle area, but we're sampling over solid angle */ | ||||
| if (UNLIKELY(solid_angle == 0.0f)) { | if (UNLIKELY(solid_angle == 0.0f)) { | ||||
| ▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines | |||||