USD: improve light units conversion #109795

Manually merged
Brecht Van Lommel merged 4 commits from brecht/blender:usd-light-units into main 2023-07-07 18:27:19 +02:00
3 changed files with 26 additions and 7 deletions
Showing only changes of commit d417968af2 - Show all commits

View File

@ -94,8 +94,14 @@ void HdCyclesLight::Sync(HdSceneDelegate *sceneDelegate,
strength *= value.Get<float>();
}
/* Convert from intensity to radiant flux. */
strength *= M_PI;
if (_lightType == HdPrimTypeTokens->distantLight) {
/* Unclear why, but approximately matches Karma. */
strength *= 4.0f;
}
else {
/* Convert from intensity to radiant flux. */
strength *= M_PI;
}
value = sceneDelegate->GetLightParamValue(id, HdLightTokens->normalize);
_light->set_normalize(value.IsHolding<bool>() && value.UncheckedGet<bool>());

View File

@ -80,8 +80,14 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime
if (pxr::UsdAttribute intensity_attr = light_api.GetIntensityAttr()) {
float intensity = 0.0f;
if (intensity_attr.Get(&intensity, motionSampleTime)) {
/* Convert from intensity to radiant flux. */
blight->energy = intensity * M_PI;
if (blight->type == LA_SUN) {
/* Unclear why, but approximately matches Karma. */
blight->energy = intensity * 4.0f;
}
else {
/* Convert from intensity to radiant flux. */
blight->energy = intensity * M_PI;
}
blight->energy *= this->import_params_.light_intensity_scale;
}
}

View File

@ -40,9 +40,6 @@ void USDLightWriter::do_write(HierarchyContext &context)
#endif
/* Convert from radiant flux to intensity. */
float usd_intensity = light->energy / M_PI;
switch (light->type) {
case LA_AREA:
switch (light->area_shape) {
@ -105,6 +102,16 @@ void USDLightWriter::do_write(HierarchyContext &context)
BLI_assert_msg(0, "is_supported() returned true for unsupported light type");
}
float usd_intensity;
if (light->type == LA_SUN) {
/* Unclear why, but approximately matches Karma. */
usd_intensity = light->energy / 4.0f;
}
else {
/* Convert from radiant flux to intensity. */
usd_intensity = light->energy / M_PI;
}
usd_light_api.CreateIntensityAttr().Set(usd_intensity, timecode);
usd_light_api.CreateColorAttr().Set(pxr::GfVec3f(light->r, light->g, light->b), timecode);
usd_light_api.CreateSpecularAttr().Set(light->spec_fac, timecode);