Skip to content

Commit 8faf7ff

Browse files
committed
Exposure: simplify hydra-USD mapping
...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.
1 parent 43b89cd commit 8faf7ff

File tree

10 files changed

+73
-72
lines changed

10 files changed

+73
-72
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.15)
22

33
project(usd)
44

pxr/imaging/hd/camera.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ HdCamera::HdCamera(SdfPath const &id)
4141
, _shutterOpen(0.0)
4242
, _shutterClose(0.0)
4343
, _exposure(0.0f)
44-
, _exposureCompensation(0.0f)
4544
, _exposureTime(1.0f)
4645
, _exposureIso(100.0f)
4746
, _exposureFStop(1.0f)
4847
, _exposureResponsivity(1.0f)
48+
, _exposureScale(0.0f)
4949
, _lensDistortionType(HdCameraTokens->standard)
5050
, _lensDistortionK1(0.0f)
5151
, _lensDistortionK2(0.0f)
@@ -243,13 +243,6 @@ HdCamera::Sync(HdSceneDelegate * sceneDelegate,
243243
_exposure = vExposure.Get<float>();
244244
}
245245

246-
const VtValue vExposureCompensation =
247-
sceneDelegate->GetCameraParamValue(
248-
id, HdCameraTokens->exposureCompensation);
249-
if (!vExposureCompensation.IsEmpty()) {
250-
_exposureCompensation = vExposureCompensation.Get<float>();
251-
}
252-
253246
const VtValue vExposureTime =
254247
sceneDelegate->GetCameraParamValue(
255248
id, HdCameraTokens->exposureTime);
@@ -278,6 +271,13 @@ HdCamera::Sync(HdSceneDelegate * sceneDelegate,
278271
_exposureResponsivity = vExposureResponsivity.Get<float>();
279272
}
280273

274+
const VtValue vExposureScale =
275+
sceneDelegate->GetCameraParamValue(
276+
id, HdCameraTokens->exposureScale);
277+
if (!vExposureScale.IsEmpty()) {
278+
_exposureScale = vExposureScale.Get<float>();
279+
}
280+
281281
const VtValue vLensDistortionType =
282282
sceneDelegate->GetCameraParamValue(
283283
id, HdCameraTokens->lensDistortionType);

pxr/imaging/hd/camera.h

+17-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PXR_NAMESPACE_OPEN_SCOPE
6161
(exposureIso) \
6262
(exposureFStop) \
6363
(exposureResponsivity) \
64-
(exposureCompensation) \
64+
(exposureScale) \
6565
\
6666
/* how to match window with different aspect */ \
6767
(windowPolicy) \
@@ -241,15 +241,26 @@ class HdCamera : public HdSprim
241241
return _shutterClose;
242242
}
243243

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

255+
/// Get the computed linear exposure scale from the underlying camera.
256+
///
257+
/// Scaling the image brightness by this value will cause the various
258+
/// exposure controls on \ref UsdGeomCamera to behave like those of a real
259+
/// camera to control the exposure of the image.
260+
float GetExposureScale() const {
261+
return _exposureScale;
262+
}
263+
253264
TfToken GetLensDistortionType() const {
254265
return _lensDistortionType;
255266
}
@@ -329,11 +340,11 @@ class HdCamera : public HdSprim
329340

330341
// exposure
331342
float _exposure;
332-
float _exposureCompensation;
333343
float _exposureTime;
334344
float _exposureIso;
335345
float _exposureFStop;
336346
float _exposureResponsivity;
347+
float _exposureScale;
337348

338349
// lens distortion
339350
TfToken _lensDistortionType;

pxr/imaging/hd/cameraSchema.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ HdCameraSchema::GetExposureResponsivity() const
152152
}
153153

154154
HdFloatDataSourceHandle
155-
HdCameraSchema::GetExposureCompensation() const
155+
HdCameraSchema::GetExposureScale() const
156156
{
157157
return _GetTypedDataSource<HdFloatDataSource>(
158-
HdCameraSchemaTokens->exposureCompensation);
158+
HdCameraSchemaTokens->exposureScale);
159159
}
160160

