HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
taskControllerSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HDX_TASK_CONTROLLER_SCENE_INDEX_H
8 #define PXR_IMAGING_HDX_TASK_CONTROLLER_SCENE_INDEX_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/imaging/hdx/api.h"
17 
18 #include "pxr/imaging/hd/aov.h"
21 #include "pxr/imaging/hd/task.h"
22 
25 
26 #include "pxr/base/gf/matrix4d.h"
27 
29 
30 HDX_API
32 
35 
36 /// \class HdxTaskControllerSceneIndex
37 ///
38 /// Manages tasks necessary to render an image (or perform picking)
39 /// as well as the related render buffers, lights and a free camera.
40 ///
41 /// Note that the set of necessary tasks is different for Storm and other
42 /// renderers. Thus, the c'tor needs to be given the renderer plugin name.
43 ///
44 /// It is a Hydra 2.0 implementation replacing the HdxTaskController.
45 /// For now, the API and behavior is the same as that of the
46 /// HdxTaskController.
47 ///
48 // XXX: This API is transitional. At the least, render/picking/selection
49 // APIs should be decoupled.
50 //
52 {
53 public:
54  using AovDescriptorCallback =
55  std::function<HdAovDescriptor(const TfToken &name)>;
56 
57  /// All prims in this scene index are under prefix.
58  /// The client needs to wrap
59  /// HdRenderDelegate::GetDefaultAovDescriptor in aovDescriptorCallback
60  /// (the API on HdRenderDelegate might change).
61  /// gpuEnabled decides whether the present task is run for
62  /// non-Storm renderers.
63  struct Parameters
64  {
65  const SdfPath prefix;
67  bool isForStorm;
68  bool gpuEnabled;
69  };
70 
71  /// C'tor.
72  HDX_API
73  static
74  HdxTaskControllerSceneIndexRefPtr
75  New(const Parameters& params);
76 
77  HDX_API
79 
80  HDX_API
81  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
82 
83  HDX_API
84  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
85 
86  /// -------------------------------------------------------
87  /// Execution API
88 
89  /// Obtain paths to the tasks managed by the task controller,
90  /// for image generation. The tasks returned will be different
91  /// based on current renderer state.
92  HDX_API
94 
95  /// Obtain paths to tasks managed by the task controller,
96  /// for picking.
97  HDX_API
99 
100  /// Get the path to the buffer for a rendered output.
101  /// Note: the caller should call Resolve(), as HdxTaskController doesn't
102  /// guarantee the buffer will be resolved.
103  HDX_API
104  SdfPath GetRenderBufferPath(const TfToken &aovName) const;
105 
106  /// -------------------------------------------------------
107  /// Rendering API
108 
109  /// Set the collection to be rendered.
110  HDX_API
111  void SetCollection(const HdRprimCollection &collection);
112 
113  /// Set the render params. Note: params.viewport will
114  /// be overwritten, since it comes from SetRenderViewport.
115  /// XXX: For GL renders, HdxTaskControllerSceneIndex relies on the caller to
116  /// correctly set GL_SAMPLE_ALPHA_TO_COVERAGE.
117  HDX_API
119 
120  /// Set the "view" opinion of the scenes render tags.
121  /// The opinion is the base opinion for the entire scene.
122  /// Individual tasks (such as the shadow task) may
123  /// have a stronger opinion and override this opinion
124  HDX_API
125  void SetRenderTags(const TfTokenVector &renderTags);
126 
127  /// -------------------------------------------------------
128  /// AOV API
129 
130  /// Set the list of outputs to be rendered. If outputs.size() == 1,
131  /// this will send that output to the viewport via a colorizer task.
132  /// Note: names should come from HdAovTokens.
133  HDX_API
134  void SetRenderOutputs(const TfTokenVector &aovNames);
135 
136  /// Set which output should be rendered to the viewport. The empty token
137  /// disables viewport rendering.
138  HDX_API
139  void SetViewportRenderOutput(TfToken const &aovName);
140 
141  /// Set custom parameters for an AOV.
142  HDX_API
143  void SetRenderOutputSettings(TfToken const& aovName,
144  const HdAovDescriptor &desc);
145 
146  /// Get parameters for an AOV.
147  HDX_API
148  HdAovDescriptor GetRenderOutputSettings(const TfToken &aovName) const;
149 
150  /// The destination API (e.g., OpenGL, see hgiInterop for details) and
151  /// framebuffer that the AOVs are presented into. The framebuffer
152  /// is a VtValue that encoding a framebuffer in a destination API
153  /// specific way.
154  /// E.g., a uint32_t (aka GLuint) for framebuffer object for OpenGL.
155  HDX_API
156  void SetPresentationOutput(const TfToken &api, const VtValue &framebuffer);
157 
158  /// -------------------------------------------------------
159  /// Lighting API
160 
161  /// Set the lighting state for the scene. HdxTaskControllerSceneIndex maintains
162  /// a set of light sprims with data set from the lights in "src".
163  /// @param src Lighting state to implement.
164  HDX_API
165  void SetLightingState(GlfSimpleLightingContextPtr const& src);
166 
167  /// -------------------------------------------------------
168  /// Camera and Framing API
169 
170  /// Set the size of the render buffers backing the AOVs.
171  /// GUI applications should set this to the size of the window.
172  ///
173  HDX_API
174  void SetRenderBufferSize(const GfVec2i &size);
175 
176  /// Determines how the filmback of the camera is mapped into
177  /// the pixels of the render buffer and what pixels of the render
178  /// buffer will be rendered into.
179  HDX_API
180  void SetFraming(const CameraUtilFraming &framing);
181 
182  /// Specifies whether to force a window policy when conforming
183  /// the frustum of the camera to match the display window of
184  /// the camera framing.
185  HDX_API
187  const std::optional<CameraUtilConformWindowPolicy> &policy);
188 
189  /// -- Scene camera --
190  /// Set the camera param on tasks to a USD camera path.
191  HDX_API
192  void SetCameraPath(const SdfPath &path);
193 
194  /// Set the viewport param on tasks.
195  ///
196  /// \deprecated Use SetFraming and SetRenderBufferSize instead.
197  HDX_API
198  void SetRenderViewport(const GfVec4d &viewport);
199 
200  /// -- Free camera --
201  /// Set the view and projection matrices for the free camera.
202  /// Note: The projection matrix must be pre-adjusted for the window policy.
203  HDX_API
204  void SetFreeCameraMatrices(const GfMatrix4d &viewMatrix,
205  const GfMatrix4d &projectionMatrix);
206  /// Set the free camera clip planes.
207  /// (Note: Scene cameras use clipping planes authored on the camera prim)
208  HDX_API
209  void SetFreeCameraClipPlanes(const std::vector<GfVec4d> &clipPlanes);
210 
211  /// Get the free camera's Hydra prim path
212  HDX_API
214 
215  /// -------------------------------------------------------
216  /// Selection API
217 
218  /// Turns the selection task on or off.
219  HDX_API
220  void SetEnableSelection(bool enable);
221 
222  /// Set the selection color.
223  HDX_API
224  void SetSelectionColor(const GfVec4f &color);
225 
226  /// Set the selection locate (over) color.
227  HDX_API
229 
230  /// Set if the selection highlight should be rendered as an outline around
231  /// the selected objects or as a solid color overlaid on top of them.
232  HDX_API
233  void SetSelectionEnableOutline(bool enableOutline);
234 
235  /// Set the selection outline radius (thickness) in pixels. This is only
236  /// relevant if the highlight is meant to be rendered as an outline (if
237  /// SetSelectionRenderOutline(true) is called).
238  HDX_API
239  void SetSelectionOutlineRadius(unsigned int radius);
240 
241  /// -------------------------------------------------------
242  /// Shadow API
243 
244  /// Turns the shadow task on or off.
245  HDX_API
246  void SetEnableShadows(bool enable);
247 
248  /// Set the shadow params. Note: params.camera will
249  /// be overwritten, since it comes from SetCameraPath/SetCameraState.
250  HDX_API
252 
253  /// -------------------------------------------------------
254  /// Color Correction API
255 
256  /// Configure color correction by settings params.
257  HDX_API
259 
260  /// -------------------------------------------------------
261  /// Bounding Box API
262 
263  /// Set the bounding box params.
264  HDX_API
266 
267  /// -------------------------------------------------------
268  /// Present API
269 
270  /// Enable / disable presenting the render to bound framebuffer.
271  /// An application may choose to manage the AOVs that are rendered into
272  /// itself and skip the task controller's presentation.
273  HDX_API
274  void SetEnablePresentation(bool enabled);
275 
276 private:
278 
279  bool _IsForStorm() const;
280  bool _RunGpuAovTasks() const;
281 
282  void _CreateStormTasks();
283  void _CreateGenericTasks();
284 
285  SdfPathVector _GetRenderingTaskPathsForStorm() const;
286  SdfPathVector _GetRenderingTaskPathsForGenericRenderer() const;
287 
288  GfVec3i _RenderBufferDimensions() const;
289 
290  void _SetRenderOutputs(const TfTokenVector &aovNames);
291  void _SetCameraFramingForTasks();
292  void _SetRenderBufferSize();
293  void _SetSimpleLightTaskParams(GlfSimpleLightingContextPtr const& src);
294  void _SetLights(const GlfSimpleLightVector &lights);
295 
296  const Parameters _params;
297 
298  HdRetainedSceneIndexRefPtr const _retainedSceneIndex;
299 
300  // All tasks using HdxRenderTaskParams.
301  SdfPathVector _renderTaskPaths;
302  SdfPath _activeCameraId;
303 
304  // Generated renderbuffers
305  TfTokenVector _aovNames;
306  TfToken _viewportAov;
307 
308  GfVec2i _renderBufferSize;
309  CameraUtilFraming _framing;
310  std::optional<CameraUtilConformWindowPolicy> _overrideWindowPolicy;
311 
312  GfVec4d _viewport;
313 
314  friend class _Observer;
315  class _Observer : public HdSceneIndexObserver
316  {
317  public:
319  : _owner(owner) {}
320 
321  HDX_API
322  void PrimsAdded(
323  const HdSceneIndexBase &sender,
324  const AddedPrimEntries &entries) override;
325 
326  HDX_API
327  void PrimsRemoved(
328  const HdSceneIndexBase &sender,
329  const RemovedPrimEntries &entries) override;
330 
331  HDX_API
332  void PrimsDirtied(
333  const HdSceneIndexBase &sender,
334  const DirtiedPrimEntries &entries) override;
335 
336  HDX_API
337  void PrimsRenamed(
338  const HdSceneIndexBase &sender,
339  const RenamedPrimEntries &entries) override;
340  private:
341  HdxTaskControllerSceneIndex * const _owner;
342  };
343  _Observer _observer;
344 };
345 
347 
348 #endif // PXR_IMAGING_HDX_TASK_CONTROLLER_SCENE_INDEX_H
PXR_NAMESPACE_OPEN_SCOPE HDX_API TfEnvSetting< int > HDX_MSAA_SAMPLE_COUNT
HDX_API void SetShadowParams(const HdxShadowTaskParams &params)
HDX_API void SetCollection(const HdRprimCollection &collection)
Set the collection to be rendered.
HDX_API void SetSelectionOutlineRadius(unsigned int radius)
HDX_API void SetColorCorrectionParams(const HdxColorCorrectionTaskParams &params)
Configure color correction by settings params.
std::function< HdAovDescriptor(const TfToken &name)> AovDescriptorCallback
Definition: vec2i.h:43
HDX_API SdfPathVector GetRenderingTaskPaths() const
HDX_API void SetCameraPath(const SdfPath &path)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
HDX_API void SetEnableSelection(bool enable)
Turns the selection task on or off.
Definition: vec4d.h:45
HDX_API ~HdxTaskControllerSceneIndex() override
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glcorearb.h:2539
#define HDX_API
Definition: api.h:23
GLenum const GLfloat * params
Definition: glcorearb.h:105
HDX_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
HDX_API void SetRenderOutputs(const TfTokenVector &aovNames)
HDX_API void SetRenderTags(const TfTokenVector &renderTags)
Definition: token.h:70
GLuint framebuffer
Definition: glcorearb.h:1287
std::vector< class SdfPath > SdfPathVector
HDX_API SdfPath GetFreeCameraPath()
Get the free camera's Hydra prim path.
HDX_API void SetSelectionLocateColor(const GfVec4f &color)
Set the selection locate (over) color.
HDX_API void SetSelectionEnableOutline(bool enableOutline)
const AovDescriptorCallback aovDescriptorCallback
HDX_API void SetRenderParams(const HdxRenderTaskParams &params)
HDX_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
HDX_API SdfPathVector GetPickingTaskPaths() const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: vec3i.h:43
HDX_API void SetFraming(const CameraUtilFraming &framing)
TF_DECLARE_REF_PTRS(HdRetainedSceneIndex)
Definition: path.h:280
HDX_API void SetLightingState(GlfSimpleLightingContextPtr const &src)
Definition: vec4f.h:45
GLsizeiptr size
Definition: glcorearb.h:664
HDX_API HdAovDescriptor GetRenderOutputSettings(const TfToken &aovName) const
Get parameters for an AOV.
HDX_API void SetFreeCameraClipPlanes(const std::vector< GfVec4d > &clipPlanes)
HDX_API void SetFreeCameraMatrices(const GfMatrix4d &viewMatrix, const GfMatrix4d &projectionMatrix)
GLuint color
Definition: glcorearb.h:1261
static HDX_API HdxTaskControllerSceneIndexRefPtr New(const Parameters &params)
C'tor.
HDX_API void SetEnableShadows(bool enable)
Turns the shadow task on or off.
HDX_API void SetOverrideWindowPolicy(const std::optional< CameraUtilConformWindowPolicy > &policy)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDX_API void SetBBoxParams(const HdxBoundingBoxTaskParams &params)
Set the bounding box params.
HDX_API void SetViewportRenderOutput(TfToken const &aovName)
HDX_API void SetSelectionColor(const GfVec4f &color)
Set the selection color.
HDX_API void SetEnablePresentation(bool enabled)
HDX_API void SetRenderViewport(const GfVec4d &viewport)
HDX_API void SetRenderOutputSettings(TfToken const &aovName, const HdAovDescriptor &desc)
Set custom parameters for an AOV.
HDX_API void SetRenderBufferSize(const GfVec2i &size)
HDX_API void SetPresentationOutput(const TfToken &api, const VtValue &framebuffer)
Definition: value.h:89
std::vector< class GlfSimpleLight > GlfSimpleLightVector
Definition: simpleLight.h:254
HDX_API SdfPath GetRenderBufferPath(const TfToken &aovName) const
GLenum src
Definition: glcorearb.h:1793