All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simpleLightTask.h
1 //
2 // Copyright 2016 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_SIMPLE_LIGHT_TASK_H
25 #define PXR_IMAGING_HDX_SIMPLE_LIGHT_TASK_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdx/api.h"
29 #include "pxr/imaging/hdx/version.h"
30 
31 #include "pxr/imaging/hd/task.h"
32 
35 
36 #include "pxr/imaging/cameraUtil/framing.h"
37 
38 #include "pxr/base/gf/vec3f.h"
40 
41 #include <memory>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
45 class HdRenderIndex;
46 class HdSceneDelegate;
47 class HdCamera;
48 
49 using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
50 using HdStSimpleLightingShaderSharedPtr =
51  std::shared_ptr<class HdStSimpleLightingShader>;
52 using HdxShadowMatrixComputationSharedPtr =
53  std::shared_ptr<class HdxShadowMatrixComputation>;
54 
55 TF_DECLARE_REF_PTRS(GlfSimpleShadowArray);
56 
57 
58 class HdxSimpleLightTask : public HdTask
59 {
60 public:
61  HDX_API
62  HdxSimpleLightTask(HdSceneDelegate* delegate, SdfPath const& id);
63 
64  HDX_API
65  ~HdxSimpleLightTask() override;
66 
68  HDX_API
69  void Sync(HdSceneDelegate* delegate,
70  HdTaskContext* ctx,
71  HdDirtyBits* dirtyBits) override;
72 
74  HDX_API
75  void Prepare(HdTaskContext* ctx,
76  HdRenderIndex* renderIndex) override;
77 
79  HDX_API
80  void Execute(HdTaskContext* ctx) override;
81 
82 private:
83  std::vector<GfMatrix4d> _ComputeShadowMatrices(
84  const HdCamera * camera,
85  HdxShadowMatrixComputationSharedPtr const &computation) const;
86 
87  SdfPath _cameraId;
88  std::map<TfToken, SdfPathVector> _lightIds;
89  SdfPathVector _lightIncludePaths;
90  SdfPathVector _lightExcludePaths;
91  size_t _numLights;
92 
93  // Should be weak ptrs
94  HdStSimpleLightingShaderSharedPtr _lightingShader;
95  bool _enableShadows;
96  GfVec4f _viewport;
97  CameraUtilFraming _framing;
98  std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
99 
100  // XXX: compatibility hack for passing some unit tests until we have
101  // more formal material plumbing.
102  GlfSimpleMaterial _material;
103  GfVec4f _sceneAmbient;
104 
105  // For now these are only valid for the lifetime of a single pass of
106  // the render graph. Maybe long-term these could be change-tracked.
107  GlfSimpleLightVector _glfSimpleLights;
108 
109  size_t _AppendLightsOfType(HdRenderIndex &renderIndex,
110  std::vector<TfToken> const &lightTypes,
111  SdfPathVector const &lightIncludePaths,
112  SdfPathVector const &lightExcludePaths,
113  std::map<TfToken, SdfPathVector> *lights);
114 
115  HdxSimpleLightTask() = delete;
116  HdxSimpleLightTask(const HdxSimpleLightTask &) = delete;
117  HdxSimpleLightTask &operator =(const HdxSimpleLightTask &) = delete;
118 };
119 
120 struct HdxSimpleLightTaskParams {
121  HdxSimpleLightTaskParams()
122  : cameraPath()
123  , lightIncludePaths(1, SdfPath::AbsoluteRootPath())
124  , lightExcludePaths()
125  , enableShadows(false)
126  , viewport(0.0f)
127  , overrideWindowPolicy{false, CameraUtilFit}
128  , material()
129  , sceneAmbient(0)
130  {}
131 
132  SdfPath cameraPath;
133  SdfPathVector lightIncludePaths;
134  SdfPathVector lightExcludePaths;
135  bool enableShadows;
136  GfVec4f viewport;
137  CameraUtilFraming framing;
138  std::pair<bool, CameraUtilConformWindowPolicy> overrideWindowPolicy;
139 
140  // XXX: compatibility hack for passing some unit tests until we have
141  // more formal material plumbing.
142  GlfSimpleMaterial material;
143  GfVec4f sceneAmbient;
144 };
145 
146 // VtValue requirements
147 HDX_API
148 std::ostream& operator<<(std::ostream& out, const HdxSimpleLightTaskParams& pv);
149 HDX_API
150 bool operator==(
151  const HdxSimpleLightTaskParams& lhs,
152  const HdxSimpleLightTaskParams& rhs);
153 HDX_API
154 bool operator!=(
155  const HdxSimpleLightTaskParams& lhs,
156  const HdxSimpleLightTaskParams& rhs);
157 
158 struct HdxShadowParams {
159  HdxShadowParams()
160  : shadowMatrix()
161  , bias(0.0)
162  , blur(0.0)
163  , resolution(0)
164  , enabled(false)
165  {}
166 
167  HdxShadowMatrixComputationSharedPtr shadowMatrix;
168  double bias;
169  double blur;
170  int resolution;
171  bool enabled;
172 };
173 
174 // VtValue requirements
175 HDX_API
176 std::ostream& operator<<(std::ostream& out, const HdxShadowParams& pv);
177 HDX_API
178 bool operator==(const HdxShadowParams& lhs, const HdxShadowParams& rhs);
179 HDX_API
180 bool operator!=(const HdxShadowParams& lhs, const HdxShadowParams& rhs);
181 
182 
183 PXR_NAMESPACE_CLOSE_SCOPE
184 
185 #endif //PXR_IMAGING_HDX_SIMPLE_LIGHT_TASK_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:116
Standard pointer typedefs.
Hydra schema for a camera that pulls the params (see above) during Sync.
Definition: camera.h:85
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
Framing information.
Definition: framing.h:79