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 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_SKYDOME_TASK_H
25 #define HDX_SKYDOME_TASK_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdx/api.h"
30 #include "pxr/imaging/hdx/task.h"
31 
32 #include "pxr/base/gf/matrix4f.h"
33 #include "pxr/base/gf/vec2f.h"
34 #include "pxr/usd/sdf/path.h"
36 
38 
40 
41 /// \class HdxSkydomeTask
42 ///
43 /// If we have a domelight present in the lighting context the SkydomeTask
44 /// will render the associated environment map as a Skydome. Otherwise, it
45 /// will simply clear the AOVs.
46 ///
47 /// Note that this task is intended to be the first "Render Task" in the
48 /// HdxTaskController so that the AOV's are properly cleared, however it
49 /// does not spawn a HdRenderPass.
50 ///
51 class HdxSkydomeTask : public HdxTask
52 {
53 public:
54  HDX_API
55  HdxSkydomeTask(HdSceneDelegate* delegate, SdfPath const& id);
56 
57  HDX_API
58  ~HdxSkydomeTask() override;
59 
60  /// Prepare the tasks resources
61  HDX_API
62  void Prepare(HdTaskContext* ctx,
63  HdRenderIndex* renderIndex) override;
64 
65  /// Execute render pass task
66  HDX_API
67  void Execute(HdTaskContext* ctx) override;
68 
69 protected:
70  /// Sync the render pass resources
71  HDX_API
72  void _Sync(HdSceneDelegate* delegate,
73  HdTaskContext* ctx,
74  HdDirtyBits* dirtyBits) override;
75 
76 private:
77  HdRenderIndex* _renderIndex;
78  HgiTextureHandle _skydomeTexture;
79  // Optional internal render setup task, for params unpacking.
80  // This is used for aov bindings, camera matrices and framing
81  HdxRenderSetupTaskSharedPtr _setupTask;
82 
83  HdxSkydomeTask() = delete;
84  HdxSkydomeTask(const HdxSkydomeTask &) = delete;
85  HdxSkydomeTask &operator =(const HdxSkydomeTask &) = delete;
86 
87  HdRenderPassStateSharedPtr _GetRenderPassState(HdTaskContext *ctx) const;
88  bool _GetSkydomeTexture(HdTaskContext* ctx);
89  void _SetFragmentShader();
90 
91  // Utility function to update the shader uniform parameters.
92  // Returns true if the values were updated. False if unchanged.
93  bool _UpdateParameterBuffer(
94  const GfMatrix4f& invProjMatrix,
95  const GfMatrix4f& viewToWorldMatrix,
96  const GfMatrix4f& lightTransform);
97 
98  // This struct must match ParameterBuffer in Skydome.glslfx.
99  // Be careful to remember the std430 rules.
100  struct _ParameterBuffer
101  {
102  GfMatrix4f invProjMatrix;
103  GfMatrix4f viewToWorldMatrix;
104  GfMatrix4f lightTransform;
105  };
106 
107  std::unique_ptr<class HdxFullscreenShader> _compositor;
108  _ParameterBuffer _parameterData;
109 };
110 
111 
113 
114 #endif
std::shared_ptr< class HdRenderPassState > HdRenderPassStateSharedPtr
Definition: engine.h:42
uint32_t HdDirtyBits
Definition: types.h:158
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:40
HDX_API ~HdxSkydomeTask() override
Definition: path.h:290
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:77
Definition: task.h:44
HDX_API void Execute(HdTaskContext *ctx) override
Execute render pass task.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1394
std::shared_ptr< class HdxRenderSetupTask > HdxRenderSetupTaskSharedPtr
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.