161161
HdBoolDataSourceHandle
@@ -213,7 +213,7 @@ HdCameraSchema::BuildRetained(
213213
const HdFloatDataSourceHandle &exposureIso,
214214
const HdFloatDataSourceHandle &exposureFStop,
215215
const HdFloatDataSourceHandle &exposureResponsivity,
216-
const HdFloatDataSourceHandle &exposureCompensation,
216+
const HdFloatDataSourceHandle &exposureScale,
217217
const HdBoolDataSourceHandle &focusOn,
218218
const HdFloatDataSourceHandle &dofAspect,
219219
const HdContainerDataSourceHandle &splitDiopter,
@@ -311,9 +311,9 @@ HdCameraSchema::BuildRetained(
311311
_values[_count++] = exposureResponsivity;
312312
}
313313

314-
if (exposureCompensation) {
315-
_names[_count] = HdCameraSchemaTokens->exposureCompensation;
316-
_values[_count++] = exposureCompensation;
314+
if (exposureScale) {
315+
_names[_count] = HdCameraSchemaTokens->exposureScale;
316+
_values[_count++] = exposureScale;
317317
}
318318

319319
if (focusOn) {
@@ -480,10 +480,10 @@ HdCameraSchema::Builder::SetExposureResponsivity(
480480
}
481481

482482
HdCameraSchema::Builder &
483-
HdCameraSchema::Builder::SetExposureCompensation(
484-
const HdFloatDataSourceHandle &exposureCompensation)
483+
HdCameraSchema::Builder::SetExposureScale(
484+
const HdFloatDataSourceHandle &exposureScale)
485485
{
486-
_exposureCompensation = exposureCompensation;
486+
_exposureScale = exposureScale;
487487
return *this;
488488
}
489489

@@ -548,7 +548,7 @@ HdCameraSchema::Builder::Build()
548548
_exposureIso,
549549
_exposureFStop,
550550
_exposureResponsivity,
551-
_exposureCompensation,
551+
_exposureScale,
552552
_focusOn,
553553
_dofAspect,
554554
_splitDiopter,
@@ -656,11 +656,11 @@ HdCameraSchema::GetExposureResponsivityLocator()
656656

657657
/* static */
658658
const HdDataSourceLocator &
659-
HdCameraSchema::GetExposureCompensationLocator()
659+
HdCameraSchema::GetExposureScaleLocator()
660660
{
661661
static const HdDataSourceLocator locator =
662662
GetDefaultLocator().Append(
663-
HdCameraSchemaTokens->exposureCompensation);
663+
HdCameraSchemaTokens->exposureScale);
664664
return locator;
665665
}
666666

pxr/imaging/hd/cameraSchema.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PXR_NAMESPACE_OPEN_SCOPE
5454
(exposureIso) \
5555
(exposureFStop) \
5656
(exposureResponsivity) \
57-
(exposureCompensation) \
57+
(exposureScale) \
5858
(focusOn) \
5959
(dofAspect) \
6060
(splitDiopter) \
@@ -147,7 +147,7 @@ class HdCameraSchema : public HdSchema
147147
HdFloatDataSourceHandle GetExposureResponsivity() const;
148148

149149
HD_API
150-
HdFloatDataSourceHandle GetExposureCompensation() const;
150+
HdFloatDataSourceHandle GetExposureScale() const;
151151

152152
HD_API
153153
HdBoolDataSourceHandle GetFocusOn() const;
@@ -218,9 +218,9 @@ class HdCameraSchema : public HdSchema
218218
HD_API
219219
static const HdDataSourceLocator &GetExposureResponsivityLocator();
220220

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

225225
/// Prim-level relative data source locator to locate namespacedProperties.
226226
HD_API
@@ -257,7 +257,7 @@ class HdCameraSchema : public HdSchema
257257
const HdFloatDataSourceHandle &exposureIso,
258258
const HdFloatDataSourceHandle &exposureFStop,
259259
const HdFloatDataSourceHandle &exposureResponsivity,
260-
const HdFloatDataSourceHandle &exposureCompensation,
260+
const HdFloatDataSourceHandle &exposureScale,
261261
const HdBoolDataSourceHandle &focusOn,
262262
const HdFloatDataSourceHandle &dofAspect,
263263
const HdContainerDataSourceHandle &splitDiopter,
@@ -326,8 +326,8 @@ class HdCameraSchema : public HdSchema
326326
Builder &SetExposureResponsivity(
327327
const HdFloatDataSourceHandle &exposureResponsivity);
328328
HD_API
329-
Builder &SetExposureCompensation(
330-
const HdFloatDataSourceHandle &exposureCompensation);
329+
Builder &SetExposureScale(
330+
const HdFloatDataSourceHandle &exposureScale);
331331
HD_API
332332
Builder &SetFocusOn(
333333
const HdBoolDataSourceHandle &focusOn);
@@ -366,7 +366,7 @@ class HdCameraSchema : public HdSchema
366366
HdFloatDataSourceHandle _exposureIso;
367367
HdFloatDataSourceHandle _exposureFStop;
368368
HdFloatDataSourceHandle _exposureResponsivity;
369-
HdFloatDataSourceHandle _exposureCompensation;
369+
HdFloatDataSourceHandle _exposureScale;
370370
HdBoolDataSourceHandle _focusOn;
371371
HdFloatDataSourceHandle _dofAspect;
372372
HdContainerDataSourceHandle _splitDiopter;

pxr/imaging/hd/dataSourceLegacyPrim.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ class Hd_DataSourceCamera : public HdContainerDataSource
10471047
HdCameraSchemaTokens->exposureIso,
10481048
HdCameraSchemaTokens->exposureFStop,
10491049
HdCameraSchemaTokens->exposureResponsivity,
1050-
HdCameraSchemaTokens->exposureCompensation,
1050+
HdCameraSchemaTokens->exposureScale,
10511051
HdCameraSchemaTokens->focusOn,
10521052
HdCameraSchemaTokens->dofAspect,
10531053
HdCameraSchemaTokens->splitDiopter,

pxr/imaging/hd/hdSchemaDefs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@
10521052
('exposureIso', T_FLOAT, dict(ADD_LOCATOR = True)),
10531053
('exposureFStop', T_FLOAT, dict(ADD_LOCATOR = True)),
10541054
('exposureResponsivity', T_FLOAT, dict(ADD_LOCATOR = True)),
1055-
('exposureCompensation', T_FLOAT, dict(ADD_LOCATOR = True)),
1055+
('exposureScale', T_FLOAT, dict(ADD_LOCATOR = True)),
10561056
('focusOn', T_BOOL, {}),
10571057
('dofAspect', T_FLOAT, {}),
10581058
('splitDiopter', 'HdSplitDiopterSchema', {}),

pxr/usd/usdGeom/camera.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,15 @@ UsdGeomCamera::ComputeLinearExposureScale(UsdTimeCode time) const
643643
float exposureIso = 100.0f;
644644
float exposureFStop = 1.0f;
645645
float exposureResponsivity = 1.0f;
646-
float exposureCompensation = 0.0f;
646+
float exposureExponent = 0.0f;
647647

648648
GetExposureTimeAttr().Get(&exposureTime, time);
649649
GetExposureIsoAttr().Get(&exposureIso, time);
650650
GetExposureFStopAttr().Get(&exposureFStop, time);
651651
GetExposureResponsivityAttr().Get(&exposureResponsivity, time);
652-
GetExposureAttr().Get(&exposureCompensation, time);
652+
GetExposureAttr().Get(&exposureExponent, time);
653653

654-
return (exposureTime * exposureIso * powf(2.0f, exposureCompensation) *
654+
return (exposureTime * exposureIso * powf(2.0f, exposureExponent) *
655655
exposureResponsivity) / (100.0f * exposureFStop * exposureFStop);
656656
}
657657

pxr/usdImaging/usdImaging/cameraAdapter.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,11 @@ UsdImagingCameraAdapter::Get(UsdPrim const& prim,
242242
cam.GetShutterCloseAttr().Get(&vShutterClose, time); // conversion n/a
243243
return vShutterClose;
244244
} else if (key == HdCameraTokens->exposure) {
245-
// we hijack the "exposure" token here in order to pass through the
246-
// calculated exposure and make it backwards-compatible.
247-
// existing clients will be expecting it as logarithmic exposure,
248-
// so we need to convert from a scalar multiplier to logarithmic
249-
// exposure here. To get the original exposure attribute value,
250-
// see "exposureCompensation" below.
251-
return VtValue(log2(cam.ComputeLinearExposureScale(time)));
245+
// The raw exponential compensation attribute.
246+
// See "exposureScale" below for the computed linear multiplier ratio.
247+
VtValue vExposureExponent;
248+
cam.GetExposureAttr().Get(&vExposureExponent, time); // conversion n/a
249+
return vExposureExponent;
252250
} else if (key == HdCameraTokens->exposureTime) {
253251
VtValue vExposureTime;
254252
cam.GetExposureTimeAttr().Get(&vExposureTime, time); // conversion n/a
@@ -265,10 +263,9 @@ UsdImagingCameraAdapter::Get(UsdPrim const& prim,
265263
VtValue vExposureResponsivity;
266264
cam.GetExposureResponsivityAttr().Get(&vExposureResponsivity, time); // conversion n/a
267265
return vExposureResponsivity;
268-
} else if (key == HdCameraTokens->exposureCompensation) {
269-
VtValue vExposureCompensation;
270-
cam.GetExposureAttr().Get(&vExposureCompensation, time); // conversion n/a
271-
return vExposureCompensation;
266+
} else if (key == HdCameraTokens->exposureScale) {
267+
// The computed linear exposure multiplier ratio
268+
return VtValue(log2(cam.ComputeLinearExposureScale(time)));
272269
}
273270

274271
VtValue v;

pxr/usdImaging/usdImaging/dataSourceCamera.cpp

+14-21
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class _CameraExposureScaleDataSource
123123
, _usdCamera(usdCamera)
124124
, _stageGlobals(stageGlobals)
125125
{
126-
static const HdDataSourceLocator exposureLocator =
127-
HdCameraSchema::GetExposureLocator();
126+
static const HdDataSourceLocator exposureScaleLocator =
127+
HdCameraSchema::exposureScaleLocator();
128128

129129
static const std::vector<TfToken> inputNames = {
130130
UsdGeomTokens->exposure,
@@ -141,7 +141,7 @@ class _CameraExposureScaleDataSource
141141
prim.GetAttribute(inputName),
142142
_stageGlobals,
143143
_sceneIndexPath,
144-
exposureLocator));
144+
exposureScaleLocator));
145145
}
146146
}
147147

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

