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