Loading...
Searching...
No Matches
taskController.h
1//
2// Copyright 2017 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_H
8#define PXR_IMAGING_HDX_TASK_CONTROLLER_H
9
10#include "pxr/pxr.h"
11
12#include "pxr/imaging/hdx/api.h"
13#include "pxr/imaging/hdx/selectionTracker.h"
14#include "pxr/imaging/hdx/renderSetupTask.h"
15#include "pxr/imaging/hdx/shadowTask.h"
16#include "pxr/imaging/hdx/colorCorrectionTask.h"
17#include "pxr/imaging/hdx/boundingBoxTask.h"
18
19#include "pxr/imaging/hd/aov.h"
20#include "pxr/imaging/hd/renderIndex.h"
21#include "pxr/imaging/hd/sceneDelegate.h"
22#include "pxr/imaging/hd/task.h"
23
24#include "pxr/imaging/cameraUtil/framing.h"
26#include "pxr/usd/sdf/path.h"
27
28#include "pxr/base/gf/bbox3d.h"
30
31PXR_NAMESPACE_OPEN_SCOPE
32
33// XXX: This API is transitional. At the least, render/picking/selection
34// APIs should be decoupled.
35
36class HdRenderBuffer;
37
42{
43public:
44 HDX_API
46 SdfPath const& controllerId,
47 bool gpuEnabled = true);
48 HDX_API
50
52 HdRenderIndex* GetRenderIndex() { return _index; }
53 HdRenderIndex const* GetRenderIndex() const { return _index; }
54
57 SdfPath const& GetControllerId() const { return _controllerId; }
58
61
65 HDX_API
66 SdfPathVector GetRenderingTaskPaths() const;
67
70 HDX_API
71 SdfPathVector GetPickingTaskPaths() const;
72
78 HDX_API
79 HdTaskSharedPtrVector GetRenderingTasks() const;
80
86 HDX_API
87 HdTaskSharedPtrVector GetPickingTasks() const;
88
91
93 HDX_API
94 void SetCollection(HdRprimCollection const& collection);
95
100 HDX_API
102
107 HDX_API
108 void SetRenderTags(TfTokenVector const& renderTags);
109
112
116 HDX_API
117 void SetRenderOutputs(TfTokenVector const& names);
118
121 HDX_API
123
127 HDX_API
129
131 HDX_API
133 HdAovDescriptor const& desc);
134
136 HDX_API
138
144 HDX_API
145 void SetPresentationOutput(TfToken const &api, VtValue const &framebuffer);
146
149
153 HDX_API
154 void SetLightingState(GlfSimpleLightingContextPtr const& src);
155
158
162 HDX_API
163 void SetRenderBufferSize(const GfVec2i &size);
164
168 HDX_API
169 void SetFraming(const CameraUtilFraming &framing);
170
174 HDX_API
176 const std::optional<CameraUtilConformWindowPolicy> &policy);
177
180 HDX_API
181 void SetCameraPath(SdfPath const& id);
182
186 HDX_API
187 void SetRenderViewport(GfVec4d const& viewport);
188
192 HDX_API
193 void SetFreeCameraMatrices(GfMatrix4d const& viewMatrix,
194 GfMatrix4d const& projectionMatrix);
197 HDX_API
198 void SetFreeCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
199
201 HDX_API
203
206
208 HDX_API
209 void SetEnableSelection(bool enable);
210
212 HDX_API
213 void SetSelectionColor(GfVec4f const& color);
214
216 HDX_API
218
221 HDX_API
222 void SetSelectionEnableOutline(bool enableOutline);
223
227 HDX_API
228 void SetSelectionOutlineRadius(unsigned int radius);
229
232
234 HDX_API
235 void SetEnableShadows(bool enable);
236
239 HDX_API
240 void SetShadowParams(HdxShadowTaskParams const& params);
241
244
255 HDX_API
256 bool IsConverged() const;
257
260
262 HDX_API
264
267
269 HDX_API
271
274
278 HDX_API
279 void SetEnablePresentation(bool enabled);
280
281private:
285 HdxTaskController(HdxTaskController const&) = delete;
286 HdxTaskController &operator=(HdxTaskController const&) = delete;
287
288 HdRenderIndex *_index;
289 SdfPath const _controllerId;
290 bool _gpuEnabled;
291
292 // Create taskController objects. Since the camera is a parameter
293 // to the tasks, _CreateCamera() should be called first.
294 void _CreateRenderGraph();
295
296 void _CreateLightingTask();
297 void _CreateShadowTask();
298 SdfPath _CreateSkydomeTask();
299 SdfPath _CreateRenderTask(TfToken const& materialTag);
300 void _CreateOitResolveTask();
301 void _CreateSelectionTask();
302 void _CreateColorizeSelectionTask();
303 void _CreateColorCorrectionTask();
304 void _CreateVisualizeAovTask();
305 void _CreatePickTask();
306 void _CreatePickFromRenderBufferTask();
307 void _CreateBoundingBoxTask();
308 void _CreateAovInputTask();
309 void _CreatePresentTask();
310
311 void _SetCameraParamForTasks(SdfPath const& id);
312 void _SetCameraFramingForTasks();
313 void _UpdateAovDimensions(GfVec2i const& dimensions);
314
315 void _SetBlendStateForMaterialTag(TfToken const& materialTag,
316 HdxRenderTaskParams *renderParams) const;
317
318 // Render graph topology control.
319 bool _ShadowsEnabled() const;
320 bool _SelectionEnabled() const;
321 bool _ColorizeSelectionEnabled() const;
322 bool _ColorCorrectionEnabled() const;
323 bool _VisualizeAovEnabled() const;
324 bool _ColorizeQuantizationEnabled() const;
325 bool _AovsSupported() const;
326 bool _UsingAovs() const;
327
328 // Helper function for renderbuffer management.
329 SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
330 SdfPath _GetAovPath(TfToken const& aov) const;
331 SdfPathVector _GetAovEnabledTasks() const;
332
333 // Helper functions to set up the lighting state for the built-in lights
334 bool _SupportBuiltInLightTypes();
335 void _SetBuiltInLightingState(GlfSimpleLightingContextPtr const& src);
336
337 // Helper function to get the built-in Camera light type SimpleLight for
338 // Storm, and DistantLight otherwise
339 TfToken _GetCameraLightType();
340
341 // Helper functions to set the parameters of a light, get a particular light
342 // in the scene, replace and remove Sprims from the scene
343 VtValue _GetDomeLightTexture(GlfSimpleLight const& light);
344 void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
345 void _SetMaterialNetwork(SdfPath const& pathName,
346 GlfSimpleLight const& light);
347 GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
348 void _RemoveLightSprim(size_t const& pathIdx);
349 void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
350 SdfPath const& pathName);
351
352 // A private scene delegate member variable backs the tasks and the free cam
353 // this controller generates. To keep _Delegate simple, the containing class
354 // is responsible for marking things dirty.
355 class _Delegate : public HdSceneDelegate
356 {
357 public:
358 _Delegate(HdRenderIndex *parentIndex,
359 SdfPath const& delegateID)
360 : HdSceneDelegate(parentIndex, delegateID)
361 {}
362 ~_Delegate() override = default;
363
364 // HdxTaskController set/get interface
365 template <typename T>
366 void SetParameter(SdfPath const& id, TfToken const& key,
367 T const& value) {
368 _valueCacheMap[id][key] = value;
369 }
370 template <typename T>
371 T GetParameter(SdfPath const& id, TfToken const& key) const {
372 VtValue vParams;
373 _ValueCache vCache;
374 TF_VERIFY(
375 TfMapLookup(_valueCacheMap, id, &vCache) &&
376 TfMapLookup(vCache, key, &vParams) &&
377 vParams.IsHolding<T>());
378 return vParams.Get<T>();
379 }
380 bool HasParameter(SdfPath const& id, TfToken const& key) const {
381 _ValueCache vCache;
382 if (TfMapLookup(_valueCacheMap, id, &vCache) &&
383 vCache.count(key) > 0) {
384 return true;
385 }
386 return false;
387 }
388
389 // HdSceneDelegate interface
390 VtValue Get(SdfPath const& id, TfToken const& key) override;
391 GfMatrix4d GetTransform(SdfPath const& id) override;
392 VtValue GetLightParamValue(SdfPath const& id,
393 TfToken const& paramName) override;
394 VtValue GetMaterialResource(SdfPath const& id) override;
395 bool IsEnabled(TfToken const& option) const override;
397 GetRenderBufferDescriptor(SdfPath const& id) override;
398 TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
399
400
401 private:
402 using _ValueCache = TfHashMap<TfToken, VtValue, TfToken::HashFunctor>;
403 using _ValueCacheMap = TfHashMap<SdfPath, _ValueCache, SdfPath::Hash>;
404 _ValueCacheMap _valueCacheMap;
405 };
406 _Delegate _delegate;
407 std::unique_ptr<class HdxFreeCameraSceneDelegate> _freeCameraSceneDelegate;
408
409 // Generated tasks.
410 SdfPath _simpleLightTaskId;
411 SdfPath _shadowTaskId;
412 SdfPathVector _renderTaskIds;
413 SdfPath _aovInputTaskId;
414 SdfPath _oitResolveTaskId;
415 SdfPath _selectionTaskId;
416 SdfPath _colorizeSelectionTaskId;
417 SdfPath _colorCorrectionTaskId;
418 SdfPath _visualizeAovTaskId;
419 SdfPath _pickTaskId;
420 SdfPath _pickFromRenderBufferTaskId;
421 SdfPath _boundingBoxTaskId;
422 SdfPath _presentTaskId;
423
424 // Current active camera
425 SdfPath _activeCameraId;
426
427 // Built-in lights
428 SdfPathVector _lightIds;
429
430 // Generated renderbuffers
431 SdfPathVector _aovBufferIds;
432 TfTokenVector _aovOutputs;
433 TfToken _viewportAov;
434
435 GfVec2i _renderBufferSize;
436 CameraUtilFraming _framing;
437 std::optional<CameraUtilConformWindowPolicy> _overrideWindowPolicy;
438
439 GfVec4d _viewport;
440};
441
442PXR_NAMESPACE_CLOSE_SCOPE
443
444#endif // PXR_IMAGING_HDX_TASK_CONTROLLER_H
Framing information.
Definition framing.h:63
Stores a 4x4 matrix of double elements.
Definition matrix4d.h:71
Basic type for a vector of 2 int components.
Definition vec2i.h:44
Basic type for a vector of 4 double components.
Definition vec4d.h:46
Basic type for a vector of 4 float components.
Definition vec4f.h:46
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
The render index is part of the Hydra 1.0 API and is only used for emulation purposes so that HdScene...
A named, semantic collection of objects.
Adapter class providing data exchange with the client scene graph.
HDX_API void SetViewportRenderOutput(TfToken const &name)
Set which output should be rendered to the viewport.
HDX_API void SetSelectionColor(GfVec4f const &color)
Set the selection color.
HDX_API void SetRenderOutputSettings(TfToken const &name, HdAovDescriptor const &desc)
Set custom parameters for an AOV.
HDX_API void SetCameraPath(SdfPath const &id)
– Scene camera – Set the camera param on tasks to a USD camera path.
HDX_API SdfPathVector GetPickingTaskPaths() const
Obtain paths to tasks managed by the task controller, for picking.
HDX_API void SetCollection(HdRprimCollection const &collection)
Set the collection to be rendered.
HDX_API void SetFreeCameraClipPlanes(std::vector< GfVec4d > const &clipPlanes)
Set the free camera clip planes.
HDX_API void SetColorCorrectionParams(HdxColorCorrectionTaskParams const &params)
Configure color correction by settings params.
HDX_API bool IsConverged() const
Return whether the image has converged.
HDX_API void SetOverrideWindowPolicy(const std::optional< CameraUtilConformWindowPolicy > &policy)
Specifies whether to force a window policy when conforming the frustum of the camera to match the dis...
HDX_API HdTaskSharedPtrVector GetPickingTasks() const
HDX_API void SetSelectionLocateColor(GfVec4f const &color)
Set the selection locate (over) color.
HdRenderIndex * GetRenderIndex()
Return the render index this controller is bound to.
HDX_API void SetRenderParams(HdxRenderTaskParams const &params)
Set the render params.
HDX_API void SetLightingState(GlfSimpleLightingContextPtr const &src)
Set the lighting state for the scene.
HDX_API SdfPathVector GetRenderingTaskPaths() const
Obtain paths to the tasks managed by the task controller, for image generation.
HDX_API void SetSelectionEnableOutline(bool enableOutline)
Set if the selection highlight should be rendered as an outline around the selected objects or as a s...
HDX_API SdfPath GetFreeCameraPath()
Get the free camera's Hydra prim path.
HDX_API HdRenderBuffer * GetRenderOutput(TfToken const &name)
Get the buffer for a rendered output.
HDX_API void SetPresentationOutput(TfToken const &api, VtValue const &framebuffer)
The destination API (e.g., OpenGL, see hgiInterop for details) and framebuffer that the AOVs are pres...
HDX_API void SetFraming(const CameraUtilFraming &framing)
Determines how the filmback of the camera is mapped into the pixels of the render buffer and what pix...
HDX_API void SetRenderOutputs(TfTokenVector const &names)
Set the list of outputs to be rendered.
HDX_API void SetFreeCameraMatrices(GfMatrix4d const &viewMatrix, GfMatrix4d const &projectionMatrix)
– Free camera – Set the view and projection matrices for the free camera.
HDX_API void SetRenderBufferSize(const GfVec2i &size)
Set the size of the render buffers backing the AOVs.
HDX_API void SetSelectionOutlineRadius(unsigned int radius)
Set the selection outline radius (thickness) in pixels.
HDX_API void SetEnablePresentation(bool enabled)
Enable / disable presenting the render to bound framebuffer.
HDX_API void SetEnableShadows(bool enable)
Turns the shadow task on or off.
HDX_API HdTaskSharedPtrVector GetRenderingTasks() const
HDX_API void SetRenderTags(TfTokenVector const &renderTags)
Set the "view" opinion of the scenes render tags.
SdfPath const & GetControllerId() const
Return the controller's scene-graph id (prefixed to any scene graph objects it creates).
HDX_API void SetBBoxParams(const HdxBoundingBoxTaskParams &params)
Set the bounding box params.
HDX_API HdAovDescriptor GetRenderOutputSettings(TfToken const &name) const
Get parameters for an AOV.
HDX_API void SetEnableSelection(bool enable)
Turns the selection task on or off.
HDX_API void SetRenderViewport(GfVec4d const &viewport)
Set the viewport param on tasks.
HDX_API void SetShadowParams(HdxShadowTaskParams const &params)
Set the shadow params.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition value.h:90
T const & Get() const &
Returns a const reference to the held object if the held object is of type T.
Definition value.h:1063
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition value.h:1002
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition diagnostic.h:266
bool TfMapLookup(Container const &map, Key const &key, Result *valuePtr)
Checks if an item exists in a map or a TfHashMap.
Definition stl.h:69
A bundle of state describing an AOV ("Arbitrary Output Variable") display channel.
Definition aov.h:30
Describes the allocation structure of a render buffer bprim.
Definition aov.h:67
BoundingBoxTask parameters.
ColorCorrectionTask parameters.
RenderTask parameters (renderpass state).
std::vector< TfToken > TfTokenVector
Convenience types.
Definition token.h:440