166162
bool GetContributingSampleTimesForInterval(
@@ -207,9 +203,7 @@ UsdImagingDataSourceCamera::GetNames()
207203
HdDataSourceBaseHandle
208204
UsdImagingDataSourceCamera::Get(const TfToken &name)
209205
{
210-
if (name == HdCameraSchemaTokens->exposure) {
211-
// we hijack the "exposure" token here in order to pass through the
212-
// calculated exposure and make it backwards-compatible.
206+
if (name == HdCameraSchemaTokens->exposureScale) {
213207
return _CameraExposureScaleDataSource::New(
214208
_sceneIndexPath, _usdCamera, _stageGlobals);
215209
}
@@ -336,38 +330,37 @@ UsdImagingDataSourceCameraPrim::Invalidate(
336330
locators.insert(
337331
HdCameraSchema::GetShutterCloseLocator());
338332
} else if (usdName == UsdGeomTokens->exposure) {
339-
// The USD "exposure" attr is mapped to hydra as
340-
// "exposureCompensation", but is also an input to the
341-
// computed value stored at "exposure".
342-
locators.insert(
343-
HdCameraSchema::GetExposureCompensationLocator());
333+
// "exposure" maps unchanged to "exposure", and is an
334+
// input to the computed value stored at "exposureScale"
344335
locators.insert(
345336
HdCameraSchema::GetExposureLocator());
337+
locators.insert(
338+
HdCameraSchema::GetExposureScaleLocator());
346339
} else if (usdName == UsdGeomTokens->exposureTime) {
347340
// "exposure:time" maps to "exposureTime", and is an
348-
// input to "exposure"
341+
// input to the computed value stored at "exposureScale"
349342
locators.insert(
350343
HdCameraSchema::GetExposureTimeLocator());
351344
locators.insert(
352-
HdCameraSchema::GetExposureLocator());
345+
HdCameraSchema::GetExposureScaleLocator());
353346
} else if (usdName == UsdGeomTokens->exposureIso) {
354347
// similar to exposureTime
355348
locators.insert(
356349
HdCameraSchema::GetExposureIsoLocator());
357350
locators.insert(
358-
HdCameraSchema::GetExposureLocator());
351+
HdCameraSchema::GetExposureScaleLocator());
359352
} else if (usdName == UsdGeomTokens->exposureFStop) {
360353
// similar to exposureTime
361354
locators.insert(
362355
HdCameraSchema::GetExposureFStopLocator());
363356
locators.insert(
364-
HdCameraSchema::GetExposureLocator());
357+
HdCameraSchema::GetExposureScaleLocator());
365358
} else if (usdName == UsdGeomTokens->exposureResponsivity) {
366359
// similar to exposureTime
367360
locators.insert(
368361
HdCameraSchema::GetExposureResponsivityLocator());
369362
locators.insert(
370-
HdCameraSchema::GetExposureLocator());
363+
HdCameraSchema::GetExposureScaleLocator());
371364
} else {
372365
locators.insert(
373366
HdCameraSchema::GetDefaultLocator().Append(

0 commit comments

Comments
 (0)