Loading...
Searching...
No Matches
camera.h
1//
2// Copyright 2019 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef EXT_RMANPKG_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_CAMERA_H
8#define EXT_RMANPKG_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_CAMERA_H
9
10#include "hdPrman/api.h"
11#include "hdPrman/cameraContext.h"
12#include "hdPrman/renderParam.h"
13
14#include "pxr/imaging/hd/camera.h"
15#include "pxr/imaging/hd/renderDelegate.h"
16#include "pxr/imaging/hd/timeSampleArray.h"
17#include "pxr/imaging/hd/types.h"
18#include "pxr/imaging/hd/version.h"
19
20#include "pxr/usd/sdf/path.h"
21
23#include "pxr/base/gf/range2d.h"
25
26#include "pxr/pxr.h"
27
28#include <Riley.h>
29#include <RileyIds.h>
30#include <RiTypesHelper.h>
31
32#include <array>
33#include <mutex>
34#include <optional>
35#include <vector>
36
37PXR_NAMESPACE_OPEN_SCOPE
38
39class HdSceneDelegate;
40
49class HdPrmanCamera final : public HdCamera
50{
51public:
56 {
57 std::optional<float> shutterOpenTime;
58 std::optional<float> shutterCloseTime;
59 std::optional<std::array<float, 8>> shutteropening;
60 };
61
62 HDPRMAN_API
63 HdPrmanCamera(SdfPath const& id);
64
65 HDPRMAN_API
66 ~HdPrmanCamera() override;
67
68 // ------------------------------------------------------------------------
69 // Riley projection shading-node identity
70 //
71 // Shared with HdPrman_CameraContext, which builds the same kind of
72 // projection node for the fallback camera.
73 // ------------------------------------------------------------------------
74
79 HDPRMAN_API
80 static const RtUString& ComputeProjectionShader(
81 HdCamera::Projection projection,
82 const RtUString& projectionOverride);
83
86 static const RtUString& ComputeProjectionShader(
87 HdCamera::Projection projection,
88 const RtUString&& projectionOverride) = delete;
89
91 HDPRMAN_API
92 static const RtUString& ProjectionNodeName();
93
95 HDPRMAN_API
96 void Sync(HdSceneDelegate *sceneDelegate,
97 HdRenderParam *renderParam,
98 HdDirtyBits *dirtyBits) override;
99
100 HDPRMAN_API
101 void Finalize(HdRenderParam* renderParam) override;
102
103 HDPRMAN_API
104 riley::CameraId GetRileyCameraId() const;
105
106 HDPRMAN_API
107 RtUString GetRileyCameraName() const;
108
113 HDPRMAN_API
115 HdPrman_RenderParam* param,
116 const HdPrman_CameraContext::ActiveCameraOverlay& overlay);
117
122 HDPRMAN_API
123 void UpdateRileyCameraForInactive(HdPrman_RenderParam* param);
124
136 HDPRMAN_API
138 HdPrman_RenderParam* param,
139 const HdPrman_CameraContext::ActiveCameraOverlay& overlay);
140
142 HDPRMAN_API
145 return _sampleXforms;
146 }
147
148 riley::ShadingNode
149 GetProjectionNode() const {
150 return _projectionNode;
151 }
152
153#if HD_API_VERSION < 52
154 float GetLensDistortionK1() const {
155 return _lensDistortionK1;
156 }
157
158 float GetLensDistortionK2() const {
159 return _lensDistortionK2;
160 }
161
162 const GfVec2f &GetLensDistortionCenter() const {
163 return _lensDistortionCenter;
164 }
165
166 float GetLensDistortionAnaSq() const {
167 return _lensDistortionAnaSq;
168 }
169
170 const GfVec2f &GetLensDistortionAsym() const {
171 return _lensDistortionAsym;
172 }
173
174 float GetLensDistortionScale() const {
175 return _lensDistortionScale;
176 }
177#endif
178
213 return _shutterCurve;
214 }
215
218 HDPRMAN_API
219 void SetRileyCameraParams(RtParamList& camParams,
220 RtParamList& camParamsOverride,
221 RtParamList& projParams) const;
222
223 float GetApertureAngle() const {
224 return _apertureAngle;
225 }
226
227 float GetApertureDensity() const {
228 return _apertureDensity;
229 }
230
231 int GetApertureNSides() const {
232 return _apertureNSides;
233 }
234
235 float GetApertureRoundness() const {
236 return _apertureRoundness;
237 }
238
239 float GetDofMult() const {
240 return _dofMult;
241 }
242
243private:
244
245 void setFov(RtParamList& projParams) const;
246
247 void setScreenWindow(RtParamList& camParams, bool isPerspective) const;
248
249 // Commit the camera state to riley. Caller must acquire lock on
250 // _rileyCameraMutex.
251 void _CommitToRiley(
252 riley::Riley* riley,
253 const GfRange2d& screenWindow,
254 bool disableDepthOfField,
255 const RtUString& projectionNameOverride,
256 const RtParamList& projectionParamsOverride);
257
258 // Commit the clip planes state to riley. Caller must acquire lock on
259 // _rileyCameraMutex.
260 void _UpdateClipPlanes(riley::Riley* riley);
261
262 // Delete the clip planes from riley. Caller must acquire lock on
263 // _rileyCameraMutex.
264 void _DeleteClipPlanes(riley::Riley* riley);
265
267 _GetScreenWindow() const;
268
269 // This camera's intrinsic screen window, conformed to the framing and
270 // window policy carried by the active camera overlay. The camera
271 // contributes its aperture; the overlay contributes the framing.
273 _ConformScreenWindow(
274 const HdPrman_CameraContext::ActiveCameraOverlay& overlay) const;
275
276 RtParamList
277 _ComputeCameraParams(const GfRange2d & screenWindow) const;
278
279 RtParamList
280 _ComputeNodeParams(
281 bool disableDepthOfField,
282 const RtUString & projectionOverride) const;
283
284 RtParamList
285 _ComputePerspectiveNodeParams(bool disableDepthOfField) const;
286
287 RtParamList
288 _ComputeOrthographicNodeParams() const;
289
291
292#if HD_API_VERSION < 52
293 float _lensDistortionK1;
294 float _lensDistortionK2;
295 GfVec2f _lensDistortionCenter;
296 float _lensDistortionAnaSq;
297 GfVec2f _lensDistortionAsym;
298 float _lensDistortionScale;
299#endif
300
311 ShutterCurve _shutterCurve;
312
313 float _apertureAngle;
314 float _apertureDensity;
315 int _apertureNSides;
316 float _apertureRoundness;
317 float _dofMult;
318
319 VtDictionary _params;
320
321 riley::ShadingNode _projectionNode;
322
323 riley::CameraId _rileyCameraId;
324 RtUString _rileyCameraName;
325 std::vector<riley::ClippingPlaneId> _rileyClipPlaneIds;
326
327 // Mutex for gating access to _rileyCameraId and _rileyCameraName
328 mutable std::mutex _rileyCameraMutex;
329};
330
331
332PXR_NAMESPACE_CLOSE_SCOPE
333
334#endif // EXT_RMANPKG_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_CAMERA_H
Basic type: 2-dimensional floating point range.
Definition range2d.h:47
Basic type for a vector of 2 float components.
Definition vec2f.h:46
Hydra schema for a camera that pulls the params (see above) during Sync.
Definition camera.h:92
A representation for cameras that pulls on camera parameters used by Riley cameras.
Definition camera.h:50
static const RtUString & ComputeProjectionShader(HdCamera::Projection projection, const RtUString &&projectionOverride)=delete
projectionOverride may be returned by reference, so binding it to a temporary would dangle.
HDPRMAN_API void RecommitRileyCameraForActive(HdPrman_RenderParam *param, const HdPrman_CameraContext::ActiveCameraOverlay &overlay)
Re-commit this camera's riley camera under the given overlay, and nothing else.
HDPRMAN_API void SetRileyCameraParams(RtParamList &camParams, RtParamList &camParamsOverride, RtParamList &projParams) const
Sets the camera and projection shader parameters as expected by Riley from the USD physical camera pa...
static HDPRMAN_API const RtUString & ComputeProjectionShader(HdCamera::Projection projection, const RtUString &projectionOverride)
The riley projection shader name to use for the given projection.
HDPRMAN_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Synchronizes state from the delegate to this object.
HDPRMAN_API HdTimeSampleArray< GfMatrix4d, HDPRMAN_MAX_TIME_SAMPLES > const & GetTimeSampleXforms() const
Returns the time sampled xforms that were queried during Sync.
Definition camera.h:144
HDPRMAN_API void UpdateRileyCameraForActive(HdPrman_RenderParam *param, const HdPrman_CameraContext::ActiveCameraOverlay &overlay)
Apply the active camera opinions overlay to this camera's riley camera.
const ShutterCurve & GetShutterCurve() const
Get the shutter curve of the camera.
Definition camera.h:212
static HDPRMAN_API const RtUString & ProjectionNodeName()
The riley projection shading-node handle name ("cam_projection").
HDPRMAN_API void Finalize(HdRenderParam *renderParam) override
Finalizes object resources.
HDPRMAN_API void UpdateRileyCameraForInactive(HdPrman_RenderParam *param)
Remove the active camera opinions overlay from this camera's riley camera.
See GetShutterCurve() below for a description of what these values represent.
Definition camera.h:56
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
A map with string keys and VtValue values.
Definition dictionary.h:52
An array of a value sampled over time, in struct-of-arrays layout.