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;
31struct HdxSimpleLightTaskParams;
32
33using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
34using HdStSimpleLightingShaderSharedPtr =
35 std::shared_ptr<class HdStSimpleLightingShader>;
36using HdxShadowMatrixComputationSharedPtr =
37 std::shared_ptr<class HdxShadowMatrixComputation>;
38
39TF_DECLARE_REF_PTRS(GlfSimpleShadowArray);
40
41
42class HdxSimpleLightTask : public HdTask
43{
44public:
45 using TaskParams = HdxSimpleLightTaskParams;
46
47 HDX_API
48 HdxSimpleLightTask(HdSceneDelegate* delegate, SdfPath const& id);
49
50 HDX_API
51 ~HdxSimpleLightTask() override;
52
54 HDX_API
55 void Sync(HdSceneDelegate* delegate,
56 HdTaskContext* ctx,
57 HdDirtyBits* dirtyBits) override;
58
60 HDX_API
61 void Prepare(HdTaskContext* ctx,
62 HdRenderIndex* renderIndex) override;
63
65 HDX_API
66 void Execute(HdTaskContext* ctx) override;
67
68private:
69 std::vector<GfMatrix4d> _ComputeShadowMatrices(
70 const HdCamera * camera,
71 HdxShadowMatrixComputationSharedPtr const &computation) const;
72
73 SdfPath _cameraId;
74 std::map<TfToken, SdfPathVector> _lightIds;
75 SdfPathVector _lightIncludePaths;
76 SdfPathVector _lightExcludePaths;
77 size_t _numLightIds;
78 size_t _maxLights;
79 unsigned _sprimIndexVersion;
80 unsigned _settingsVersion;
81
82 // Should be weak ptrs
83 HdStSimpleLightingShaderSharedPtr _lightingShader;
84 bool _enableShadows;
85 GfVec4f _viewport;
86 CameraUtilFraming _framing;
87 std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
88
89 // XXX: compatibility hack for passing some unit tests until we have
90 // more formal material plumbing.
91 GlfSimpleMaterial _material;
92 GfVec4f _sceneAmbient;
93
94 // For now these are only valid for the lifetime of a single pass of
95 // the render graph. Maybe long-term these could be change-tracked.
96 GlfSimpleLightVector _glfSimpleLights;
97
98 HdBufferArrayRangeSharedPtr _lightingBar;
99 HdBufferArrayRangeSharedPtr _lightSourcesBar;
100 HdBufferArrayRangeSharedPtr _shadowsBar;
101 HdBufferArrayRangeSharedPtr _materialBar;
102
103 bool _rebuildLightingBufferSources;
104 bool _rebuildLightAndShadowBufferSources;
105 bool _rebuildMaterialBufferSources;
106
107 size_t _AppendLightsOfType(HdRenderIndex &renderIndex,
108 TfTokenVector const &lightTypes,
109 SdfPathVector const &lightIncludePaths,
110 SdfPathVector const &lightExcludePaths,
111 std::map<TfToken, SdfPathVector> *lights);
112
113 HdxSimpleLightTask() = delete;
114 HdxSimpleLightTask(const HdxSimpleLightTask &) = delete;
115 HdxSimpleLightTask &operator =(const HdxSimpleLightTask &) = delete;
116};
117
118struct HdxSimpleLightTaskParams
119{
120 HdxSimpleLightTaskParams()
121 : cameraPath()
122 , lightIncludePaths(1, SdfPath::AbsoluteRootPath())
123 , lightExcludePaths()
124 , enableShadows(false)
125 , viewport(0.0f)
126 , overrideWindowPolicy{false, CameraUtilFit}
127 , material()
128 , sceneAmbient(0)
129 {}
130
131 SdfPath cameraPath;
132 SdfPathVector lightIncludePaths;
133 SdfPathVector lightExcludePaths;
134 bool enableShadows;
135 GfVec4f viewport;
136 CameraUtilFraming framing;
137 std::pair<bool, CameraUtilConformWindowPolicy> overrideWindowPolicy;
138
139 // XXX: compatibility hack for passing some unit tests until we have
140 // more formal material plumbing.
141 GlfSimpleMaterial material;
142 GfVec4f sceneAmbient;
143};
144
145// VtValue requirements
146HDX_API
147std::ostream& operator<<(std::ostream& out, const HdxSimpleLightTaskParams& pv);
148HDX_API
149bool operator==(
150 const HdxSimpleLightTaskParams& lhs,
151 const HdxSimpleLightTaskParams& rhs);
152HDX_API
153bool operator!=(
154 const HdxSimpleLightTaskParams& lhs,
155 const HdxSimpleLightTaskParams& rhs);
156
157struct HdxShadowParams {
158 HdxShadowParams()
159 : shadowMatrix()
160 , bias(0.0)
161 , blur(0.0)
162 , resolution(0)
163 , enabled(false)
164 {}
165
166 HdxShadowMatrixComputationSharedPtr shadowMatrix;
167 double bias;
168 double blur;
169 int resolution;
170 bool enabled;
171};
172
173// VtValue requirements
174HDX_API
175std::ostream& operator<<(std::ostream& out, const HdxShadowParams& pv);
176HDX_API
177bool operator==(const HdxShadowParams& lhs, const HdxShadowParams& rhs);
178HDX_API
179bool operator!=(const HdxShadowParams& lhs, const HdxShadowParams& rhs);
180
181
182PXR_NAMESPACE_CLOSE_SCOPE
183
184#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:92
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:105
Adapter class providing data exchange with the client scene graph.
HdTask represents a unit of work to perform during a Hydra render.
Definition: task.h:44
virtual void Execute(HdTaskContext *ctx)=0
Execute Phase: Runs the task.
virtual void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex)=0
Prepare Phase: Resolve bindings and manage resources.
virtual void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits)=0
Sync Phase: Obtain task state from Scene delegate based on change processing.
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