Skip to content

Commit

Permalink
Add exposure controls to UsdGeomCamera
Browse files Browse the repository at this point in the history
This PR adds exposure controls to UsdGeomCamera, allowing to specify
brightness as with a physical camera. The calculated exposure value is
fed to `HdCamera::GetLinearExposureScale()` via `UsdImagingCameraAdapter`
and `UsdImagingDataSourceCamera`. Note that:

1. Existing scenes that use the existing `exposure` attribute continue to
   work as before, whether the render delegate calls `HdCamera::GetExposure()`
   or `HdCamera::GetLinearExposureScale()`.
2. Renderers need to switch to calling `HdCamera::GetLinearExposureScale()`
   to make use of the new attributes.

Adds exposure:time, exposure:iso, exposure:fNumber, exposure:responsivity
attributes and repurposes exposure attribute to be interpreted as exposure
compensation. Adds UsdGeomCamera::ComputeLinearExposureScale() method which
allows users to calculate the imaging ratio (i.e. given a certain luminance
on the sensor, what is the photometric exposure output) from these attributes.

Also adds a unit test to test the above.

Adds tokens `exposureTime`, `exposureIso`, `exposureFNumber`,
`exposureResponsivity`, `exposureCompensation` to `HdCamera`. Adds
`HdCamera::GetLinearExposureScale()` for delegates to be able to use the new
controls with a single function call.

Closes #3085

(Internal change: 2353446)

Co-authored-by: Tom <[email protected]>
Co-authored-by: Paul Molodowitch <[email protected]>
  • Loading branch information
3 people authored and pixar-oss committed Jan 28, 2025
1 parent 7a5e7af commit 3f4bf38
Show file tree
Hide file tree
Showing 18 changed files with 977 additions and 20 deletions.
40 changes: 40 additions & 0 deletions pxr/imaging/hd/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ HdCamera::HdCamera(SdfPath const &id)
, _shutterOpen(0.0)
, _shutterClose(0.0)
, _exposure(0.0f)
, _exposureTime(1.0f)
, _exposureIso(100.0f)
, _exposureFStop(1.0f)
, _exposureResponsivity(1.0f)
, _linearExposureScale(1.0f)
, _lensDistortionType(HdCameraTokens->standard)
, _lensDistortionK1(0.0f)
, _lensDistortionK2(0.0f)
Expand Down Expand Up @@ -238,6 +243,41 @@ HdCamera::Sync(HdSceneDelegate * sceneDelegate,
_exposure = vExposure.Get<float>();
}

const VtValue vExposureTime =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->exposureTime);
if (!vExposureTime.IsEmpty()) {
_exposureTime = vExposureTime.Get<float>();
}

const VtValue vExposureIso =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->exposureIso);
if (!vExposureIso.IsEmpty()) {
_exposureIso = vExposureIso.Get<float>();
}

const VtValue vExposureFStop =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->exposureFStop);
if (!vExposureFStop.IsEmpty()) {
_exposureFStop = vExposureFStop.Get<float>();
}

const VtValue vExposureResponsivity =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->exposureResponsivity);
if (!vExposureResponsivity.IsEmpty()) {
_exposureResponsivity = vExposureResponsivity.Get<float>();
}

const VtValue vLinearExposureScale =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->linearExposureScale);
if (!vLinearExposureScale.IsEmpty()) {
_linearExposureScale = vLinearExposureScale.Get<float>();
}

const VtValue vLensDistortionType =
sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->lensDistortionType);
Expand Down
30 changes: 29 additions & 1 deletion pxr/imaging/hd/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ PXR_NAMESPACE_OPEN_SCOPE
(shutterOpen) \
(shutterClose) \
(exposure) \
(exposureTime) \
(exposureIso) \
(exposureFStop) \
(exposureResponsivity) \
(linearExposureScale) \
\
/* how to match window with different aspect */ \
(windowPolicy) \
Expand Down Expand Up @@ -236,10 +241,26 @@ class HdCamera : public HdSprim
return _shutterClose;
}

/// Get the raw exposure exponent value.
///
/// 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
/// GetLinearExposureScale() 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 GetLinearExposureScale() const {
return _linearExposureScale;
}

TfToken GetLensDistortionType() const {
return _lensDistortionType;
}
Expand Down Expand Up @@ -313,10 +334,17 @@ class HdCamera : public HdSprim
float _splitDiopterWidth2;
float _splitDiopterFocusDistance2;

// shutter/lighting
// shutter
double _shutterOpen;
double _shutterClose;

// exposure
float _exposure;
float _exposureTime;
float _exposureIso;
float _exposureFStop;
float _exposureResponsivity;
float _linearExposureScale;

// lens distortion
TfToken _lensDistortionType;
Expand Down
174 changes: 172 additions & 2 deletions pxr/imaging/hd/cameraSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,41 @@ HdCameraSchema::GetExposure() const
HdCameraSchemaTokens->exposure);
}

HdFloatDataSourceHandle
HdCameraSchema::GetExposureTime() const
{
return _GetTypedDataSource<HdFloatDataSource>(
HdCameraSchemaTokens->exposureTime);
}

HdFloatDataSourceHandle
HdCameraSchema::GetExposureIso() const
{
return _GetTypedDataSource<HdFloatDataSource>(
HdCameraSchemaTokens->exposureIso);
}

HdFloatDataSourceHandle
HdCameraSchema::GetExposureFStop() const
{
return _GetTypedDataSource<HdFloatDataSource>(
HdCameraSchemaTokens->exposureFStop);
}

