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
38class HdxTaskController final
39{
40public:
41 HDX_API
42 HdxTaskController(HdRenderIndex *renderIndex,
43 SdfPath const& controllerId,
44 bool gpuEnabled = true);
45 HDX_API
46 ~HdxTaskController();
47
49 HdRenderIndex* GetRenderIndex() { return _index; }
50 HdRenderIndex const* GetRenderIndex() const { return _index; }
51
54 SdfPath const& GetControllerId() const { return _controllerId; }
55
58
62 HDX_API
63 SdfPathVector GetRenderingTaskPaths() const;
64
67 HDX_API
68 SdfPathVector GetPickingTaskPaths() const;
69
75 HDX_API
76 HdTaskSharedPtrVector GetRenderingTasks() const;
77
83 HDX_API
84 HdTaskSharedPtrVector GetPickingTasks() const;
85
88
90 HDX_API
91 void SetCollection(HdRprimCollection const& collection);
92
97 HDX_API
98 void SetRenderParams(HdxRenderTaskParams const& params);
99
104 HDX_API
105 void SetRenderTags(TfTokenVector const& renderTags);
106
109
113 HDX_API
114 void SetRenderOutputs(TfTokenVector const& names);
115
118 HDX_API
119 void SetViewportRenderOutput(TfToken const& name);
120
124 HDX_API
125 HdRenderBuffer* GetRenderOutput(TfToken const& name);
126
128 HDX_API
129 void SetRenderOutputSettings(TfToken const& name,
130 HdAovDescriptor const& desc);
131
133 HDX_API
134 HdAovDescriptor GetRenderOutputSettings(TfToken const& name) const;
135
141 HDX_API
142 void SetPresentationOutput(TfToken const &api, VtValue const &framebuffer);
143
146
150 HDX_API
151 void SetLightingState(GlfSimpleLightingContextPtr const& src);
152
155
159 HDX_API
160 void SetRenderBufferSize(const GfVec2i &size);
161
165 HDX_API
166 void SetFraming(const CameraUtilFraming &framing);
167
171 HDX_API
172 void SetOverrideWindowPolicy(
173 const std::optional<CameraUtilConformWindowPolicy> &policy);
174
177 HDX_API
178 void SetCameraPath(SdfPath const& id);
179
183 HDX_API
184 void SetRenderViewport(GfVec4d const& viewport);
185
189 HDX_API
190 void SetFreeCameraMatrices(GfMatrix4d const& viewMatrix,
191 GfMatrix4d const& projectionMatrix);
194 HDX_API
195 void SetFreeCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
196
198 HDX_API
199 SdfPath GetFreeCameraPath();
200
203
205 HDX_API
206 void SetEnableSelection(bool enable);
207
209 HDX_API
210 void SetSelectionColor(GfVec4f const& color);
211
213 HDX_API
214 void SetSelectionLocateColor(GfVec4f const& color);
215
218 HDX_API
219 void SetSelectionEnableOutline(bool enableOutline);
220
224 HDX_API
225 void SetSelectionOutlineRadius(unsigned int radius);
226
229
231 HDX_API
232 void SetEnableShadows(bool enable);
233
236 HDX_API
237 void SetShadowParams(HdxShadowTaskParams const& params);
238
241
252 HDX_API
253 bool IsConverged() const;
254
257
259 HDX_API
260 void SetColorCorrectionParams(HdxColorCorrectionTaskParams const& params);
261
264
266 HDX_API
267 void SetBBoxParams(const HdxBoundingBoxTaskParams& params);
268
271
275 HDX_API
276 void SetEnablePresentation(bool enabled);
277
278private:
282 HdxTaskController(HdxTaskController const&) = delete;
283 HdxTaskController &operator=(HdxTaskController const&) = delete;
284
285 HdRenderIndex *_index;
286 SdfPath const _controllerId;
287 bool _gpuEnabled;
288
289 // Create taskController objects. Since the camera is a parameter
290 // to the tasks, _CreateCamera() should be called first.
291 void _CreateRenderGraph();
292
293 void _CreateLightingTask();
294 void _CreateShadowTask();
295 SdfPath _CreateSkydomeTask();
296 SdfPath _CreateRenderTask(TfToken const& materialTag);
297 void _CreateOitResolveTask();
298 void _CreateSelectionTask();
299 void _CreateColorizeSelectionTask();
300 void _CreateColorCorrectionTask();
301 void _CreateVisualizeAovTask();
302 void _CreatePickTask();
303 void _CreatePickFromRenderBufferTask();
304 void _CreateBoundingBoxTask();
305 void _CreateAovInputTask();
306 void _CreatePresentTask();
307
308 void _SetCameraParamForTasks(SdfPath const& id);
309 void _SetCameraFramingForTasks();
310 void _UpdateAovDimensions(GfVec2i const& dimensions);
311
312 void _SetBlendStateForMaterialTag(TfToken const& materialTag,
313 HdxRenderTaskParams *renderParams) const;
314
315 // Render graph topology control.
316 bool _ShadowsEnabled() const;
317 bool _SelectionEnabled() const;
318 bool _ColorizeSelectionEnabled() const;
319 bool _ColorCorrectionEnabled() const;
320 bool _VisualizeAovEnabled() const;
321 bool _ColorizeQuantizationEnabled() const;
322 bool _AovsSupported() const;
323 bool _UsingAovs() const;
324
325 // Helper function for renderbuffer management.
326 SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
327 SdfPath _GetAovPath(TfToken const& aov) const;
328 SdfPathVector _GetAovEnabledTasks() const;
329
330 // Helper functions to set up the lighting state for the built-in lights
331 bool _SupportBuiltInLightTypes();
332 void _SetBuiltInLightingState(GlfSimpleLightingContextPtr const& src);
333
334 // Helper function to get the built-in Camera light type SimpleLight for
335 // Storm, and DistantLight otherwise
336 TfToken _GetCameraLightType();
337
338 // Helper functions to set the parameters of a light, get a particular light
339 // in the scene, replace and remove Sprims from the scene
340 VtValue _GetDomeLightTexture(GlfSimpleLight const& light);
341 void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
342 void _SetMaterialNetwork(SdfPath const& pathName,
343 GlfSimpleLight const& light);
344 GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
345 void _RemoveLightSprim(size_t const& pathIdx);
346 void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
347 SdfPath const& pathName);
348
349 // A private scene delegate member variable backs the tasks and the free cam
350 // this controller generates. To keep _Delegate simple, the containing class
351 // is responsible for marking things dirty.
352 class _Delegate : public HdSceneDelegate
353 {
354 public:
355 _Delegate(HdRenderIndex *parentIndex,
356 SdfPath const& delegateID)
357 : HdSceneDelegate(parentIndex, delegateID)
358 {}
359 ~_Delegate() override = default;
360
361 // HdxTaskController set/get interface
362 template <typename T>
363 void SetParameter(SdfPath const& id, TfToken const& key,
364 T const& value) {
365 _valueCacheMap[id][key] = value;
366 }
367 template <typename T>
368 T GetParameter(SdfPath const& id, TfToken const& key) const {
369 VtValue vParams;
370 _ValueCache vCache;
371 TF_VERIFY(
372 TfMapLookup(_valueCacheMap, id, &vCache) &&
373 TfMapLookup(vCache, key, &vParams) &&
374 vParams.IsHolding<T>());
375 return vParams.Get<T>();
376 }
377 bool HasParameter(SdfPath const& id, TfToken const& key) const {
378 _ValueCache vCache;
379 if (TfMapLookup(_valueCacheMap, id, &vCache) &&
380 vCache.count(key) > 0) {
381 return true;
382 }
383 return false;
384 }
385
386 // HdSceneDelegate interface
387 VtValue Get(SdfPath const& id, TfToken const& key) override;
388 GfMatrix4d GetTransform(SdfPath const& id) override;
389 VtValue GetLightParamValue(SdfPath const& id,
390 TfToken const& paramName) override;
391 VtValue GetMaterialResource(SdfPath const& id) override;
392 bool IsEnabled(TfToken const& option) const override;
394 GetRenderBufferDescriptor(SdfPath const& id) override;
395 TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
396
397
398 private:
399 using _ValueCache = TfHashMap<TfToken, VtValue, TfToken::HashFunctor>;
400 using _ValueCacheMap = TfHashMap<SdfPath, _ValueCache, SdfPath::Hash>;
401 _ValueCacheMap _valueCacheMap;
402 };
403 _Delegate _delegate;
404 std::unique_ptr<class HdxFreeCameraSceneDelegate> _freeCameraSceneDelegate;
405
406 // Generated tasks.
407 SdfPath _simpleLightTaskId;
408 SdfPath _shadowTaskId;
409 SdfPathVector _renderTaskIds;
410 SdfPath _aovInputTaskId;
411 SdfPath _oitResolveTaskId;
412 SdfPath _selectionTaskId;
413 SdfPath _colorizeSelectionTaskId;
414 SdfPath _colorCorrectionTaskId;
415 SdfPath _visualizeAovTaskId;
416 SdfPath _pickTaskId;
417 SdfPath _pickFromRenderBufferTaskId;
418 SdfPath _boundingBoxTaskId;
419 SdfPath _presentTaskId;
420
421 // Current active camera
422 SdfPath _activeCameraId;
423
424 // Built-in lights
425 SdfPathVector _lightIds;
426
427 // Generated renderbuffers
428 SdfPathVector _aovBufferIds;
429 TfTokenVector _aovOutputs;
430 TfToken _viewportAov;
431
432 GfVec2i _renderBufferSize;
433 CameraUtilFraming _framing;
434 std::optional<CameraUtilConformWindowPolicy> _overrideWindowPolicy;
435
436 GfVec4d _viewport;
437};
438
439PXR_NAMESPACE_CLOSE_SCOPE
440
441#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...
Definition: renderBuffer.h:33
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:105
A named, semantic collection of objects.
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
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