HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simpleLightTask.h
Go to the documentation of this file.
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"
30 
31 #include "pxr/imaging/hd/task.h"
32 
35 
37 
38 #include "pxr/base/gf/vec3f.h"
40 
41 #include <memory>
42 
44 
45 class HdRenderIndex;
46 class HdSceneDelegate;
47 class HdCamera;
48 
49 using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
51  std::shared_ptr<class HdStSimpleLightingShader>;
53  std::shared_ptr<class HdxShadowMatrixComputation>;
54 
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 
67  /// Sync the render pass resources
68  HDX_API
69  void Sync(HdSceneDelegate* delegate,
70  HdTaskContext* ctx,
71  HdDirtyBits* dirtyBits) override;
72 
73  /// Prepare the tasks resources
74  HDX_API
75  void Prepare(HdTaskContext* ctx,
76  HdRenderIndex* renderIndex) override;
77 
78  /// Execute render pass task
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  HdBufferArrayRangeSharedPtr _lightingBar;
110  HdBufferArrayRangeSharedPtr _lightSourcesBar;
111  HdBufferArrayRangeSharedPtr _shadowsBar;
112  HdBufferArrayRangeSharedPtr _materialBar;
113 
114  size_t _AppendLightsOfType(HdRenderIndex &renderIndex,
115  TfTokenVector const &lightTypes,
116  SdfPathVector const &lightIncludePaths,
117  SdfPathVector const &lightExcludePaths,
118  std::map<TfToken, SdfPathVector> *lights);
119 
120  HdxSimpleLightTask() = delete;
121  HdxSimpleLightTask(const HdxSimpleLightTask &) = delete;
122  HdxSimpleLightTask &operator =(const HdxSimpleLightTask &) = delete;
123 };
124 
127  : cameraPath()
128  , lightIncludePaths(1, SdfPath::AbsoluteRootPath())
130  , enableShadows(false)
131  , viewport(0.0f)
133  , material()
134  , sceneAmbient(0)
135  {}
136 
143  std::pair<bool, CameraUtilConformWindowPolicy> overrideWindowPolicy;
144 
145  // XXX: compatibility hack for passing some unit tests until we have
146  // more formal material plumbing.
149 };
150 
151 // VtValue requirements
152 HDX_API
153 std::ostream& operator<<(std::ostream& out, const HdxSimpleLightTaskParams& pv);
154 HDX_API
155 bool operator==(
156  const HdxSimpleLightTaskParams& lhs,
157  const HdxSimpleLightTaskParams& rhs);
158 HDX_API
159 bool operator!=(
160  const HdxSimpleLightTaskParams& lhs,
161  const HdxSimpleLightTaskParams& rhs);
162 
165  : shadowMatrix()
166  , bias(0.0)
167  , blur(0.0)
168  , resolution(0)
169  , enabled(false)
170  {}
171 
173  double bias;
174  double blur;
176  bool enabled;
177 };
178 
179 // VtValue requirements
180 HDX_API
181 std::ostream& operator<<(std::ostream& out, const HdxShadowParams& pv);
182 HDX_API
183 bool operator==(const HdxShadowParams& lhs, const HdxShadowParams& rhs);
184 HDX_API
185 bool operator!=(const HdxShadowParams& lhs, const HdxShadowParams& rhs);
186 
187 
189 
190 #endif //PXR_IMAGING_HDX_SIMPLE_LIGHT_TASK_H
TF_DECLARE_REF_PTRS(GlfSimpleShadowArray)
std::shared_ptr< class HdRenderPass > HdRenderPassSharedPtr
Definition: engine.h:41
uint32_t HdDirtyBits
Definition: types.h:158
HDX_API std::ostream & operator<<(std::ostream &out, const HdxSimpleLightTaskParams &pv)
std::shared_ptr< class HdxShadowMatrixComputation > HdxShadowMatrixComputationSharedPtr
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glcorearb.h:2539
#define HDX_API
Definition: api.h:40
HDX_API void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
GLfloat bias
Definition: glew.h:10316
std::pair< bool, CameraUtilConformWindowPolicy > overrideWindowPolicy
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:570
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
GlfSimpleMaterial material
Definition: task.h:54
Definition: path.h:290
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
HDX_API void Execute(HdTaskContext *ctx) override
Execute render pass task.
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:77
std::shared_ptr< class HdStSimpleLightingShader > HdStSimpleLightingShaderSharedPtr
Definition: vec4f.h:63
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1394
CameraUtilFraming framing
HDX_API ~HdxSimpleLightTask() override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
std::shared_ptr< HdBufferArrayRange > HdBufferArrayRangeSharedPtr
Definition: bufferArray.h:45
SdfPathVector lightExcludePaths
GLfloat f
Definition: glcorearb.h:1926
SdfPathVector lightIncludePaths
HdxShadowMatrixComputationSharedPtr shadowMatrix
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:556
std::vector< class GlfSimpleLight > GlfSimpleLightVector
Definition: simpleLight.h:231
Increase width or height.
Definition: conformWindow.h:50