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
199
201 HDX_API
202 void SetEnableSelection(bool enable);
203
205 HDX_API
206 void SetSelectionColor(GfVec4f const& color);
207
209 HDX_API
210 void SetSelectionLocateColor(GfVec4f const& color);
211
214 HDX_API
215 void SetSelectionEnableOutline(bool enableOutline);
216
220 HDX_API
221 void SetSelectionOutlineRadius(unsigned int radius);
222
225
227 HDX_API
228 void SetEnableShadows(bool enable);
229
232 HDX_API
233 void SetShadowParams(HdxShadowTaskParams const& params);
234
237
248 HDX_API
249 bool IsConverged() const;
250
253
255 HDX_API
256 void SetColorCorrectionParams(HdxColorCorrectionTaskParams const& params);
257
260
262 HDX_API
263 void SetBBoxParams(const HdxBoundingBoxTaskParams& params);
264
267
271 HDX_API
272 void SetEnablePresentation(bool enabled);
273
274private:
278 HdxTaskController(HdxTaskController const&) = delete;
279 HdxTaskController &operator=(HdxTaskController const&) = delete;
280
281 HdRenderIndex *_index;
282 SdfPath const _controllerId;
283 bool _gpuEnabled;
284
285 // Create taskController objects. Since the camera is a parameter
286 // to the tasks, _CreateCamera() should be called first.
287 void _CreateRenderGraph();
288
289 void _CreateLightingTask();
290 void _CreateShadowTask();
291 SdfPath _CreateSkydomeTask();
292 SdfPath _CreateRenderTask(TfToken const& materialTag);
293 void _CreateOitResolveTask();
294 void _CreateSelectionTask();
295 void _CreateColorizeSelectionTask();
296 void _CreateColorCorrectionTask();
297 void _CreateVisualizeAovTask();
298 void _CreatePickTask();
299 void _CreatePickFromRenderBufferTask();
300 void _CreateBoundingBoxTask();
301 void _CreateAovInputTask();
302 void _CreatePresentTask();
303
304 void _SetCameraParamForTasks(SdfPath const& id);
305 void _SetCameraFramingForTasks();
306 void _UpdateAovDimensions(GfVec2i const& dimensions);
307
308 void _SetBlendStateForMaterialTag(TfToken const& materialTag,
309 HdxRenderTaskParams *renderParams) const;
310
311 // Render graph topology control.
312 bool _ShadowsEnabled() const;
313 bool _SelectionEnabled() const;
314 bool _ColorizeSelectionEnabled() const;
315 bool _ColorCorrectionEnabled() const;
316 bool _VisualizeAovEnabled() const;
317 bool _ColorizeQuantizationEnabled() const;
318 bool _AovsSupported() const;
319 bool _UsingAovs() const;
320
321 // Helper function for renderbuffer management.
322 SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
323 SdfPath _GetAovPath(TfToken const& aov) const;
324 SdfPathVector _GetAovEnabledTasks() const;
325
326 // Helper functions to set up the lighting state for the built-in lights
327 bool _SupportBuiltInLightTypes();
328 void _SetBuiltInLightingState(GlfSimpleLightingContextPtr const& src);
329
330 // Helper function to get the built-in Camera light type SimpleLight for
331 // Storm, and DistantLight otherwise
332 TfToken _GetCameraLightType();
333
334 // Helper functions to set the parameters of a light, get a particular light
335 // in the scene, replace and remove Sprims from the scene
336 VtValue _GetDomeLightTexture(GlfSimpleLight const& light);
337 void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
338 void _SetMaterialNetwork(SdfPath const& pathName,
339 GlfSimpleLight const& light);
340 GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
341 void _RemoveLightSprim(size_t const& pathIdx);
342 void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
343 SdfPath const& pathName);
344
345 // A private scene delegate member variable backs the tasks and the free cam
346 // this controller generates. To keep _Delegate simple, the containing class
347 // is responsible for marking things dirty.
348 class _Delegate : public HdSceneDelegate
349 {
350 public:
351 _Delegate(HdRenderIndex *parentIndex,
352 SdfPath const& delegateID)
353 : HdSceneDelegate(parentIndex, delegateID)
354 {}
355 ~_Delegate() override = default;
356
357 // HdxTaskController set/get interface
358 template <typename T>
359 void SetParameter(SdfPath const& id, TfToken const& key,
360 T const& value) {
361 _valueCacheMap[id][key] = value;
362 }
363 template <typename T>
364 T GetParameter(SdfPath const& id, TfToken const& key) const {
365 VtValue vParams;
366 _ValueCache vCache;
367 TF_VERIFY(
368 TfMapLookup(_valueCacheMap, id, &vCache) &&
369 TfMapLookup(vCache, key, &vParams) &&
370 vParams.IsHolding<T>());
371 return vParams.Get<T>();
372 }
373 bool HasParameter(SdfPath const& id, TfToken const& key) const {
374 _ValueCache vCache;
375 if (TfMapLookup(_valueCacheMap, id, &vCache) &&
376 vCache.count(key) > 0) {
377 return true;
378 }
379 return false;
380 }
381
382 // HdSceneDelegate interface
383 VtValue Get(SdfPath const& id, TfToken const& key) override;
384 GfMatrix4d GetTransform(SdfPath const& id) override;
385 VtValue GetLightParamValue(SdfPath const& id,
386 TfToken const& paramName) override;
387 VtValue GetMaterialResource(SdfPath const& id) override;
388 bool IsEnabled(TfToken const& option) const override;
390 GetRenderBufferDescriptor(SdfPath const& id) override;
391 TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
392
393
394 private:
395 using _ValueCache = TfHashMap<TfToken, VtValue, TfToken::HashFunctor>;
396 using _ValueCacheMap = TfHashMap<SdfPath, _ValueCache, SdfPath::Hash>;
397 _ValueCacheMap _valueCacheMap;
398 };
399 _Delegate _delegate;
400 std::unique_ptr<class HdxFreeCameraSceneDelegate> _freeCameraSceneDelegate;
401
402 // Generated tasks.
403 SdfPath _simpleLightTaskId;
404 SdfPath _shadowTaskId;
405 SdfPathVector _renderTaskIds;
406 SdfPath _aovInputTaskId;
407 SdfPath _oitResolveTaskId;
408 SdfPath _selectionTaskId;
409 SdfPath _colorizeSelectionTaskId;
410 SdfPath _colorCorrectionTaskId;
411 SdfPath _visualizeAovTaskId;
412 SdfPath _pickTaskId;
413 SdfPath _pickFromRenderBufferTaskId;
414 SdfPath _boundingBoxTaskId;
415 SdfPath _presentTaskId;
416
417 // Current active camera
418 SdfPath _activeCameraId;
419
420 // Built-in lights
421 SdfPathVector _lightIds;
422
423 // Generated renderbuffers
424 SdfPathVector _aovBufferIds;
425 TfTokenVector _aovOutputs;
426 TfToken _viewportAov;
427
428 GfVec2i _renderBufferSize;
429 CameraUtilFraming _framing;
430 std::optional<CameraUtilConformWindowPolicy> _overrideWindowPolicy;
431
432 GfVec4d _viewport;
433};
434
435PXR_NAMESPACE_CLOSE_SCOPE
436
437#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:274
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