Skip to content

Commit

Permalink
Exposure: simplify hydra-USD mapping
Browse files Browse the repository at this point in the history
...by making exposure hydra attribute map to exposure USD attribute,
and exposureScale map to ComputeLinearExposureScale.

This means that existing render delegates that already query exposure
will not get the more advanced behavior "for free", and will need to be
updated to query exposureScale instead, but should lessen future
confusion and potential bugs.
  • Loading branch information
pmolodo committed Dec 10, 2024
1 parent 43b89cd commit 8faf7ff
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 72 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.15)

project(usd)

Expand Down
16 changes: 8 additions & 8 deletions pxr/imaging/hd/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ HdCamera::HdCamera(SdfPath const &id)
, _shutterOpen(0.0)
, _shutterClose(0.0)
, _exposure(0.0f)
, _exposureCompensation(0.0f)
, _exposureTime(1.0f)
, _exposureIso(100.0f)
, _exposureFStop(1.0f)
, _exposureResponsivity(1.0f)
, _exposureScale(0.0f)
, _lensDistortionType(HdCameraTokens->standard)
, _lensDistortionK1(0.0f)
, _lensDistortionK2(0.0f)
Expand Down Expand Up @@ -243,13 +243,6 @@ HdCamera::Sync(HdSceneDelegate * sceneDelegate,
_exposure = vExposure.Get<float>();
}

const VtValue vExposureCompensation =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->exposureCompensation);
if (!vExposureCompensation.IsEmpty()) {
_exposureCompensation = vExposureCompensation.Get<float>();
}

const VtValue vExposureTime =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->exposureTime);
Expand Down Expand Up @@ -278,6 +271,13 @@ HdCamera::Sync(HdSceneDelegate * sceneDelegate,
_exposureResponsivity = vExposureResponsivity.Get<float>();
}

const VtValue vExposureScale =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->exposureScale);
if (!vExposureScale.IsEmpty()) {
_exposureScale = vExposureScale.Get<float>();
}

const VtValue vLensDistortionType =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->lensDistortionType);
Expand Down
23 changes: 17 additions & 6 deletions pxr/imaging/hd/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PXR_NAMESPACE_OPEN_SCOPE
(exposureIso) \
(exposureFStop) \
(exposureResponsivity) \
(exposureCompensation) \
(exposureScale) \
\
/* how to match window with different aspect */ \
(windowPolicy) \
Expand Down Expand Up @@ -241,15 +241,26 @@ class HdCamera : public HdSprim
return _shutterClose;
}

/// Get the computed exposure scale from the underlying camera.
/// Get the raw exposure exponent value.
///
/// Scaling the image brightness by this value will cause the various exposure
/// controls on \ref UsdGeomCamera to behave like those of a real camera to
/// control the exposure of the image.
/// This the same as the value stored in the exposure attribute on the
/// underlying camera. Note that in most cases, you will want to use
/// GetExposureScale() instead of this method, as it is the computed
/// end result of all related exposure attributes.
/// GetExposure() is retained as-is for backward compatibility.
float GetExposure() const {
return _exposure;
}

/// Get the computed linear exposure scale from the underlying camera.
///
/// Scaling the image brightness by this value will cause the various
/// exposure controls on \ref UsdGeomCamera to behave like those of a real
/// camera to control the exposure of the image.
float GetExposureScale() const {
return _exposureScale;
}

TfToken GetLensDistortionType() const {
return _lensDistortionType;
}
Expand Down Expand Up @@ -329,11 +340,11 @@ class HdCamera : public HdSprim

// exposure
float _exposure;
float _exposureCompensation;
float _exposureTime;
float _exposureIso;
float _exposureFStop;
float _exposureResponsivity;
float _exposureScale;

// lens distortion
TfToken _lensDistortionType;
Expand Down
24 changes: 12 additions & 12 deletions pxr/imaging/hd/cameraSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ HdCameraSchema::GetExposureResponsivity() const
}

HdFloatDataSourceHandle
HdCameraSchema::GetExposureCompensation() const
HdCameraSchema::GetExposureScale() const
{
return _GetTypedDataSource<HdFloatDataSource>(
HdCameraSchemaTokens->exposureCompensation);
HdCameraSchemaTokens->exposureScale);
}

