Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/light/light.h
| Context not available. | |||||
| ls->P = make_float3(klight->co[0], klight->co[1], klight->co[2]); | ls->P = make_float3(klight->co[0], klight->co[1], klight->co[2]); | ||||
| if (type == LIGHT_SPOT) { | 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]); | ||||
| float radius = klight->spot.radius; | 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) | if (radius > 0.0f) | ||||
| /* sphere light */ | /* disk light */ | ||||
| ls->P += disk_light_sample(ls->Ng, randu, randv) * radius; | 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); | 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->eval_fac = (0.25f * M_1_PI_F) * invarea; | ||||
| ls->pdf = invarea; | |||||
| /* spot light attenuation */ | /* spot light attenuation */ | ||||
| ls->eval_fac *= 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) { | if (!in_volume_segment && ls->eval_fac == 0.0f) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| Context not available. | |||||
| 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, lightN, -ls->D, ls->t); | ||||
| } | } | ||||
| else if (type == LIGHT_POINT) { | else if (type == LIGHT_POINT) { | ||||
| float3 center = make_float3(klight->co[0], klight->co[1], klight->co[2]); | float3 center = make_float3(klight->co[0], klight->co[1], klight->co[2]); | ||||
| float radius = klight->spot.radius; | float radius = klight->spot.radius; | ||||
| /* disk oriented normal */ | |||||
| const float3 lightN = normalize(P - center); | |||||
| ls->P = center; | ls->P = center; | ||||
| float pdf = 1.0; | |||||
| if (radius > 0.0f) { | if (radius > 0.0f) { | ||||
| ls->Ng = normalize(P - center); | ls->P += disk_light_sample(lightN, randu, randv) * radius; | ||||
| 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->pdf = klight->spot.invarea; | |||||
| ls->D = normalize_len(ls->P - P, &ls->t); | 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; | 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); | 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, lightN, -ls->D, ls->t); | ||||
| } | } | ||||
| else { | else { | ||||
| /* area light */ | /* area light */ | ||||
| Context not available. | |||||
| if (type == LIGHT_SPOT) { | if (type == LIGHT_SPOT) { | ||||
| /* Spot/Disk light. */ | /* 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 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; | const float radius = klight->spot.radius; | ||||
| if (radius == 0.0f) { | if (radius == 0.0f) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* disk oriented normal */ | |||||
| const float3 lightN = normalize(ray_P - lightP); | |||||
| /* One sided. */ | /* One sided. */ | ||||
| if (dot(ray->D, lightN) >= 0.0f) { | if (dot(ray->D, lightN) >= 0.0f) { | ||||
| continue; | continue; | ||||
| Context not available. | |||||
| continue; | continue; | ||||
| } | } | ||||
| /* disk oriented normal */ | |||||
| const float3 lightN = normalize(ray_P - lightP); | |||||
| float3 P; | float3 P; | ||||
| const float3 lsN = normalize(ray_P - lightP); | if (!ray_disk_intersect(ray->P, ray->D, ray->t, lightP, lightN, radius, &P, &t)) { | ||||
| if (!ray_disk_intersect(ray->P, ray->D, ray->t, lightP, lsN, radius, &P, &t)) { | |||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| ls->D = ray_D; | ls->D = ray_D; | ||||
| if (type == LIGHT_SPOT) { | 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; | float invarea = klight->spot.invarea; | ||||
| ls->eval_fac = (0.25f * M_1_PI_F) * invarea; | ls->eval_fac = (0.25f * M_1_PI_F) * invarea; | ||||
| Context not available. | |||||
| /* spot light attenuation */ | /* spot light attenuation */ | ||||
| ls->eval_fac *= 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) { | if (ls->eval_fac == 0.0f) { | ||||
| return false; | return false; | ||||
| Context not available. | |||||
| /* compute pdf */ | /* compute pdf */ | ||||
| if (ls->t != FLT_MAX) | 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) { | 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); | |||||
| ls->Ng = 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; | float invarea = klight->spot.invarea; | ||||
| 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 (ls->eval_fac == 0.0f) { | |||||
| 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; | ||||
| /* compute pdf */ | /* compute pdf */ | ||||
| if (ls->t != FLT_MAX) | 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 | else | ||||
| ls->pdf = 0.f; | ls->pdf = 0.f; | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| No newline at end of file | |||||
| Context not available. | |||||