camera.h
1 //
2 // Copyright 2017 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_CAMERA_H
25 #define PXR_IMAGING_HD_CAMERA_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hd/sprim.h"
31 
32 #include "pxr/imaging/cameraUtil/conformWindow.h"
33 
34 #include "pxr/usd/sdf/path.h"
36 #include "pxr/base/gf/matrix4d.h"
37 #include "pxr/base/gf/range1f.h"
38 
39 #include <vector>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
48 #define HD_CAMERA_TOKENS \
49  /* frustum */ \
50  (projection) \
51  (horizontalAperture) \
52  (verticalAperture) \
53  (horizontalApertureOffset) \
54  (verticalApertureOffset) \
55  (focalLength) \
56  (clippingRange) \
57  (clipPlanes) \
58  \
59  /* depth of field */ \
60  (fStop) \
61  (focusDistance) \
62  \
63  /* shutter/lighting */ \
64  (shutterOpen) \
65  (shutterClose) \
66  (exposure) \
67  \
68  /* how to match window with different aspect */ \
69  (windowPolicy) \
70  \
71  /* OpenGL-style matrices, deprecated */ \
72  (worldToViewMatrix) \
73  (projectionMatrix)
74 
75 
76 TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS);
77 
85 class HdCamera : public HdSprim
86 {
87 public:
88  using ClipPlanesVector = std::vector<GfVec4d>;
89 
90  HD_API
91  HdCamera(SdfPath const & id);
92  HD_API
93  ~HdCamera() override;
94 
95  // change tracking for HdCamera
96  enum DirtyBits : HdDirtyBits
97  {
98  Clean = 0,
99  DirtyTransform = 1 << 0,
100  DirtyViewMatrix = DirtyTransform, // deprecated
101  DirtyProjMatrix = 1 << 1, // deprecated
102  DirtyWindowPolicy = 1 << 2,
103  DirtyClipPlanes = 1 << 3,
104  DirtyParams = 1 << 4,
105  AllDirty = (DirtyTransform
106  |DirtyProjMatrix
107  |DirtyWindowPolicy
108  |DirtyClipPlanes
109  |DirtyParams)
110  };
111 
112  enum Projection {
113  Perspective = 0,
114  Orthographic
115  };
116 
117  // ---------------------------------------------------------------------- //
119  // ---------------------------------------------------------------------- //
120 
122  HD_API
123  void Sync(HdSceneDelegate *sceneDelegate,
124  HdRenderParam *renderParam,
125  HdDirtyBits *dirtyBits) override;
126 
127 
131  HD_API
132  HdDirtyBits GetInitialDirtyBitsMask() const override;
133 
134  // ---------------------------------------------------------------------- //
136  // ---------------------------------------------------------------------- //
137 
139  GfMatrix4d const& GetTransform() const {
140  return _transform;
141  }
142 
144  Projection GetProjection() const {
145  return _projection;
146  }
147 
149  float GetHorizontalAperture() const {
150  return _horizontalAperture;
151  }
152 
154  float GetVerticalAperture() const {
155  return _verticalAperture;
156  }
157 
160  return _horizontalApertureOffset;
161  }
162 
165  return _verticalApertureOffset;
166  }
167 
169  float GetFocalLength() const {
170  return _focalLength;
171  }
172 
174  GfRange1f const &GetClippingRange() const {
175  return _clippingRange;
176  }
177 
179  std::vector<GfVec4d> const& GetClipPlanes() const {
180  return _clipPlanes;
181  }
182 
184  float GetFStop() const {
185  return _fStop;
186  }
187 
189  float GetFocusDistance() const {
190  return _focusDistance;
191  }
192 
193  double GetShutterOpen() const {
194  return _shutterOpen;
195  }
196 
197  double GetShutterClose() const {
198  return _shutterClose;
199  }
200 
201  float GetExposure() const {
202  return _exposure;
203  }
204 
207  CameraUtilConformWindowPolicy const& GetWindowPolicy() const {
208  return _windowPolicy;
209  }
210 
211  // ---------------------------------------------------------------------- //
213  // ---------------------------------------------------------------------- //
214 
217  HD_API
218  GfMatrix4d GetViewMatrix() const;
219 
222  HD_API
224 
227  HD_API
229 
230 protected:
231  // frustum
232  GfMatrix4d _transform;
233  Projection _projection;
234  float _horizontalAperture;
235  float _verticalAperture;
236  float _horizontalApertureOffset;
237  float _verticalApertureOffset;
238  float _focalLength;
239  GfRange1f _clippingRange;
240  std::vector<GfVec4d> _clipPlanes;
241 
242  // focus
243  float _fStop;
244  float _focusDistance;
245 
246  // shutter/lighting
247  double _shutterOpen;
248  double _shutterClose;
249  float _exposure;
250 
251  // Camera's opinion how it display in a window with
252  // a different aspect ratio
253  CameraUtilConformWindowPolicy _windowPolicy;
254 
255  // OpenGL-style matrices
256  GfMatrix4d _worldToViewMatrix;
257  GfMatrix4d _worldToViewInverseMatrix;
258  GfMatrix4d _projectionMatrix;
259 };
260 
261 PXR_NAMESPACE_CLOSE_SCOPE
262 
263 #endif // PXR_IMAGING_HD_CAMERA_H
std::vector< GfVec4d > const & GetClipPlanes() const
Returns any additional clipping planes defined in camera space.
Definition: camera.h:179
GfRange1f const & GetClippingRange() const
Returns near and far plane in world units.
Definition: camera.h:174
Hydra schema for a camera that pulls the params (see above) during Sync.
Definition: camera.h:85
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
float GetFocalLength() const
Returns focal length in world units.
Definition: camera.h:169
float GetVerticalApertureOffset() const
Returns vertical aperture offset in world units.
Definition: camera.h:164
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Sprim API.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Adapter class providing data exchange with the client scene graph.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
float GetVerticalAperture() const
Returns vertical aperture in world units.
Definition: camera.h:154
Projection GetProjection() const
Returns whether camera is orthographic and perspective.
Definition: camera.h:144
Basic type: 1-dimensional floating point range.
Definition: range1f.h:62
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
CameraUtilConformWindowPolicy const & GetWindowPolicy() const
Returns the window policy of the camera.
Definition: camera.h:207
HD_API GfMatrix4d GetProjectionMatrix() const
Returns the projection matrix for the camera.
float GetFocusDistance() const
Returns focus distance in world units.
Definition: camera.h:189
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e....
Definition: sprim.h:52
float GetHorizontalAperture() const
Returns horizontal aperture in world units.
Definition: camera.h:149
HD_API GfMatrix4d GetViewInverseMatrix() const
Returns the matrix transformation from camera to world space.
This file defines some macros that are useful for declaring and using static TfTokens.
GfMatrix4d const & GetTransform() const
Camera parameters accessor API.
Definition: camera.h:139
HD_API GfMatrix4d GetViewMatrix() const
Legacy camera parameters accessor API.
float GetFStop() const
Returns fstop of camera.
Definition: camera.h:184
float GetHorizontalApertureOffset() const
Returns horizontal aperture offset in world units.
Definition: camera.h:159
HD_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the minimal set of dirty bits to place in the change tracker for use in the first sync of thi...