Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix depth of field #319

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pxr/imaging/plugin/hdRpr/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ limitations under the License.

PXR_NAMESPACE_OPEN_SCOPE

TF_DEFINE_PRIVATE_TOKENS(HdRprCameraTokens,
(apertureBlades)
);

namespace {

template<typename T>
Expand Down Expand Up @@ -60,6 +64,7 @@ HdRprCamera::HdRprCamera(SdfPath const& id)
m_focalLength(std::numeric_limits<float>::quiet_NaN()),
m_fStop(std::numeric_limits<float>::quiet_NaN()),
m_focusDistance(std::numeric_limits<float>::quiet_NaN()),
m_apertureBlades(0),
m_shutterOpen(std::numeric_limits<double>::quiet_NaN()),
m_shutterClose(std::numeric_limits<double>::quiet_NaN()),
m_clippingRange(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()) {
Expand Down Expand Up @@ -95,6 +100,8 @@ void HdRprCamera::Sync(HdSceneDelegate* sceneDelegate,
EvalCameraParam(&m_clippingRange, HdCameraTokens->clippingRange, sceneDelegate, id, GfRange1f(std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()));

EvalCameraParam(&m_projectionType, UsdGeomTokens->projection, sceneDelegate, id, TfToken());

EvalCameraParam(&m_apertureBlades, HdRprCameraTokens->apertureBlades, sceneDelegate, id, 16);
}

if (*dirtyBits & HdCamera::DirtyViewMatrix) {
Expand Down
2 changes: 2 additions & 0 deletions pxr/imaging/plugin/hdRpr/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class HdRprCamera : public HdCamera {
bool GetClippingRange(GfRange1f* value) const;
bool GetProjectionType(TfToken* value) const;
HdTimeSampleArray<GfMatrix4d, 2> const& GetTransformSamples() const { return m_transform; }
int GetApertureBlades() const { return m_apertureBlades; }

HdDirtyBits GetDirtyBits() const { return m_rprDirtyBits; }
void CleanDirtyBits() const { m_rprDirtyBits = HdCamera::Clean; }
Expand All @@ -57,6 +58,7 @@ class HdRprCamera : public HdCamera {
float m_focalLength;
float m_fStop;
float m_focusDistance;
int m_apertureBlades;
double m_shutterOpen;
double m_shutterClose;
GfRange1f m_clippingRange;
Expand Down
17 changes: 16 additions & 1 deletion pxr/imaging/plugin/hdRpr/rprApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,9 +1477,24 @@ class HdRprApiImpl {

float fstop = 0.0f;
m_hdCamera->GetFStop(&fstop);
if (fstop == 0.0f) { fstop = std::numeric_limits<float>::max(); }
bool dofEnabled = fstop != 0.0f && fstop != std::numeric_limits<float>::max();

if (dofEnabled) {
int apertureBlades = m_hdCamera->GetApertureBlades();
if (apertureBlades < 4 || apertureBlades > 32) {
apertureBlades = 16;
}
RPR_ERROR_CHECK(m_camera->SetApertureBlades(apertureBlades), "Failed to set camera aperture blades");
} else {
fstop = std::numeric_limits<float>::max();
}
RPR_ERROR_CHECK(m_camera->SetFStop(fstop), "Failed to set camera FStop");

// Convert to millimeters
focalLength *= 1e3f;
sensorWidth *= 1e3f;
sensorHeight *= 1e3f;

RPR_ERROR_CHECK(m_camera->SetFocalLength(focalLength), "Fail to set camera focal length");
RPR_ERROR_CHECK(m_camera->SetSensorSize(sensorWidth, sensorHeight), "Failed to set camera sensor size");
}
Expand Down