All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/colorChannelTask.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/conformWindow.h"
42 
43 #include "pxr/imaging/glf/simpleLightingContext.h"
44 #include "pxr/usd/sdf/path.h"
45 #include "pxr/base/tf/staticTokens.h"
46 #include "pxr/base/gf/matrix4d.h"
47 
48 PXR_NAMESPACE_OPEN_SCOPE
49 
50 // XXX: This API is transitional. At the least, render/picking/selection
51 // APIs should be decoupled.
52 
53 class HdRenderBuffer;
54 
55 class HdxTaskController {
56 public:
57  HDX_API
58  HdxTaskController(HdRenderIndex *renderIndex,
59  SdfPath const& controllerId);
60  HDX_API
61  ~HdxTaskController();
62 
64  HdRenderIndex* GetRenderIndex() { return _index; }
65  HdRenderIndex const* GetRenderIndex() const { return _index; }
66 
69  SdfPath const& GetControllerId() const { return _controllerId; }
70 
73 
77  HDX_API
78  HdTaskSharedPtrVector const GetRenderingTasks() const;
79 
82  HDX_API
83  HdTaskSharedPtrVector const GetPickingTasks() const;
84 
87 
89  HDX_API
90  void SetCollection(HdRprimCollection const& collection);
91 
96  HDX_API
97  void SetRenderParams(HdxRenderTaskParams const& params);
98 
103  HDX_API
104  void SetRenderTags(TfTokenVector const& renderTags);
105 
108 
112  HDX_API
113  void SetRenderOutputs(TfTokenVector const& names);
114 
117  HDX_API
118  void SetViewportRenderOutput(TfToken const& name);
119 
123  HDX_API
124  HdRenderBuffer* GetRenderOutput(TfToken const& name);
125 
127  HDX_API
128  void SetRenderOutputSettings(TfToken const& name,
129  HdAovDescriptor const& desc);
130 
131  // Get parameters for an AOV.
132  HDX_API
133  HdAovDescriptor GetRenderOutputSettings(TfToken const& name) const;
134 
137 
141  HDX_API
142  void SetLightingState(GlfSimpleLightingContextPtr const& src);
143 
146 
148  HDX_API
149  void SetRenderViewport(GfVec4d const& viewport);
150 
153  HDX_API
154  void SetCameraPath(SdfPath const& id);
155 
159  HDX_API
160  void SetFreeCameraMatrices(GfMatrix4d const& viewMatrix,
161  GfMatrix4d const& projectionMatrix);
164  HDX_API
165  void SetFreeCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
166 
169 
171  HDX_API
172  void SetEnableSelection(bool enable);
173 
175  HDX_API
176  void SetSelectionColor(GfVec4f const& color);
177 
180 
182  HDX_API
183  void SetEnableShadows(bool enable);
184 
187  HDX_API
188  void SetShadowParams(HdxShadowTaskParams const& params);
189 
192 
194  HDX_API
195  bool IsConverged() const;
196 
199 
201  HDX_API
202  void SetColorCorrectionParams(HdxColorCorrectionTaskParams const& params);
203 
206 
208  HDX_API
209  void SetColorChannelParams(HdxColorChannelTaskParams const& params);
210 
213 
216  // avoid calling it.
217  HDX_API
218  void SetColorizeQuantizationEnabled(bool enabled);
219 
220 private:
224  HdxTaskController(HdxTaskController const&) = delete;
225  HdxTaskController &operator=(HdxTaskController const&) = delete;
226 
227  HdRenderIndex *_index;
228  SdfPath const _controllerId;
229 
230  // Create taskController objects. Since the camera is a parameter
231  // to the tasks, _CreateCamera() should be called first.
232  void _CreateRenderGraph();
233 
234  void _CreateCamera();
235  void _CreateLightingTask();
236  void _CreateShadowTask();
237  SdfPath _CreateRenderTask(TfToken const& materialTag);
238  void _CreateOitResolveTask();
239  void _CreateSelectionTask();
240  void _CreateColorizeTask();
241  void _CreateColorizeSelectionTask();
242  void _CreateColorCorrectionTask();
243  void _CreateColorChannelTask();
244  void _CreatePickTask();
245  void _CreatePickFromRenderBufferTask();
246  SdfPath _CreateAovResolveTask(TfToken const& aovName);
247  void _CreatePresentTask();
248 
249  void _SetCameraParamForTasks(SdfPath const& id);
250 
251  void _SetBlendStateForMaterialTag(TfToken const& materialTag,
252  HdxRenderTaskParams *renderParams) const;
253 
254  // Render graph topology control.
255  bool _ShadowsEnabled() const;
256  bool _SelectionEnabled() const;
257  bool _ColorizeSelectionEnabled() const;
258  bool _ColorCorrectionEnabled() const;
259  bool _ColorChannelEnabled() const;
260  bool _ColorizeQuantizationEnabled() const;
261  bool _AovsSupported() const;
262 
263  // Helper function for renderbuffer management.
264  SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
265  SdfPath _GetAovPath(TfToken const& aov) const;
266  SdfPathVector _GetAovEnabledTasks() const;
267 
268  // Helper function to load the default domeLight texture
269  void _LoadDefaultDomeLightTexture();
270 
271  // Helper function to set the parameters of a light, get a particular light
272  // in the scene, replace and remove Sprims from the scene
273  void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
274  GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
275  void _RemoveLightSprim(size_t const& pathIdx);
276  void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
277  SdfPath const& pathName);
278 
279  // A private scene delegate member variable backs the tasks and the free cam
280  // this controller generates. To keep _Delegate simple, the containing class
281  // is responsible for marking things dirty.
282  class _Delegate : public HdSceneDelegate
283  {
284  public:
285  _Delegate(HdRenderIndex *parentIndex,
286  SdfPath const& delegateID)
287  : HdSceneDelegate(parentIndex, delegateID)
288  {}
289  virtual ~_Delegate() = default;
290 
291  // HdxTaskController set/get interface
292  template <typename T>
293  void SetParameter(SdfPath const& id, TfToken const& key,
294  T const& value) {
295  _valueCacheMap[id][key] = value;
296  }
297  template <typename T>
298  T GetParameter(SdfPath const& id, TfToken const& key) const {
299  VtValue vParams;
300  _ValueCache vCache;
301  TF_VERIFY(
302  TfMapLookup(_valueCacheMap, id, &vCache) &&
303  TfMapLookup(vCache, key, &vParams) &&
304  vParams.IsHolding<T>());
305  return vParams.Get<T>();
306  }
307  bool HasParameter(SdfPath const& id, TfToken const& key) const {
308  _ValueCache vCache;
309  if (TfMapLookup(_valueCacheMap, id, &vCache) &&
310  vCache.count(key) > 0) {
311  return true;
312  }
313  return false;
314  }
315 
316  // HdSceneDelegate interface
317  virtual VtValue Get(SdfPath const& id, TfToken const& key);
318  virtual GfMatrix4d GetTransform(SdfPath const& id);
319  virtual VtValue GetCameraParamValue(SdfPath const& id,
320  TfToken const& key);
321  virtual VtValue GetLightParamValue(SdfPath const& id,
322  TfToken const& paramName);
323  virtual bool IsEnabled(TfToken const& option) const;
325  GetRenderBufferDescriptor(SdfPath const& id);
326  virtual TfTokenVector GetTaskRenderTags(SdfPath const& taskId);
327 
328 
329  private:
330  typedef TfHashMap<TfToken, VtValue, TfToken::HashFunctor> _ValueCache;
331  typedef TfHashMap<SdfPath, _ValueCache, SdfPath::Hash> _ValueCacheMap;
332  _ValueCacheMap _valueCacheMap;
333  };
334  _Delegate _delegate;
335 
336  // Generated tasks.
337  SdfPath _simpleLightTaskId;
338  SdfPath _shadowTaskId;
339  SdfPathVector _renderTaskIds;
340  SdfPath _oitResolveTaskId;
341  SdfPath _selectionTaskId;
342  SdfPath _colorizeSelectionTaskId;
343  SdfPath _colorizeTaskId;
344  SdfPath _colorCorrectionTaskId;
345  SdfPath _colorChannelTaskId;
346  SdfPath _pickTaskId;
347  SdfPath _pickFromRenderBufferTaskId;
348  SdfPath _aovColorResolveTaskId;
349  SdfPath _aovDepthResolveTaskId;
350  SdfPath _presentTaskId;
351 
352  // Generated camera (for the default/free cam)
353  SdfPath _freeCamId;
354  // Current active camera
355  SdfPath _activeCameraId;
356 
357  // Built-in lights
358  SdfPathVector _lightIds;
359  HdTextureResourceSharedPtr _defaultDomeLightTextureResource;
360 
361  // Generated renderbuffers
362  SdfPathVector _aovBufferIds;
363  TfTokenVector _aovOutputs;
364  TfToken _viewportAov;
365 };
366 
367 PXR_NAMESPACE_CLOSE_SCOPE
368 
369 #endif // PXR_IMAGING_HDX_TASK_CONTROLLER_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:117
ColorChannelTask parameters.
Describes the allocation structure of a render buffer bprim.
Definition: aov.h:84
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:808
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
T const & Get() const
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:847
ColorCorrectionTask parameters.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
RenderTask parameters (renderpass state).
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:289
Adapter class providing data exchange with the client scene graph.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:433
bool TfMapLookup(Container const &map, Key const &key, Result *valuePtr)
Checks if an item exists in a map or a TfHashMap.
Definition: stl.h:88
A named, semantic collection of objects.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
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:51
A bundle of state describing an AOV (&quot;Alternate Output Value&quot;) display channel.
Definition: aov.h:46
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182