HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
skydomeTask.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef HDX_SKYDOME_TASK_H
8 #define HDX_SKYDOME_TASK_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdx/api.h"
13 #include "pxr/imaging/hdx/task.h"
14 
15 #include "pxr/base/gf/matrix4f.h"
16 #include "pxr/base/gf/vec2f.h"
17 #include "pxr/usd/sdf/path.h"
19 
21 
23 
24 /// \class HdxSkydomeTask
25 ///
26 /// If we have a domelight present in the lighting context the SkydomeTask
27 /// will render the associated environment map as a Skydome. Otherwise, it
28 /// will simply clear the AOVs.
29 ///
30 /// Note that this task is intended to be the first "Render Task" in the
31 /// HdxTaskController so that the AOV's are properly cleared, however it
32 /// does not spawn a HdRenderPass.
33 ///
34 class HdxSkydomeTask : public HdxTask
35 {
36 public:
38 
39  HDX_API
40  HdxSkydomeTask(HdSceneDelegate* delegate, SdfPath const& id);
41 
42  HDX_API
43  ~HdxSkydomeTask() override;
44 
45  /// Prepare the tasks resources
46  HDX_API
47  void Prepare(HdTaskContext* ctx,
48  HdRenderIndex* renderIndex) override;
49 
50  /// Execute render pass task
51  HDX_API
52  void Execute(HdTaskContext* ctx) override;
53 
54 protected:
55  /// Sync the render pass resources
56  HDX_API
57  void _Sync(HdSceneDelegate* delegate,
58  HdTaskContext* ctx,
59  HdDirtyBits* dirtyBits) override;
60 
61 private:
62  HdRenderIndex* _renderIndex;
63  HgiTextureHandle _skydomeTexture;
64  HgiSamplerHandle _skydomeSampler;
65  // Optional internal render setup task, for params unpacking.
66  // This is used for aov bindings, camera matrices and framing
67  HdxRenderSetupTaskSharedPtr _setupTask;
68  unsigned int _settingsVersion;
69  bool _skydomeVisibility;
70 
71  HdxSkydomeTask() = delete;
72  HdxSkydomeTask(const HdxSkydomeTask &) = delete;
73  HdxSkydomeTask &operator =(const HdxSkydomeTask &) = delete;
74 
75  HdRenderPassStateSharedPtr _GetRenderPassState(HdTaskContext *ctx) const;
76  bool _GetSkydomeTexture(HdTaskContext* ctx);
77  void _SetFragmentShader();
78 
79  // Utility function to update the shader uniform parameters.
80  // Returns true if the values were updated. False if unchanged.
81  bool _UpdateParameterBuffer(
82  const GfMatrix4f& invProjMatrix,
83  const GfMatrix4f& viewToWorldMatrix,
84  const GfMatrix4f& lightTransform);
85 
86  // This struct must match ParameterBuffer in Skydome.glslfx.
87  // Be careful to remember the std430 rules.
88  struct _ParameterBuffer
89  {
90  GfMatrix4f invProjMatrix;
91  GfMatrix4f viewToWorldMatrix;
92  GfMatrix4f lightTransform;
93  };
94 
95  std::unique_ptr<class HdxFullscreenShader> _compositor;
96  _ParameterBuffer _parameterData;
97 };
98 
99 
101 
102 #endif
std::shared_ptr< class HdRenderPassState > HdRenderPassStateSharedPtr
Definition: engine.h:25
uint32_t HdDirtyBits
Definition: types.h:143
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
int HgiHandle< class HgiTexture > HgiTextureHandle
#define HDX_API
Definition: api.h:23
HDX_API ~HdxSkydomeTask() override
Definition: path.h:273
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:61
Definition: task.h:27
HDX_API void Execute(HdTaskContext *ctx) override
Execute render pass task.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
std::shared_ptr< class HdxRenderSetupTask > HdxRenderSetupTaskSharedPtr
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.