HdBoolDataSourceHandle
Expand Down Expand Up @@ -213,7 +213,7 @@ HdCameraSchema::BuildRetained(
const HdFloatDataSourceHandle &exposureIso,
const HdFloatDataSourceHandle &exposureFStop,
const HdFloatDataSourceHandle &exposureResponsivity,
const HdFloatDataSourceHandle &exposureCompensation,
const HdFloatDataSourceHandle &exposureScale,
const HdBoolDataSourceHandle &focusOn,
const HdFloatDataSourceHandle &dofAspect,
const HdContainerDataSourceHandle &splitDiopter,
Expand Down Expand Up @@ -311,9 +311,9 @@ HdCameraSchema::BuildRetained(
_values[_count++] = exposureResponsivity;
}

if (exposureCompensation) {
_names[_count] = HdCameraSchemaTokens->exposureCompensation;
_values[_count++] = exposureCompensation;
if (exposureScale) {
_names[_count] = HdCameraSchemaTokens->exposureScale;
_values[_count++] = exposureScale;
}

if (focusOn) {
Expand Down Expand Up @@ -480,10 +480,10 @@ HdCameraSchema::Builder::SetExposureResponsivity(
}

HdCameraSchema::Builder &
HdCameraSchema::Builder::SetExposureCompensation(
const HdFloatDataSourceHandle &exposureCompensation)
HdCameraSchema::Builder::SetExposureScale(
const HdFloatDataSourceHandle &exposureScale)
{
_exposureCompensation = exposureCompensation;
_exposureScale = exposureScale;
return *this;
}

Expand Down Expand Up @@ -548,7 +548,7 @@ HdCameraSchema::Builder::Build()
_exposureIso,
_exposureFStop,
_exposureResponsivity,
_exposureCompensation,
_exposureScale,
_focusOn,
_dofAspect,
_splitDiopter,
Expand Down Expand Up @@ -656,11 +656,11 @@ HdCameraSchema::GetExposureResponsivityLocator()

/* static */
const HdDataSourceLocator &
HdCameraSchema::GetExposureCompensationLocator()
HdCameraSchema::GetExposureScaleLocator()
{
static const HdDataSourceLocator locator =
GetDefaultLocator().Append(
HdCameraSchemaTokens->exposureCompensation);
HdCameraSchemaTokens->exposureScale);
return locator;
}

Expand Down
16 changes: 8 additions & 8 deletions pxr/imaging/hd/cameraSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PXR_NAMESPACE_OPEN_SCOPE
(exposureIso) \
(exposureFStop) \
(exposureResponsivity) \
(exposureCompensation) \
(exposureScale) \
(focusOn) \
(dofAspect) \
(splitDiopter) \
Expand Down Expand Up @@ -147,7 +147,7 @@ class HdCameraSchema : public HdSchema
HdFloatDataSourceHandle GetExposureResponsivity() const;

HD_API
HdFloatDataSourceHandle GetExposureCompensation() const;
HdFloatDataSourceHandle GetExposureScale() const;

HD_API
HdBoolDataSourceHandle GetFocusOn() const;
Expand Down Expand Up @@ -218,9 +218,9 @@ class HdCameraSchema : public HdSchema
HD_API
static const HdDataSourceLocator &GetExposureResponsivityLocator();

/// Prim-level relative data source locator to locate exposureCompensation.
/// Prim-level relative data source locator to locate exposureScale.
HD_API
static const HdDataSourceLocator &GetExposureCompensationLocator();
static const HdDataSourceLocator &GetExposureScaleLocator();

/// Prim-level relative data source locator to locate namespacedProperties.
HD_API
Expand Down Expand Up @@ -257,7 +257,7 @@ class HdCameraSchema : public HdSchema
const HdFloatDataSourceHandle &exposureIso,
const HdFloatDataSourceHandle &exposureFStop,
const HdFloatDataSourceHandle &exposureResponsivity,
const HdFloatDataSourceHandle &exposureCompensation,
const HdFloatDataSourceHandle &exposureScale,
const HdBoolDataSourceHandle &focusOn,
const HdFloatDataSourceHandle &dofAspect,
const HdContainerDataSourceHandle &splitDiopter,
Expand Down Expand Up @@ -326,8 +326,8 @@ class HdCameraSchema : public HdSchema
Builder &SetExposureResponsivity(
const HdFloatDataSourceHandle &exposureResponsivity);
HD_API
Builder &SetExposureCompensation(
const HdFloatDataSourceHandle &exposureCompensation);
Builder &SetExposureScale(
const HdFloatDataSourceHandle &exposureScale);
HD_API
Builder &SetFocusOn(
const HdBoolDataSourceHandle &focusOn);
Expand Down Expand Up @@ -366,7 +366,7 @@ class HdCameraSchema : public HdSchema
HdFloatDataSourceHandle _exposureIso;
HdFloatDataSourceHandle _exposureFStop;
HdFloatDataSourceHandle _exposureResponsivity;
HdFloatDataSourceHandle _exposureCompensation;
HdFloatDataSourceHandle _exposureScale;
HdBoolDataSourceHandle _focusOn;
HdFloatDataSourceHandle _dofAspect;
HdContainerDataSourceHandle _splitDiopter;
Expand Down
2 changes: 1 addition & 1 deletion pxr/imaging/hd/dataSourceLegacyPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ class Hd_DataSourceCamera : public HdContainerDataSource
HdCameraSchemaTokens->exposureIso,
HdCameraSchemaTokens->exposureFStop,
HdCameraSchemaTokens->exposureResponsivity,
HdCameraSchemaTokens->exposureCompensation,
HdCameraSchemaTokens->exposureScale,
HdCameraSchemaTokens->focusOn,
HdCameraSchemaTokens->dofAspect,
HdCameraSchemaTokens->splitDiopter,
Expand Down
2 changes: 1 addition & 1 deletion pxr/imaging/hd/hdSchemaDefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@
('exposureIso', T_FLOAT, dict(ADD_LOCATOR = True)),
('exposureFStop', T_FLOAT, dict(ADD_LOCATOR = True)),
('exposureResponsivity', T_FLOAT, dict(ADD_LOCATOR = True)),
('exposureCompensation', T_FLOAT, dict(ADD_LOCATOR = True)),
('exposureScale', T_FLOAT, dict(ADD_LOCATOR = True)),
('focusOn', T_BOOL, {}),
('dofAspect', T_FLOAT, {}),
('splitDiopter', 'HdSplitDiopterSchema', {}),
Expand Down
6 changes: 3 additions & 3 deletions pxr/usd/usdGeom/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,15 @@ UsdGeomCamera::ComputeLinearExposureScale(UsdTimeCode time) const
float exposureIso = 100.0f;
float exposureFStop = 1.0f;
float exposureResponsivity = 1.0f;
float exposureCompensation = 0.0f;
float exposureExponent = 0.0f;

GetExposureTimeAttr().Get(&exposureTime, time);
GetExposureIsoAttr().Get(&exposureIso, time);
GetExposureFStopAttr().Get(&exposureFStop, time);
GetExposureResponsivityAttr().Get(&exposureResponsivity, time);
GetExposureAttr().Get(&exposureCompensation, time);
GetExposureAttr().Get(&exposureExponent, time);

return (exposureTime * exposureIso * powf(2.0f, exposureCompensation) *
return (exposureTime * exposureIso * powf(2.0f, exposureExponent) *
exposureResponsivity) / (100.0f * exposureFStop * exposureFStop);
}

Expand Down
19 changes: 8 additions & 11 deletions pxr/usdImaging/usdImaging/cameraAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,11 @@ UsdImagingCameraAdapter::Get(UsdPrim const& prim,
cam.GetShutterCloseAttr().Get(&vShutterClose, time); // conversion n/a
return vShutterClose;
} else if (key == HdCameraTokens->exposure) {
// we hijack the "exposure" token here in order to pass through the
// calculated exposure and make it backwards-compatible.
// existing clients will be expecting it as logarithmic exposure,
// so we need to convert from a scalar multiplier to logarithmic
// exposure here. To get the original exposure attribute value,
// see "exposureCompensation" below.
return VtValue(log2(cam.ComputeLinearExposureScale(time)));
// The raw exponential compensation attribute.
// See "exposureScale" below for the computed linear multiplier ratio.
VtValue vExposureExponent;
cam.GetExposureAttr().Get(&vExposureExponent, time); // conversion n/a
return vExposureExponent;
} else if (key == HdCameraTokens->exposureTime) {
VtValue vExposureTime;
cam.GetExposureTimeAttr().Get(&vExposureTime, time); // conversion n/a
Expand All @@ -265,10 +263,9 @@ UsdImagingCameraAdapter::Get(UsdPrim const& prim,
VtValue vExposureResponsivity;
cam.GetExposureResponsivityAttr().Get(&vExposureResponsivity, time); // conversion n/a
return vExposureResponsivity;
} else if (key == HdCameraTokens->exposureCompensation) {
VtValue vExposureCompensation;
cam.GetExposureAttr().Get(&vExposureCompensation, time); // conversion n/a
return vExposureCompensation;
} else if (key == HdCameraTokens->exposureScale) {
// The computed linear exposure multiplier ratio
return VtValue(log2(cam.ComputeLinearExposureScale(time)));
}

VtValue v;
Expand Down
35 changes: 14 additions & 21 deletions pxr/usdImaging/usdImaging/dataSourceCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class _CameraExposureScaleDataSource
, _usdCamera(usdCamera)
, _stageGlobals(stageGlobals)
{
static const HdDataSourceLocator exposureLocator =
HdCameraSchema::GetExposureLocator();
static const HdDataSourceLocator exposureScaleLocator =
HdCameraSchema::exposureScaleLocator();

static const std::vector<TfToken> inputNames = {
UsdGeomTokens->exposure,
Expand All @@ -141,7 +141,7 @@ class _CameraExposureScaleDataSource
prim.GetAttribute(inputName),
_stageGlobals,
_sceneIndexPath,
exposureLocator));
exposureScaleLocator));
}
}

