Loading...
Searching...
No Matches
simpleLightingShader.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_HDST_SIMPLE_LIGHTING_SHADER_H
8#define PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdSt/api.h"
12#include "pxr/imaging/hdSt/binding.h"
13#include "pxr/imaging/hdSt/lightingShader.h"
14
15#include "pxr/imaging/hd/version.h"
16
18
19#include <memory>
20#include <string>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24class HdRenderIndex;
25class HdRenderParam;
26class HdSceneDelegate;
27class HdStRenderBuffer;
29using HdStSimpleLightingShaderSharedPtr =
30 std::shared_ptr<class HdStSimpleLightingShader>;
31using HdRenderPassAovBindingVector = std::vector<HdRenderPassAovBinding>;
32
38{
39public:
40 HDST_API
41 HdStSimpleLightingShader(const Hgi* hgi);
42 HDST_API
44
46 HDST_API
47 ID ComputeHash() const override;
48 HDST_API
49 std::string GetSource(TfToken const &shaderStageKey) const override;
50 HDST_API
51 void BindResources(int program,
52 HdSt_ResourceBinder const &binder) override;
53 HDST_API
54 void UnbindResources(int program,
55 HdSt_ResourceBinder const &binder) override;
56
58 HDST_API
60
62 HDST_API
63 void RemoveBufferBinding(TfToken const &name);
64
66 HDST_API
68
69 HDST_API
70 void AddBindings(HdStBindingRequestVector *customBindings) override;
71
74 HDST_API
75 void AddResourcesFromTextures(ResourceContext &ctx) const override;
76
78 HDST_API
79 HdSt_MaterialParamVector const& GetParams() const override;
80
82 HDST_API
84 GfMatrix4d const &worldToViewMatrix,
85 GfMatrix4d const &projectionMatrix) override;
86
87 GlfSimpleLightingContextRefPtr GetLightingContext() const {
88 return _lightingContext;
89 };
90
96 HDST_API
98 HdRenderIndex const &renderIndex,
99 const SdfPath& graphPath);
100
103 const HdStTextureHandleSharedPtr &
105 return _domeLightEnvironmentTextureHandle;
106 }
107
110 HDST_API
111 NamedTextureHandleVector const &GetNamedTextureHandles() const override;
112
115 HDST_API
116 const HdStTextureHandleSharedPtr &GetTextureHandle(
117 const TfToken &name) const;
118
121 HDST_API
122 const HdStTextureHandleSharedPtr &
124
125 HdRenderPassAovBindingVector const& GetShadowAovBindings() {
126 return _shadowAovBindings;
127 }
128
129 HDST_API
130 void SetDomeLightCubemapTargetMemory(unsigned int targetMemoryMB);
131
132 HDST_API
133 void SetMaxLights(uint32_t maxLights);
134
135 // Limit set based to half the max samplers allowed by selected Hgi backend.
136 HDST_API
137 uint32_t GetMaxShadows() const {
138 return _maxShadows;
139 }
140
141private:
142 void _AllocateShadowTextures(
143 HdStResourceRegistry* const resourceRegistry,
144 const SdfPath& graphPath);
145 void _CleanupAovBindings();
146
147 GlfSimpleLightingContextRefPtr _lightingContext;
148 std::unique_ptr<class HioGlslfx> _glslfx;
149
150 // Lexicographic ordering for stable output between runs.
151 std::map<TfToken, HdStBindingRequest> _customBuffers;
152
153 // The environment map used as source for the dome light textures.
154 //
155 // Handle is allocated in AllocateTextureHandles. Actual loading
156 // happens during commit.
157 HdStTextureHandleSharedPtr _domeLightEnvironmentTextureHandle;
158
159 // Other dome light textures.
160 NamedTextureHandleVector _namedTextureHandles;
161
162 NamedTextureHandleVector _domeLightTextureHandles;
163
164 // Maximum target memory of computed dome light cubemap texture (in MB)
165 unsigned int _domeLightCubemapTargetMemoryMB;
166
167 NamedTextureHandle _shadowTextureHandle;
168
169 HdSt_MaterialParamVector _lightTextureParams;
170
171 HdRenderParam *_renderParam;
172
173 HdRenderPassAovBindingVector _shadowAovBindings;
174
175 std::vector<HdStPooledRenderBufferUniquePtr> _shadowBuffers;
176
177 HdStPooledRenderBufferUniquePtr _shadowBufferFallback;
178
179 uint32_t _maxLights;
180 uint32_t _maxShadows;
181};
182
183
184PXR_NAMESPACE_CLOSE_SCOPE
185
186#endif // PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
Stores a 4x4 matrix of double elements.
Definition matrix4d.h:71
The render index is part of the Hydra 1.0 API and is only used for emulation purposes so that HdScene...
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Adapter class providing data exchange with the client scene graph.
BindingRequest allows externally allocated buffers to be bound at render time.
Definition binding.h:111
A lighting shader base class.
A central registry of all GPU resources.
The context available in implementations of AddResourcesFromTextures.
Definition shaderCode.h:185
A shader that supports simple lighting functionality.
HDST_API void RemoveBufferBinding(TfToken const &name)
Remove name from custom binding.
HDST_API const HdStTextureHandleSharedPtr & GetTextureHandle(const TfToken &name) const
Get one of the textures that need to be computed from the dome light environment map.
HDST_API void AddBufferBinding(HdStBindingRequest const &req)
Add a custom binding request for use when this shader executes.
HDST_API void AddBindings(HdStBindingRequestVector *customBindings) override
Add custom bindings (used by codegen)
HDST_API void ClearBufferBindings()
Clear all custom bindings associated with this shader.
HDST_API void AllocateTextureHandles(HdRenderIndex const &renderIndex, const SdfPath &graphPath)
Allocates texture handles (texture loading happens later during commit) needed for lights.
const HdStTextureHandleSharedPtr & GetDomeLightEnvironmentTextureHandle() const
The dome light environment map used as source for the other dome light textures.
HDST_API const HdStTextureHandleSharedPtr & GetDomeLightEnvironmentCubemapTextureHandle() const
The dome light environment cubemap texture generated from the latlong dome light texture.
HDST_API std::string GetSource(TfToken const &shaderStageKey) const override
Returns the shader source provided by this shader for shaderStageKey.
HDST_API ID ComputeHash() const override
HdShader overrides.
HDST_API void AddResourcesFromTextures(ResourceContext &ctx) const override
Adds computations to create the dome light textures that are pre-calculated from the environment map ...
HDST_API void UnbindResources(int program, HdSt_ResourceBinder const &binder) override
Unbinds shader-specific resources.
HDST_API void BindResources(int program, HdSt_ResourceBinder const &binder) override
Binds shader-specific resources to program XXX: this interface is meant to be used for bridging the G...
HDST_API NamedTextureHandleVector const & GetNamedTextureHandles() const override
The textures computed from the dome light environment map that the shader needs to bind for the dome ...
HDST_API void SetCamera(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix) override
HdStLightingShader overrides.
HDST_API HdSt_MaterialParamVector const & GetParams() const override
HdStShaderCode overrides.
Hydra Graphics Interface.
Definition hgi.h:95
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:81
A renderpass AOV represents a binding of some output of the rendering process to an output buffer.
Definition aov.h:100