Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/light/light.h
| Show First 20 Lines • Show All 641 Lines • ▼ Show 20 Lines | if (longest_edge_squared > distance_to_plane * distance_to_plane) { | ||||
| const float solid_angle = alpha + beta + gamma - M_PI_F; | const float solid_angle = alpha + beta + gamma - M_PI_F; | ||||
| /* pdf_triangles is calculated over triangle area, but we're not sampling over its area */ | /* pdf_triangles is calculated over triangle area, but we're not sampling over its area */ | ||||
| if (UNLIKELY(solid_angle == 0.0f)) { | if (UNLIKELY(solid_angle == 0.0f)) { | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| else { | else { | ||||
| float area = 1.0f; | float area = 1.0f; | ||||
| if (!kernel_data.integrator.use_light_tree) { | |||||
| if (has_motion) { | if (has_motion) { | ||||
| /* get the center frame vertices, this is what the PDF was calculated from */ | /* get the center frame vertices, this is what the PDF was calculated from */ | ||||
| triangle_world_space_vertices(kg, sd->object, sd->prim, -1.0f, V); | triangle_world_space_vertices(kg, sd->object, sd->prim, -1.0f, V); | ||||
| area = triangle_area(V[0], V[1], V[2]); | area = triangle_area(V[0], V[1], V[2]); | ||||
| } | } | ||||
| else { | else { | ||||
| area = 0.5f * len(N); | area = 0.5f * len(N); | ||||
| } | } | ||||
| const float pdf = area * kernel_data.integrator.pdf_triangles; | } | ||||
| float pdf = area * kernel_data.integrator.pdf_triangles; | |||||
| return pdf / solid_angle; | return pdf / solid_angle; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| float pdf = triangle_light_pdf_area(kg, sd->Ng, sd->I, t); | float pdf = triangle_light_pdf_area(kg, sd->Ng, sd->I, t); | ||||
| if (has_motion) { | |||||
| const float area = 0.5f * len(N); | const float area = 0.5f * len(N); | ||||
| if (UNLIKELY(area == 0.0f)) { | if (UNLIKELY(area == 0.0f)) { | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| if (area != 0.0f) { | |||||
| /* scale the PDF. | /* scale the PDF. | ||||
| * area = the area the sample was taken from | * area = the area the sample was taken from | ||||
| * area_pre = the are from which pdf_triangles was calculated from */ | * area_pre = the are from which pdf_triangles was calculated from */ | ||||
| triangle_world_space_vertices(kg, sd->object, sd->prim, -1.0f, V); | if (has_motion) { | ||||
| const float area_pre = triangle_area(V[0], V[1], V[2]); | triangle_world_space_vertices(kg, sd->object, sd->prim, sd->time, V); | ||||
| pdf = pdf * area_pre / area; | const float area_pre = (kernel_data.integrator.use_light_tree) ? | ||||
| 1.0f : | |||||
| triangle_area(V[0], V[1], V[2]); | |||||
| pdf *= area_pre / area; | |||||
| } | |||||
| else if (kernel_data.integrator.use_light_tree) { | |||||
| pdf /= area; | |||||
| } | } | ||||
| } | |||||
| return pdf; | return pdf; | ||||
| } | } | ||||
| } | } | ||||
| template<bool in_volume_segment> | template<bool in_volume_segment> | ||||
| ccl_device_forceinline void triangle_light_sample(KernelGlobals kg, | ccl_device_forceinline void triangle_light_sample(KernelGlobals kg, | ||||
| int prim, | int prim, | ||||
| int object, | int object, | ||||
| ▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | if (UNLIKELY(solid_angle == 0.0f)) { | ||||
| return; | return; | ||||
| } | } | ||||
| else { | else { | ||||
| if (has_motion) { | if (has_motion) { | ||||
| /* get the center frame vertices, this is what the PDF was calculated from */ | /* get the center frame vertices, this is what the PDF was calculated from */ | ||||
| triangle_world_space_vertices(kg, object, prim, -1.0f, V); | triangle_world_space_vertices(kg, object, prim, -1.0f, V); | ||||
| area = triangle_area(V[0], V[1], V[2]); | area = triangle_area(V[0], V[1], V[2]); | ||||
| } | } | ||||
| if (kernel_data.integrator.use_light_tree) { | |||||
| area = 1.0f; | |||||
| } | |||||
| const float pdf = area * kernel_data.integrator.pdf_triangles; | const float pdf = area * kernel_data.integrator.pdf_triangles; | ||||
| ls->pdf = pdf / solid_angle; | ls->pdf = pdf / solid_angle; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* compute random point in triangle. From Eric Heitz's "A Low-Distortion Map Between Triangle | /* compute random point in triangle. From Eric Heitz's "A Low-Distortion Map Between Triangle | ||||
| * and Square" */ | * and Square" */ | ||||
| float u = randu; | float u = randu; | ||||
| float v = randv; | float v = randv; | ||||
| if (v > u) { | if (v > u) { | ||||
| u *= 0.5f; | u *= 0.5f; | ||||
| v -= u; | v -= u; | ||||
| } | } | ||||
| else { | else { | ||||
| v *= 0.5f; | v *= 0.5f; | ||||
| u -= v; | u -= v; | ||||
| } | } | ||||
| const float t = 1.0f - u - v; | const float t = 1.0f - u - v; | ||||
| ls->P = u * V[0] + v * V[1] + t * V[2]; | ls->P = u * V[0] + v * V[1] + t * V[2]; | ||||
| /* compute incoming direction, distance and pdf */ | /* compute incoming direction, distance and pdf */ | ||||
| ls->D = normalize_len(ls->P - P, &ls->t); | ls->D = normalize_len(ls->P - P, &ls->t); | ||||
| ls->pdf = triangle_light_pdf_area(kg, ls->Ng, -ls->D, ls->t); | ls->pdf = triangle_light_pdf_area(kg, ls->Ng, -ls->D, ls->t); | ||||
| if (has_motion && area != 0.0f) { | if (area != 0.0f) { | ||||
| /* scale the PDF. | /* scale the PDF. | ||||
| * area = the area the sample was taken from | * area = the area the sample was taken from | ||||
| * area_pre = the are from which pdf_triangles was calculated from */ | * area_pre = the are from which pdf_triangles was calculated from */ | ||||
| if (has_motion) { | |||||
| triangle_world_space_vertices(kg, object, prim, -1.0f, V); | triangle_world_space_vertices(kg, object, prim, -1.0f, V); | ||||
| const float area_pre = triangle_area(V[0], V[1], V[2]); | const float area_pre = (kernel_data.integrator.use_light_tree) ? | ||||
| 1.0f : | |||||
| triangle_area(V[0], V[1], V[2]); | |||||
| ls->pdf = ls->pdf * area_pre / area; | ls->pdf = ls->pdf * area_pre / area; | ||||
| } | } | ||||
| else if (kernel_data.integrator.use_light_tree) { | |||||
| ls->pdf = ls->pdf / area; | |||||
| } | |||||
| } | |||||
| ls->u = u; | ls->u = u; | ||||
| ls->v = v; | ls->v = v; | ||||
| } | } | ||||
| } | } | ||||
| /* Light Distribution */ | /* Light Distribution */ | ||||
| ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *randu) | ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *randu) | ||||
| ▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines | |||||