HdFloatDataSourceHandle
HdCameraSchema::GetExposureResponsivity() const
{
return _GetTypedDataSource<HdFloatDataSource>(
HdCameraSchemaTokens->exposureResponsivity);
}

HdFloatDataSourceHandle
HdCameraSchema::GetLinearExposureScale() const
{
return _GetTypedDataSource<HdFloatDataSource>(
HdCameraSchemaTokens->linearExposureScale);
}

HdBoolDataSourceHandle
HdCameraSchema::GetFocusOn() const
{
Expand Down Expand Up @@ -174,15 +209,20 @@ HdCameraSchema::BuildRetained(
const HdDoubleDataSourceHandle &shutterOpen,
const HdDoubleDataSourceHandle &shutterClose,
const HdFloatDataSourceHandle &exposure,
const HdFloatDataSourceHandle &exposureTime,
const HdFloatDataSourceHandle &exposureIso,
const HdFloatDataSourceHandle &exposureFStop,
const HdFloatDataSourceHandle &exposureResponsivity,
const HdFloatDataSourceHandle &linearExposureScale,
const HdBoolDataSourceHandle &focusOn,
const HdFloatDataSourceHandle &dofAspect,
const HdContainerDataSourceHandle &splitDiopter,
const HdContainerDataSourceHandle &lensDistortion,
const HdContainerDataSourceHandle &namespacedProperties
)
{
TfToken _names[18];
HdDataSourceBaseHandle _values[18];
TfToken _names[23];
HdDataSourceBaseHandle _values[23];

size_t _count = 0;

Expand Down Expand Up @@ -251,6 +291,31 @@ HdCameraSchema::BuildRetained(
_values[_count++] = exposure;
}

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

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

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

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

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

if (focusOn) {
_names[_count] = HdCameraSchemaTokens->focusOn;
_values[_count++] = focusOn;
Expand Down Expand Up @@ -382,6 +447,46 @@ HdCameraSchema::Builder::SetExposure(
return *this;
}

HdCameraSchema::Builder &
HdCameraSchema::Builder::SetExposureTime(
const HdFloatDataSourceHandle &exposureTime)
{
_exposureTime = exposureTime;
return *this;
}

HdCameraSchema::Builder &
HdCameraSchema::Builder::SetExposureIso(
const HdFloatDataSourceHandle &exposureIso)
{
_exposureIso = exposureIso;
return *this;
}

HdCameraSchema::Builder &
HdCameraSchema::Builder::SetExposureFStop(
const HdFloatDataSourceHandle &exposureFStop)
{
_exposureFStop = exposureFStop;
return *this;
}

HdCameraSchema::Builder &
HdCameraSchema::Builder::SetExposureResponsivity(
const HdFloatDataSourceHandle &exposureResponsivity)
{
_exposureResponsivity = exposureResponsivity;
return *this;
}

HdCameraSchema::Builder &
HdCameraSchema::Builder::SetLinearExposureScale(
const HdFloatDataSourceHandle &linearExposureScale)
{
_linearExposureScale = linearExposureScale;
return *this;
}

HdCameraSchema::Builder &
HdCameraSchema::Builder::SetFocusOn(
const HdBoolDataSourceHandle &focusOn)
Expand Down Expand Up @@ -439,6 +544,11 @@ HdCameraSchema::Builder::Build()
_shutterOpen,
_shutterClose,
_exposure,
_exposureTime,
_exposureIso,
_exposureFStop,
_exposureResponsivity,
_linearExposureScale,
_focusOn,
_dofAspect,
_splitDiopter,
Expand Down Expand Up @@ -494,6 +604,66 @@ HdCameraSchema::GetShutterCloseLocator()
return locator;
}

/* static */
const HdDataSourceLocator &
HdCameraSchema::GetExposureLocator()
{
static const HdDataSourceLocator locator =
GetDefaultLocator().Append(
HdCameraSchemaTokens->exposure);
return locator;
}

/* static */
const HdDataSourceLocator &
HdCameraSchema::GetExposureTimeLocator()
{
static const HdDataSourceLocator locator =
GetDefaultLocator().Append(
HdCameraSchemaTokens->exposureTime);
return locator;
}

/* static */
const HdDataSourceLocator &
HdCameraSchema::GetExposureIsoLocator()
{
static const HdDataSourceLocator locator =
GetDefaultLocator().Append(
HdCameraSchemaTokens->exposureIso);
return locator;
}

/* static */
const HdDataSourceLocator &
HdCameraSchema::GetExposureFStopLocator()
{
static const HdDataSourceLocator locator =
GetDefaultLocator().Append(
HdCameraSchemaTokens->exposureFStop);
return locator;
}

/* static */
const HdDataSourceLocator &
HdCameraSchema::GetExposureResponsivityLocator()
{
static const HdDataSourceLocator locator =
GetDefaultLocator().Append(
HdCameraSchemaTokens->exposureResponsivity);
return locator;
}

/* static */
const HdDataSourceLocator &
HdCameraSchema::GetLinearExposureScaleLocator()
{
static const HdDataSourceLocator locator =
GetDefaultLocator().Append(
HdCameraSchemaTokens->linearExposureScale);
return locator;
}

/* static */
const HdDataSourceLocator &
HdCameraSchema::GetNamespacedPropertiesLocator()
Expand Down
Loading

0 comments on commit 3f4bf38

Please sign in to comment.