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 HDX_TASK_CONTROLLER_H
25 #define 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 
35 #include "pxr/imaging/hd/aov.h"
36 #include "pxr/imaging/hd/renderIndex.h"
37 #include "pxr/imaging/hd/sceneDelegate.h"
38 #include "pxr/imaging/hd/task.h"
39 
40 #include "pxr/imaging/cameraUtil/conformWindow.h"
41 
42 #include "pxr/imaging/glf/simpleLightingContext.h"
43 #include "pxr/usd/sdf/path.h"
44 #include "pxr/base/tf/staticTokens.h"
45 #include "pxr/base/gf/matrix4d.h"
46 
47 PXR_NAMESPACE_OPEN_SCOPE
48 
49 // XXX: This API is transitional. At the least, render/picking/selection
50 // APIs should be decoupled.
51 
52 class HdRenderBuffer;
53 
54 class HdxTaskController {
55 public:
56  HDX_API
57  HdxTaskController(HdRenderIndex *renderIndex,
58  SdfPath const& controllerId);
59  HDX_API
60  ~HdxTaskController();
61 
63  HdRenderIndex* GetRenderIndex() { return _index; }
64  HdRenderIndex const* GetRenderIndex() const { return _index; }
65 
68  SdfPath const& GetControllerId() const { return _controllerId; }
69 
72 
76  HDX_API
77  HdTaskSharedPtrVector const GetRenderingTasks() const;
78 
81  HDX_API
82  HdTaskSharedPtrVector const GetPickingTasks() const;
83 
86 
88  HDX_API
89  void SetCollection(HdRprimCollection const& collection);
90 
95  HDX_API
96  void SetRenderParams(HdxRenderTaskParams const& params);
97 
102  HDX_API
103  void SetRenderTags(TfTokenVector const& renderTags);
104 
107 
111  HDX_API
112  void SetRenderOutputs(TfTokenVector const& names);
113 
116  HDX_API
117  void SetViewportRenderOutput(TfToken const& name);
118 
122  HDX_API
123  HdRenderBuffer* GetRenderOutput(TfToken const& name);
124 
126  HDX_API
127  void SetRenderOutputSettings(TfToken const& name,
128  HdAovDescriptor const& desc);
129 
130  // Get parameters for an AOV.
131  HDX_API
132  HdAovDescriptor GetRenderOutputSettings(TfToken const& name) const;
133 
136 
140  HDX_API
141  void SetLightingState(GlfSimpleLightingContextPtr const& src);
142 
145 
147  HDX_API
148  void SetRenderViewport(GfVec4d const& viewport);
149 
152  HDX_API
153  void SetCameraPath(SdfPath const& id);
154 
158  HDX_API
159  void SetFreeCameraMatrices(GfMatrix4d const& viewMatrix,
160  GfMatrix4d const& projectionMatrix);
163  HDX_API
164  void SetFreeCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
165 
168 
170  HDX_API
171  void SetEnableSelection(bool enable);
172 
174  HDX_API
175  void SetSelectionColor(GfVec4f const& color);
176 
179 
181  HDX_API
182  void SetEnableShadows(bool enable);
183 
186  HDX_API
187  void SetShadowParams(HdxShadowTaskParams const& params);
188 
191 
193  HDX_API
194  bool IsConverged() const;
195 
198 
200  HDX_API
201  void SetColorCorrectionParams(HdxColorCorrectionTaskParams const& params);
202 
203 private:
207  HdxTaskController(HdxTaskController const&) = delete;
208  HdxTaskController &operator=(HdxTaskController const&) = delete;
209 
210  HdRenderIndex *_index;
211  SdfPath const _controllerId;
212 
213  // Create taskController objects. Since the camera is a parameter
214  // to the tasks, _CreateCamera() should be called first.
215  void _CreateRenderGraph();
216 
217  void _CreateCamera();
218  void _CreateLightingTask();
219  void _CreateShadowTask();
220  SdfPath _CreateRenderTask(TfToken const& materialTag);
221  void _CreateOitResolveTask();
222  void _CreateSelectionTask();
223  void _CreateColorizeTask();
224  void _CreateColorizeSelectionTask();
225  void _CreateColorCorrectionTask();
226  void _CreatePickTask();
227  void _CreatePickFromRenderBufferTask();
228  SdfPath _CreateAovResolveTask(TfToken const& aovName);
229  void _CreatePresentTask();
230 
231  void _SetCameraParamForTasks(SdfPath const& id);
232 
233  void _SetBlendStateForMaterialTag(TfToken const& materialTag,
234  HdxRenderTaskParams *renderParams) const;
235 
236  void _SetColorizeQuantizationEnabled(bool enabled);
237 
238  // Render graph topology control.
239  bool _ShadowsEnabled() const;
240  bool _SelectionEnabled() const;
241  bool _ColorizeSelectionEnabled() const;
242  bool _ColorCorrectionEnabled() const;
243  bool _ColorizeQuantizationEnabled() const;
244  bool _AovsSupported() const;
245 
246  // Helper function for renderbuffer management.
247  SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
248  SdfPath _GetAovPath(TfToken const& aov) const;
249  SdfPathVector _GetAovEnabledTasks() const;
250 
251  // Helper function to load the default domeLight texture
252  void _LoadDefaultDomeLightTexture();
253 
254  // Helper function to set the parameters of a light, get a particular light
255  // in the scene, replace and remove Sprims from the scene
256  void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
257  GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
258  void _RemoveLightSprim(size_t const& pathIdx);
259  void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
260  SdfPath const& pathName);
261 
262  // A private scene delegate member variable backs the tasks and the free cam
263  // this controller generates. To keep _Delegate simple, the containing class
264  // is responsible for marking things dirty.
265  class _Delegate : public HdSceneDelegate
266  {
267  public:
268  _Delegate(HdRenderIndex *parentIndex,
269  SdfPath const& delegateID)
270  : HdSceneDelegate(parentIndex, delegateID)
271  {}
272  virtual ~_Delegate() = default;
273 
274  // HdxTaskController set/get interface
275  template <typename T>
276  void SetParameter(SdfPath const& id, TfToken const& key,
277  T const& value) {
278  _valueCacheMap[id][key] = value;
279  }
280  template <typename T>
281  T const& GetParameter(SdfPath const& id, TfToken const& key) const {
282  VtValue vParams;
283  _ValueCache vCache;
284  TF_VERIFY(
285  TfMapLookup(_valueCacheMap, id, &vCache) &&
286  TfMapLookup(vCache, key, &vParams) &&
287  vParams.IsHolding<T>());
288  return vParams.Get<T>();
289  }
290  bool HasParameter(SdfPath const& id, TfToken const& key) const {
291  _ValueCache vCache;
292  if (TfMapLookup(_valueCacheMap, id, &vCache) &&
293  vCache.count(key) > 0) {
294  return true;
295  }
296  return false;
297  }
298 
299  // HdSceneDelegate interface
300  virtual VtValue Get(SdfPath const& id, TfToken const& key);
301  virtual GfMatrix4d GetTransform(SdfPath const& id);
302  virtual VtValue GetCameraParamValue(SdfPath const& id,
303  TfToken const& key);
304  virtual VtValue GetLightParamValue(SdfPath const& id,
305  TfToken const& paramName);
306  virtual bool IsEnabled(TfToken const& option) const;
308  GetRenderBufferDescriptor(SdfPath const& id);
309  virtual TfTokenVector GetTaskRenderTags(SdfPath const& taskId);
310 
311 
312  private:
313  typedef TfHashMap<TfToken, VtValue, TfToken::HashFunctor> _ValueCache;
314  typedef TfHashMap<SdfPath, _ValueCache, SdfPath::Hash> _ValueCacheMap;
315  _ValueCacheMap _valueCacheMap;
316  };
317  _Delegate _delegate;
318 
319  // Generated tasks.
320  SdfPath _simpleLightTaskId;
321  SdfPath _shadowTaskId;
322  SdfPathVector _renderTaskIds;
323  SdfPath _oitResolveTaskId;
324  SdfPath _selectionTaskId;
325  SdfPath _colorizeSelectionTaskId;
326  SdfPath _colorizeTaskId;
327  SdfPath _colorCorrectionTaskId;
328  SdfPath _pickTaskId;
329  SdfPath _pickFromRenderBufferTaskId;
330  SdfPath _aovColorResolveTaskId;
331  SdfPath _aovDepthResolveTaskId;
332  SdfPath _presentTaskId;
333 
334  // Generated camera (for the default/free cam)
335  SdfPath _freeCamId;
336  // Current active camera
337  SdfPath _activeCameraId;
338 
339  // Built-in lights
340  SdfPathVector _lightIds;
341  HdTextureResourceSharedPtr _defaultDomeLightTextureResource;
342 
343  // Generated renderbuffers
344  SdfPathVector _aovBufferIds;
345  TfTokenVector _aovOutputs;
346  TfToken _viewportAov;
347 };
348 
349 PXR_NAMESPACE_CLOSE_SCOPE
350 
351 #endif // HDX_TASK_CONTROLLER_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:119
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:438
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:48
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