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 HdTaskSharedPtrVector const GetRenderingTasks() const;
64
67 HDX_API
68 HdTaskSharedPtrVector const GetPickingTasks() const;
69
72
74 HDX_API
75 void SetCollection(HdRprimCollection const& collection);
76
81 HDX_API
82 void SetRenderParams(HdxRenderTaskParams const& params);
83
88 HDX_API
89 void SetRenderTags(TfTokenVector const& renderTags);
90
93
97 HDX_API
98 void SetRenderOutputs(TfTokenVector const& names);
99
102 HDX_API
103 void SetViewportRenderOutput(TfToken const& name);
104
108 HDX_API
109 HdRenderBuffer* GetRenderOutput(TfToken const& name);
110
112 HDX_API
113 void SetRenderOutputSettings(TfToken const& name,
114 HdAovDescriptor const& desc);
115
117 HDX_API
118 HdAovDescriptor GetRenderOutputSettings(TfToken const& name) const;
119
125 HDX_API
126 void SetPresentationOutput(TfToken const &api, VtValue const &framebuffer);
127
130
134 HDX_API
135 void SetLightingState(GlfSimpleLightingContextPtr const& src);
136
139
143 HDX_API
144 void SetRenderBufferSize(const GfVec2i &size);
145
149 HDX_API
150 void SetFraming(const CameraUtilFraming &framing);
151
155 HDX_API
156 void SetOverrideWindowPolicy(
157 const std::optional<CameraUtilConformWindowPolicy> &policy);
158
161 HDX_API
162 void SetCameraPath(SdfPath const& id);
163
167 HDX_API
168 void SetRenderViewport(GfVec4d const& viewport);
169
173 HDX_API
174 void SetFreeCameraMatrices(GfMatrix4d const& viewMatrix,
175 GfMatrix4d const& projectionMatrix);
178 HDX_API
179 void SetFreeCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
180
183
185 HDX_API
186 void SetEnableSelection(bool enable);
187
189 HDX_API
190 void SetSelectionColor(GfVec4f const& color);
191
193 HDX_API
194 void SetSelectionLocateColor(GfVec4f const& color);
195
198 HDX_API
199 void SetSelectionEnableOutline(bool enableOutline);
200
204 HDX_API
205 void SetSelectionOutlineRadius(unsigned int radius);
206
209
211 HDX_API
212 void SetEnableShadows(bool enable);
213
216 HDX_API
217 void SetShadowParams(HdxShadowTaskParams const& params);
218
221
223 HDX_API
224 bool IsConverged() const;
225
228
230 HDX_API
231 void SetColorCorrectionParams(HdxColorCorrectionTaskParams const& params);
232
235
237 HDX_API
238 void SetBBoxParams(const HdxBoundingBoxTaskParams& params);
239
242
246 HDX_API
247 void SetEnablePresentation(bool enabled);
248
249private:
253 HdxTaskController(HdxTaskController const&) = delete;
254 HdxTaskController &operator=(HdxTaskController const&) = delete;
255
256 HdRenderIndex *_index;
257 SdfPath const _controllerId;
258 bool _gpuEnabled;
259
260 // Create taskController objects. Since the camera is a parameter
261 // to the tasks, _CreateCamera() should be called first.
262 void _CreateRenderGraph();
263
264 void _CreateLightingTask();
265 void _CreateShadowTask();
266 SdfPath _CreateSkydomeTask();
267 SdfPath _CreateRenderTask(TfToken const& materialTag);
268 void _CreateOitResolveTask();
269 void _CreateSelectionTask();
270 void _CreateColorizeSelectionTask();
271 void _CreateColorCorrectionTask();
272 void _CreateVisualizeAovTask();
273 void _CreatePickTask();
274 void _CreatePickFromRenderBufferTask();
275 void _CreateBoundingBoxTask();
276 void _CreateAovInputTask();
277 void _CreatePresentTask();
278
279 void _SetCameraParamForTasks(SdfPath const& id);
280 void _SetCameraFramingForTasks();
281 void _UpdateAovDimensions(GfVec2i const& dimensions);
282
283 void _SetBlendStateForMaterialTag(TfToken const& materialTag,
284 HdxRenderTaskParams *renderParams) const;
285
286 // Render graph topology control.
287 bool _ShadowsEnabled() const;
288 bool _SelectionEnabled() const;
289 bool _ColorizeSelectionEnabled() const;
290 bool _ColorCorrectionEnabled() const;
291 bool _VisualizeAovEnabled() const;
292 bool _ColorizeQuantizationEnabled() const;
293 bool _AovsSupported() const;
294 bool _UsingAovs() const;
295
296 // Helper function for renderbuffer management.
297 SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
298 SdfPath _GetAovPath(TfToken const& aov) const;
299 SdfPathVector _GetAovEnabledTasks() const;
300
301 // Helper functions to set up the lighting state for the built-in lights
302 bool _SupportBuiltInLightTypes();
303 void _SetBuiltInLightingState(GlfSimpleLightingContextPtr const& src);
304
305 // Helper function to get the built-in Camera light type SimpleLight for
306 // Storm, and DistantLight otherwise
307 TfToken _GetCameraLightType();
308
309 // Helper functions to set the parameters of a light, get a particular light
310 // in the scene, replace and remove Sprims from the scene
311 VtValue _GetDomeLightTexture(GlfSimpleLight const& light);
312 void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
313 void _SetMaterialNetwork(SdfPath const& pathName,
314 GlfSimpleLight const& light);
315 GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
316 void _RemoveLightSprim(size_t const& pathIdx);
317 void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
318 SdfPath const& pathName);
319
320 // A private scene delegate member variable backs the tasks and the free cam
321 // this controller generates. To keep _Delegate simple, the containing class
322 // is responsible for marking things dirty.
323 class _Delegate : public HdSceneDelegate
324 {
325 public:
326 _Delegate(HdRenderIndex *parentIndex,
327 SdfPath const& delegateID)
328 : HdSceneDelegate(parentIndex, delegateID)
329 {}
330 ~_Delegate() override = default;
331
332 // HdxTaskController set/get interface
333 template <typename T>
334 void SetParameter(SdfPath const& id, TfToken const& key,
335 T const& value) {
336 _valueCacheMap[id][key] = value;
337 }
338 template <typename T>
339 T GetParameter(SdfPath const& id, TfToken const& key) const {
340 VtValue vParams;
341 _ValueCache vCache;
342 TF_VERIFY(
343 TfMapLookup(_valueCacheMap, id, &vCache) &&
344 TfMapLookup(vCache, key, &vParams) &&
345 vParams.IsHolding<T>());
346 return vParams.Get<T>();
347 }
348 bool HasParameter(SdfPath const& id, TfToken const& key) const {
349 _ValueCache vCache;
350 if (TfMapLookup(_valueCacheMap, id, &vCache) &&
351 vCache.count(key) > 0) {
352 return true;
353 }
354 return false;
355 }
356
357 // HdSceneDelegate interface
358 VtValue Get(SdfPath const& id, TfToken const& key) override;
359 GfMatrix4d GetTransform(SdfPath const& id) override;
360 VtValue GetLightParamValue(SdfPath const& id,
361 TfToken const& paramName) override;
362 VtValue GetMaterialResource(SdfPath const& id) override;
363 bool IsEnabled(TfToken const& option) const override;
365 GetRenderBufferDescriptor(SdfPath const& id) override;
366 TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
367
368
369 private:
370 using _ValueCache = TfHashMap<TfToken, VtValue, TfToken::HashFunctor>;
371 using _ValueCacheMap = TfHashMap<SdfPath, _ValueCache, SdfPath::Hash>;
372 _ValueCacheMap _valueCacheMap;
373 };
374 _Delegate _delegate;
375 std::unique_ptr<class HdxFreeCameraSceneDelegate> _freeCameraSceneDelegate;
376
377 // Generated tasks.
378 SdfPath _simpleLightTaskId;
379 SdfPath _shadowTaskId;
380 SdfPathVector _renderTaskIds;
381 SdfPath _aovInputTaskId;
382 SdfPath _oitResolveTaskId;
383 SdfPath _selectionTaskId;
384 SdfPath _colorizeSelectionTaskId;
385 SdfPath _colorCorrectionTaskId;
386 SdfPath _visualizeAovTaskId;
387 SdfPath _pickTaskId;
388 SdfPath _pickFromRenderBufferTaskId;
389 SdfPath _boundingBoxTaskId;
390 SdfPath _presentTaskId;
391
392 // Current active camera
393 SdfPath _activeCameraId;
394
395 // Built-in lights
396 SdfPathVector _lightIds;
397
398 // Generated renderbuffers
399 SdfPathVector _aovBufferIds;
400 TfTokenVector _aovOutputs;
401 TfToken _viewportAov;
402
403 GfVec2i _renderBufferSize;
404 CameraUtilFraming _framing;
405 std::optional<CameraUtilConformWindowPolicy> _overrideWindowPolicy;
406
407 GfVec4d _viewport;
408};
409
410PXR_NAMESPACE_CLOSE_SCOPE
411
412#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:104
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:147
T const & Get() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1120
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1064
#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