Loading...
Searching...
No Matches
taskController.h
1//
2// Copyright 2017 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_IMAGING_HDX_TASK_CONTROLLER_H
25#define PXR_IMAGING_HDX_TASK_CONTROLLER_H
26
27#include "pxr/pxr.h"
28
29#include "pxr/imaging/hdx/api.h"
30#include "pxr/imaging/hdx/selectionTracker.h"
31#include "pxr/imaging/hdx/renderSetupTask.h"
32#include "pxr/imaging/hdx/shadowTask.h"
33#include "pxr/imaging/hdx/colorCorrectionTask.h"
34#include "pxr/imaging/hdx/boundingBoxTask.h"
35
36#include "pxr/imaging/hd/aov.h"
37#include "pxr/imaging/hd/renderIndex.h"
38#include "pxr/imaging/hd/sceneDelegate.h"
39#include "pxr/imaging/hd/task.h"
40
41#include "pxr/imaging/cameraUtil/framing.h"
43#include "pxr/usd/sdf/path.h"
44
45#include "pxr/base/gf/bbox3d.h"
47
48PXR_NAMESPACE_OPEN_SCOPE
49
50// XXX: This API is transitional. At the least, render/picking/selection
51// APIs should be decoupled.
52
53class HdRenderBuffer;
54
55class HdxTaskController final
56{
57public:
58 HDX_API
59 HdxTaskController(HdRenderIndex *renderIndex,
60 SdfPath const& controllerId,
61 bool gpuEnabled = true);
62 HDX_API
63 ~HdxTaskController();
64
66 HdRenderIndex* GetRenderIndex() { return _index; }
67 HdRenderIndex const* GetRenderIndex() const { return _index; }
68
71 SdfPath const& GetControllerId() const { return _controllerId; }
72
75
79 HDX_API
80 HdTaskSharedPtrVector const GetRenderingTasks() const;
81
84 HDX_API
85 HdTaskSharedPtrVector const GetPickingTasks() const;
86
89
91 HDX_API
92 void SetCollection(HdRprimCollection const& collection);
93
98 HDX_API
99 void SetRenderParams(HdxRenderTaskParams const& params);
100
105 HDX_API
106 void SetRenderTags(TfTokenVector const& renderTags);
107
110
114 HDX_API
115 void SetRenderOutputs(TfTokenVector const& names);
116
119 HDX_API
120 void SetViewportRenderOutput(TfToken const& name);
121
125 HDX_API
126 HdRenderBuffer* GetRenderOutput(TfToken const& name);
127
129 HDX_API
130 void SetRenderOutputSettings(TfToken const& name,
131 HdAovDescriptor const& desc);
132
134 HDX_API
135 HdAovDescriptor GetRenderOutputSettings(TfToken const& name) const;
136
142 HDX_API
143 void SetPresentationOutput(TfToken const &api, VtValue const &framebuffer);
144
147
151 HDX_API
152 void SetLightingState(GlfSimpleLightingContextPtr const& src);
153
156
160 HDX_API
161 void SetRenderBufferSize(const GfVec2i &size);
162
166 HDX_API
167 void SetFraming(const CameraUtilFraming &framing);
168
172 HDX_API
173 void SetOverrideWindowPolicy(
174 const std::optional<CameraUtilConformWindowPolicy> &policy);
175
178 HDX_API
179 void SetCameraPath(SdfPath const& id);
180
184 HDX_API
185 void SetRenderViewport(GfVec4d const& viewport);
186
190 HDX_API
191 void SetFreeCameraMatrices(GfMatrix4d const& viewMatrix,
192 GfMatrix4d const& projectionMatrix);
195 HDX_API
196 void SetFreeCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
197
200
202 HDX_API
203 void SetEnableSelection(bool enable);
204
206 HDX_API
207 void SetSelectionColor(GfVec4f const& color);
208
210 HDX_API
211 void SetSelectionLocateColor(GfVec4f const& color);
212
215 HDX_API
216 void SetSelectionEnableOutline(bool enableOutline);
217
221 HDX_API
222 void SetSelectionOutlineRadius(unsigned int radius);
223
226
228 HDX_API
229 void SetEnableShadows(bool enable);
230
233 HDX_API
234 void SetShadowParams(HdxShadowTaskParams const& params);
235
238
240 HDX_API
241 bool IsConverged() const;
242
245
247 HDX_API
248 void SetColorCorrectionParams(HdxColorCorrectionTaskParams const& params);
249
252
254 HDX_API
255 void SetBBoxParams(const HdxBoundingBoxTaskParams& params);
256
259
263 HDX_API
264 void SetEnablePresentation(bool enabled);
265
266private:
270 HdxTaskController(HdxTaskController const&) = delete;
271 HdxTaskController &operator=(HdxTaskController const&) = delete;
272
273 HdRenderIndex *_index;
274 SdfPath const _controllerId;
275 bool _gpuEnabled;
276
277 // Create taskController objects. Since the camera is a parameter
278 // to the tasks, _CreateCamera() should be called first.
279 void _CreateRenderGraph();
280
281 void _CreateLightingTask();
282 void _CreateShadowTask();
283 SdfPath _CreateSkydomeTask();
284 SdfPath _CreateRenderTask(TfToken const& materialTag);
285 void _CreateOitResolveTask();
286 void _CreateSelectionTask();
287 void _CreateColorizeSelectionTask();
288 void _CreateColorCorrectionTask();
289 void _CreateVisualizeAovTask();
290 void _CreatePickTask();
291 void _CreatePickFromRenderBufferTask();
292 void _CreateBoundingBoxTask();
293 void _CreateAovInputTask();
294 void _CreatePresentTask();
295
296 void _SetCameraParamForTasks(SdfPath const& id);
297 void _SetCameraFramingForTasks();
298 void _UpdateAovDimensions(GfVec2i const& dimensions);
299
300 void _SetBlendStateForMaterialTag(TfToken const& materialTag,
301 HdxRenderTaskParams *renderParams) const;
302
303 // Render graph topology control.
304 bool _ShadowsEnabled() const;
305 bool _SelectionEnabled() const;
306 bool _ColorizeSelectionEnabled() const;
307 bool _ColorCorrectionEnabled() const;
308 bool _VisualizeAovEnabled() const;
309 bool _ColorizeQuantizationEnabled() const;
310 bool _AovsSupported() const;
311 bool _UsingAovs() const;
312
313 // Helper function for renderbuffer management.
314 SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
315 SdfPath _GetAovPath(TfToken const& aov) const;
316 SdfPathVector _GetAovEnabledTasks() const;
317
318 // Helper functions to set up the lighting state for the built-in lights
319 bool _SupportBuiltInLightTypes();
320 void _SetBuiltInLightingState(GlfSimpleLightingContextPtr const& src);
321
322 // Helper function to get the built-in Camera light type SimpleLight for
323 // Storm, and DistantLight otherwise
324 TfToken _GetCameraLightType();
325
326 // Helper functions to set the parameters of a light, get a particular light
327 // in the scene, replace and remove Sprims from the scene
328 VtValue _GetDomeLightTexture(GlfSimpleLight const& light);
329 void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
330 void _SetMaterialNetwork(SdfPath const& pathName,
331 GlfSimpleLight const& light);
332 GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
333 void _RemoveLightSprim(size_t const& pathIdx);
334 void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
335 SdfPath const& pathName);
336
337 // A private scene delegate member variable backs the tasks and the free cam
338 // this controller generates. To keep _Delegate simple, the containing class
339 // is responsible for marking things dirty.
340 class _Delegate : public HdSceneDelegate
341 {
342 public:
343 _Delegate(HdRenderIndex *parentIndex,
344 SdfPath const& delegateID)
345 : HdSceneDelegate(parentIndex, delegateID)
346 {}
347 ~_Delegate() override = default;
348
349 // HdxTaskController set/get interface
350 template <typename T>
351 void SetParameter(SdfPath const& id, TfToken const& key,
352 T const& value) {
353 _valueCacheMap[id][key] = value;
354 }
355 template <typename T>
356 T GetParameter(SdfPath const& id, TfToken const& key) const {
357 VtValue vParams;
358 _ValueCache vCache;
359 TF_VERIFY(
360 TfMapLookup(_valueCacheMap, id, &vCache) &&
361 TfMapLookup(vCache, key, &vParams) &&
362 vParams.IsHolding<T>());
363 return vParams.Get<T>();
364 }
365 bool HasParameter(SdfPath const& id, TfToken const& key) const {
366 _ValueCache vCache;
367 if (TfMapLookup(_valueCacheMap, id, &vCache) &&
368 vCache.count(key) > 0) {
369 return true;
370 }
371 return false;
372 }
373
374 // HdSceneDelegate interface
375 VtValue Get(SdfPath const& id, TfToken const& key) override;
376 GfMatrix4d GetTransform(SdfPath const& id) override;
377 VtValue GetLightParamValue(SdfPath const& id,
378 TfToken const& paramName) override;
379 VtValue GetMaterialResource(SdfPath const& id) override;
380 bool IsEnabled(TfToken const& option) const override;
382 GetRenderBufferDescriptor(SdfPath const& id) override;
383 TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
384
385
386 private:
387 using _ValueCache = TfHashMap<TfToken, VtValue, TfToken::HashFunctor>;
388 using _ValueCacheMap = TfHashMap<SdfPath, _ValueCache, SdfPath::Hash>;
389 _ValueCacheMap _valueCacheMap;
390 };
391 _Delegate _delegate;
392 std::unique_ptr<class HdxFreeCameraSceneDelegate> _freeCameraSceneDelegate;
393
394 // Generated tasks.
395 SdfPath _simpleLightTaskId;
396 SdfPath _shadowTaskId;
397 SdfPathVector _renderTaskIds;
398 SdfPath _aovInputTaskId;
399 SdfPath _oitResolveTaskId;
400 SdfPath _selectionTaskId;
401 SdfPath _colorizeSelectionTaskId;
402 SdfPath _colorCorrectionTaskId;
403 SdfPath _visualizeAovTaskId;
404 SdfPath _pickTaskId;
405 SdfPath _pickFromRenderBufferTaskId;
406 SdfPath _boundingBoxTaskId;
407 SdfPath _presentTaskId;
408
409 // Current active camera
410 SdfPath _activeCameraId;
411
412 // Built-in lights
413 SdfPathVector _lightIds;
414
415 // Generated renderbuffers
416 SdfPathVector _aovBufferIds;
417 TfTokenVector _aovOutputs;
418 TfToken _viewportAov;
419
420 GfVec2i _renderBufferSize;
421 CameraUtilFraming _framing;
422 std::optional<CameraUtilConformWindowPolicy> _overrideWindowPolicy;
423
424 GfVec4d _viewport;
425};
426
427PXR_NAMESPACE_CLOSE_SCOPE
428
429#endif // PXR_IMAGING_HDX_TASK_CONTROLLER_H
Framing information.
Definition: framing.h:80
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
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:50
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:121
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:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:164
T const & Get() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1137
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1081
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:283
bool TfMapLookup(Container const &map, Key const &key, Result *valuePtr)
Checks if an item exists in a map or a TfHashMap.
Definition: stl.h:86
A bundle of state describing an AOV ("Arbitrary Output Variable") display channel.
Definition: aov.h:47
Describes the allocation structure of a render buffer bprim.
Definition: aov.h:84
BoundingBoxTask parameters.
ColorCorrectionTask parameters.
RenderTask parameters (renderpass state).
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457