Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/scene/light.cpp
| Show First 20 Lines • Show All 1,032 Lines • ▼ Show 20 Lines | else if (light->light_type == LIGHT_AREA) { | ||||
| float3 axis_v = normalize_len(extentv, &len_v); | float3 axis_v = normalize_len(extentv, &len_v); | ||||
| float area = len_u * len_v; | float area = len_u * len_v; | ||||
| if (light->round) { | if (light->round) { | ||||
| area *= -M_PI_4_F; | area *= -M_PI_4_F; | ||||
| } | } | ||||
| float invarea = (area != 0.0f) ? 1.0f / area : 1.0f; | float invarea = (area != 0.0f) ? 1.0f / area : 1.0f; | ||||
| float3 dir = light->dir; | float3 dir = light->dir; | ||||
| /* Convert from spread angle 0..180 to 90..0, clamping to a minimum | /* Clamping to a minimum angle to avoid excessive noise. */ | ||||
| * angle to avoid excessive noise. */ | const float min_spread = 1.0f * M_PI_F / 180.0f; | ||||
| const float min_spread_angle = 1.0f * M_PI_F / 180.0f; | const float half_spread = 0.5f * max(light->spread, min_spread); | ||||
| const float spread_angle = 0.5f * (M_PI_F - max(light->spread, min_spread_angle)); | /* cot_half_spread is h in D10594#269626 */ | ||||
| const float cot_half_spread = tanf(M_PI_2_F - half_spread); | |||||
| /* Normalization computed using: | /* Normalization computed using: | ||||
| * integrate cos(x) * (1 - tan(x) * tan(a)) * sin(x) from x = 0 to pi/2 - a. */ | * integrate cos(x) * (1 - tan(x) / tan(a)) * sin(x) from x = 0 to a, a being half_spread */ | ||||
| const float tan_spread = tanf(spread_angle); | const float normalize_spread = 1.0f / (1.0f - half_spread * cot_half_spread); | ||||
| const float normalize_spread = 2.0f / (2.0f + (2.0f * spread_angle - M_PI_F) * tan_spread); | |||||
| dir = safe_normalize(dir); | dir = safe_normalize(dir); | ||||
| if (light->use_mis && area != 0.0f) | if (light->use_mis && area != 0.0f) | ||||
| shader_id |= SHADER_USE_MIS; | shader_id |= SHADER_USE_MIS; | ||||
| klights[light_index].co = co; | klights[light_index].co = co; | ||||
| klights[light_index].area.axis_u = axis_u; | klights[light_index].area.axis_u = axis_u; | ||||
| klights[light_index].area.len_u = len_u; | klights[light_index].area.len_u = len_u; | ||||
| klights[light_index].area.axis_v = axis_v; | klights[light_index].area.axis_v = axis_v; | ||||
| klights[light_index].area.len_v = len_v; | klights[light_index].area.len_v = len_v; | ||||
| klights[light_index].area.invarea = invarea; | klights[light_index].area.invarea = invarea; | ||||
| klights[light_index].area.dir = dir; | klights[light_index].area.dir = dir; | ||||
| klights[light_index].area.tan_spread = tan_spread; | klights[light_index].area.cot_half_spread = cot_half_spread; | ||||
| klights[light_index].area.normalize_spread = normalize_spread; | klights[light_index].area.normalize_spread = normalize_spread; | ||||
| } | } | ||||
| else if (light->light_type == LIGHT_SPOT) { | else if (light->light_type == LIGHT_SPOT) { | ||||
| shader_id &= ~SHADER_AREA_LIGHT; | shader_id &= ~SHADER_AREA_LIGHT; | ||||
| float radius = light->size; | float radius = light->size; | ||||
| float invarea = (radius > 0.0f) ? 1.0f / (M_PI_F * radius * radius) : 1.0f; | float invarea = (radius > 0.0f) ? 1.0f / (M_PI_F * radius * radius) : 1.0f; | ||||
| float cos_half_spot_angle = cosf(light->spot_angle * 0.5f); | float cos_half_spot_angle = cosf(light->spot_angle * 0.5f); | ||||
| ▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines | |||||