Expand All @@ -156,11 +156,7 @@ class _CameraExposureScaleDataSource
if (time.IsNumeric()) {
time = UsdTimeCode(time.GetValue() + shutterOffset);
}
// existing clients will be expecting it as logarithmic exposure,
// so we need to convert from a scalar multiplier to logarithmic
// exposure here. To get the original exposure attribute value,
// see "exposureCompensation" below.
return log2f(_usdCamera.ComputeLinearExposureScale(time));
return _usdCamera.ComputeLinearExposureScale(time);
}

bool GetContributingSampleTimesForInterval(
Expand Down Expand Up @@ -207,9 +203,7 @@ UsdImagingDataSourceCamera::GetNames()
HdDataSourceBaseHandle
UsdImagingDataSourceCamera::Get(const TfToken &name)
{
if (name == HdCameraSchemaTokens->exposure) {
// we hijack the "exposure" token here in order to pass through the
// calculated exposure and make it backwards-compatible.
if (name == HdCameraSchemaTokens->exposureScale) {
return _CameraExposureScaleDataSource::New(
_sceneIndexPath, _usdCamera, _stageGlobals);
}
Expand Down Expand Up @@ -336,38 +330,37 @@ UsdImagingDataSourceCameraPrim::Invalidate(
locators.insert(
HdCameraSchema::GetShutterCloseLocator());
} else if (usdName == UsdGeomTokens->exposure) {
// The USD "exposure" attr is mapped to hydra as
// "exposureCompensation", but is also an input to the
// computed value stored at "exposure".
locators.insert(
HdCameraSchema::GetExposureCompensationLocator());
// "exposure" maps unchanged to "exposure", and is an
// input to the computed value stored at "exposureScale"
locators.insert(
HdCameraSchema::GetExposureLocator());
locators.insert(
HdCameraSchema::GetExposureScaleLocator());
} else if (usdName == UsdGeomTokens->exposureTime) {
// "exposure:time" maps to "exposureTime", and is an
// input to "exposure"
// input to the computed value stored at "exposureScale"
locators.insert(
HdCameraSchema::GetExposureTimeLocator());
locators.insert(
HdCameraSchema::GetExposureLocator());
HdCameraSchema::GetExposureScaleLocator());
} else if (usdName == UsdGeomTokens->exposureIso) {
// similar to exposureTime
locators.insert(
HdCameraSchema::GetExposureIsoLocator());
locators.insert(
HdCameraSchema::GetExposureLocator());
HdCameraSchema::GetExposureScaleLocator());
} else if (usdName == UsdGeomTokens->exposureFStop) {
// similar to exposureTime
locators.insert(
HdCameraSchema::GetExposureFStopLocator());
locators.insert(
HdCameraSchema::GetExposureLocator());
HdCameraSchema::GetExposureScaleLocator());
} else if (usdName == UsdGeomTokens->exposureResponsivity) {
// similar to exposureTime
locators.insert(
HdCameraSchema::GetExposureResponsivityLocator());
locators.insert(
HdCameraSchema::GetExposureLocator());
HdCameraSchema::GetExposureScaleLocator());
} else {
locators.insert(
HdCameraSchema::GetDefaultLocator().Append(
Expand Down

0 comments on commit 8faf7ff

Please sign in to comment.