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 of HdxTaskController.
45 /// For now, the API and the behavior is the same than 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  /// C'tor.
58  ///
59  /// All prims in this scene index are under prefix.
60  /// The client needs to wrap
61  /// HdRenderDelegate::GetDefaultAovDescriptor in aovDescriptorCallback
62  /// (the API on HdRenderDelegate might change).
63  /// gpuEnabled decides whether the present task is run for
64  /// non-Storm renderers.
65  HDX_API
66  static
67  HdxTaskControllerSceneIndexRefPtr
68  New(const SdfPath &prefix,
69  const TfToken &rendererPluginName,
70  const AovDescriptorCallback &aovDescriptorCallback,
71  bool gpuEnabled = true);
72 
73  HDX_API
75 
76  HDX_API
77  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
78 
79  HDX_API
80  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
81 
82  /// -------------------------------------------------------
83  /// Execution API
84 
85  /// Obtain paths to the tasks managed by the task controller,
86  /// for image generation. The tasks returned will be different
87  /// based on current renderer state.
88  HDX_API
90 
91  /// Obtain paths to tasks managed by the task controller,
92  /// for picking.
93  HDX_API
95 
96  /// Get the path to the buffer for a rendered output.
97  /// Note: the caller should call Resolve(), as HdxTaskController doesn't
98  /// guarantee the buffer will be resolved.
99  HDX_API
100  SdfPath GetRenderBufferPath(const TfToken &aovName) const;
101 
102  /// -------------------------------------------------------
103  /// Rendering API
104 
105  /// Set the collection to be rendered.
106  HDX_API
107  void SetCollection(const HdRprimCollection &collection);
108 
109  /// Set the render params. Note: params.viewport will
110  /// be overwritten, since it comes from SetRenderViewport.
111  /// XXX: For GL renders, HdxTaskControllerSceneIndex relies on the caller to
112  /// correctly set GL_SAMPLE_ALPHA_TO_COVERAGE.
113  HDX_API
115 
116  /// Set the "view" opinion of the scenes render tags.
117  /// The opinion is the base opinion for the entire scene.
118  /// Individual tasks (such as the shadow task) may
119  /// have a stronger opinion and override this opinion
120  HDX_API
121  void SetRenderTags(const TfTokenVector &renderTags);
122 
123  /// -------------------------------------------------------
124  /// AOV API
125 
126  /// Set the list of outputs to be rendered. If outputs.size() == 1,
127  /// this will send that output to the viewport via a colorizer task.
128  /// Note: names should come from HdAovTokens.
129  HDX_API
130  void SetRenderOutputs(const TfTokenVector &aovNames);
131 
132  /// Set which output should be rendered to the viewport. The empty token
133  /// disables viewport rendering.
134  HDX_API
135  void SetViewportRenderOutput(TfToken const &aovName);
136 
137  /// Set custom parameters for an AOV.
138  HDX_API
139  void SetRenderOutputSettings(TfToken const& aovName,
140  const HdAovDescriptor &desc);
141 
142  /// Get parameters for an AOV.
143  HDX_API
144  HdAovDescriptor GetRenderOutputSettings(const TfToken &aovName) const;
145 
146  /// The destination API (e.g., OpenGL, see hgiInterop for details) and
147  /// framebuffer that the AOVs are presented into. The framebuffer
148  /// is a VtValue that encoding a framebuffer in a destination API
149  /// specific way.
150  /// E.g., a uint32_t (aka GLuint) for framebuffer object for OpenGL.
151  HDX_API
152  void SetPresentationOutput(const TfToken &api, const VtValue &framebuffer);
153 
154  /// -------------------------------------------------------
155  /// Lighting API
156 
157  /// Set the lighting state for the scene. HdxTaskControllerSceneIndex maintains
158  /// a set of light sprims with data set from the lights in "src".
159  /// @param src Lighting state to implement.
160  HDX_API
161  void SetLightingState(GlfSimpleLightingContextPtr const& src);
162 
163  /// -------------------------------------------------------
164  /// Camera and Framing API
165 
166  /// Set the size of the render buffers backing the AOVs.
167  /// GUI applications should set this to the size of the window.
168  ///
169  HDX_API
170  void SetRenderBufferSize(const GfVec2i &size);
171 
172  /// Determines how the filmback of the camera is mapped into
173  /// the pixels of the render buffer and what pixels of the render
174  /// buffer will be rendered into.
175  HDX_API
176  void SetFraming(const CameraUtilFraming &framing);
177 
178  /// Specifies whether to force a window policy when conforming
179  /// the frustum of the camera to match the display window of
180  /// the camera framing.
181  HDX_API
183  const std::optional<CameraUtilConformWindowPolicy> &policy);
184 
185  /// -- Scene camera --
186  /// Set the camera param on tasks to a USD camera path.
187  HDX_API
188  void SetCameraPath(const SdfPath &path);
189 
190  /// Set the viewport param on tasks.
191  ///
192  /// \deprecated Use SetFraming and SetRenderBufferSize instead.
193  HDX_API
194  void SetRenderViewport(const GfVec4d &viewport);
195 
196  /// -- Free camera --
197  /// Set the view and projection matrices for the free camera.
198  /// Note: The projection matrix must be pre-adjusted for the window policy.
199  HDX_API
200  void SetFreeCameraMatrices(const GfMatrix4d &viewMatrix,
201  const GfMatrix4d &projectionMatrix);
202  /// Set the free camera clip planes.
203  /// (Note: Scene cameras use clipping planes authored on the camera prim)
204  HDX_API
205  void SetFreeCameraClipPlanes(const std::vector<GfVec4d> &clipPlanes);
206 
207  /// -------------------------------------------------------
208  /// Selection API
209 
210  /// Turns the selection task on or off.
211  HDX_API
212  void SetEnableSelection(bool enable);
213 
214  /// Set the selection color.
215  HDX_API
216  void SetSelectionColor(const GfVec4f &color);
217 
218  /// Set the selection locate (over) color.
219  HDX_API
221 
222  /// Set if the selection highlight should be rendered as an outline around
223  /// the selected objects or as a solid color overlaid on top of them.
224  HDX_API
225  void SetSelectionEnableOutline(bool enableOutline);
226 
227  /// Set the selection outline radius (thickness) in pixels. This is only
228  /// relevant if the highlight is meant to be rendered as an outline (if
229  /// SetSelectionRenderOutline(true) is called).
230  HDX_API
231  void SetSelectionOutlineRadius(unsigned int radius);
232 
233  /// -------------------------------------------------------
234  /// Shadow API
235 
236  /// Turns the shadow task on or off.
237  HDX_API
238  void SetEnableShadows(bool enable);
239 
240  /// Set the shadow params. Note: params.camera will
241  /// be overwritten, since it comes from SetCameraPath/SetCameraState.
242  HDX_API
244 
245  /// -------------------------------------------------------
246  /// Color Correction API
247 
248  /// Configure color correction by settings params.
249  HDX_API
251 
252  /// -------------------------------------------------------
253  /// Bounding Box API
254 
255  /// Set the bounding box params.
256  HDX_API
258 
259  /// -------------------------------------------------------
260  /// Present API
261 
262  /// Enable / disable presenting the render to bound framebuffer.
263  /// An application may choose to manage the AOVs that are rendered into
264  /// itself and skip the task controller's presentation.
265  HDX_API
266  void SetEnablePresentation(bool enabled);
267 
268 private:
270  const SdfPath &prefix,
271  const TfToken &rendererPluginName,
272  const AovDescriptorCallback &aovDescriptorCallback,
273  bool gpuEnabled);
274 
275  bool _IsForStorm() const;
276 
277  void _CreateStormTasks();
278  void _CreateGenericTasks();
279 
280  SdfPathVector _GetRenderingTaskPathsForStorm() const;
281  SdfPathVector _GetRenderingTaskPathsForGenericRenderer() const;
282 
283  GfVec3i _RenderBufferDimensions() const;
284 
285  void _SetRenderOutputs(const TfTokenVector &aovNames);
286  void _SetCameraFramingForTasks();
287  void _SetRenderBufferSize();
288  void _SetSimpleLightTaskParams(GlfSimpleLightingContextPtr const& src);
289  void _SetLights(const GlfSimpleLightVector &lights);
290 
291  const SdfPath _prefix;
292  const bool _isForStorm;
293  const AovDescriptorCallback _aovDescriptorCallback;
294  const bool _runGpuAovTasks;
295 
296  HdRetainedSceneIndexRefPtr const _retainedSceneIndex;
297 
298  // All tasks using HdxRenderTaskParams.
299  SdfPathVector _renderTaskPaths;
300  SdfPath _activeCameraId;
301 
302  // Generated renderbuffers
303  TfTokenVector _aovNames;
304  TfToken _viewportAov;
305 
306  GfVec2i _renderBufferSize;
307  CameraUtilFraming _framing;
308  std::optional<CameraUtilConformWindowPolicy> _overrideWindowPolicy;
309 
310  GfVec4d _viewport;
311 
312  friend class _Observer;
313  class _Observer : public HdSceneIndexObserver
314  {
315  public:
317  : _owner(owner) {}
318 
319  HDX_API
320  void PrimsAdded(
321  const HdSceneIndexBase &sender,
322  const AddedPrimEntries &entries) override;
323 
324  HDX_API
325  void PrimsRemoved(
326  const HdSceneIndexBase &sender,
327  const RemovedPrimEntries &entries) override;
328 
329  HDX_API
330  void PrimsDirtied(
331  const HdSceneIndexBase &sender,
332  const DirtiedPrimEntries &entries) override;
333 
334  HDX_API
335  void PrimsRenamed(
336  const HdSceneIndexBase &sender,
337  const RenamedPrimEntries &entries) override;
338  private:
339  HdxTaskControllerSceneIndex * const _owner;
340  };
341  _Observer _observer;
342 };
343 
345 
346 #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.
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
Definition: SYS_MathCbrt.h:35
std::function< HdAovDescriptor(const TfToken &name)> AovDescriptorCallback
Definition: vec2i.h:43
HDX_API SdfPathVector GetRenderingTaskPaths() const
HDX_API void SetCameraPath(const SdfPath &path)
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 void SetSelectionLocateColor(const GfVec4f &color)
Set the selection locate (over) color.
HDX_API void SetSelectionEnableOutline(bool enableOutline)
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:273
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.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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
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)
static HDX_API HdxTaskControllerSceneIndexRefPtr New(const SdfPath &prefix, const TfToken &rendererPluginName, const AovDescriptorCallback &aovDescriptorCallback, bool gpuEnabled=true)
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:146
std::vector< class GlfSimpleLight > GlfSimpleLightVector
Definition: simpleLight.h:254
HDX_API SdfPath GetRenderBufferPath(const TfToken &aovName) const
GLenum src
Definition: glcorearb.h:1793