skydomeTask.h
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"
29 #include "pxr/imaging/hdx/renderSetupTask.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"
35 #include "pxr/imaging/hgi/graphicsCmds.h"
36 
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
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 
61  HDX_API
62  void Prepare(HdTaskContext* ctx,
63  HdRenderIndex* renderIndex) override;
64 
66  HDX_API
67  void Execute(HdTaskContext* ctx) override;
68 
69 protected:
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  unsigned int _settingsVersion;
83  bool _skydomeVisibility;
84 
85  HdxSkydomeTask() = delete;
86  HdxSkydomeTask(const HdxSkydomeTask &) = delete;
87  HdxSkydomeTask &operator =(const HdxSkydomeTask &) = delete;
88 
89  HdRenderPassStateSharedPtr _GetRenderPassState(HdTaskContext *ctx) const;
90  bool _GetSkydomeTexture(HdTaskContext* ctx);
91  void _SetFragmentShader();
92 
93  // Utility function to update the shader uniform parameters.
94  // Returns true if the values were updated. False if unchanged.
95  bool _UpdateParameterBuffer(
96  const GfMatrix4f& invProjMatrix,
97  const GfMatrix4f& viewToWorldMatrix,
98  const GfMatrix4f& lightTransform);
99 
100  // This struct must match ParameterBuffer in Skydome.glslfx.
101  // Be careful to remember the std430 rules.
102  struct _ParameterBuffer
103  {
104  GfMatrix4f invProjMatrix;
105  GfMatrix4f viewToWorldMatrix;
106  GfMatrix4f lightTransform;
107  };
108 
109  std::unique_ptr<class HdxFullscreenShader> _compositor;
110  _ParameterBuffer _parameterData;
111 };
112 
113 
114 PXR_NAMESPACE_CLOSE_SCOPE
115 
116 #endif
Stores a 4x4 matrix of float elements.
Definition: matrix4f.h:87
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:120
HDX_API void Execute(HdTaskContext *ctx) override
Execute render pass task.
Adapter class providing data exchange with the client scene graph.
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Base class for (some) tasks in Hdx that provides common progressive rendering and Hgi functionality.
Definition: task.h:44
If we have a domelight present in the lighting context the SkydomeTask will render the associated env...
Definition: skydomeTask.h:51
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.