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
19
20#include <memory>
21#include <string>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25class HdRenderIndex;
26class HdRenderParam;
27class HdSceneDelegate;
28class HdStRenderBuffer;
30using HdStSimpleLightingShaderSharedPtr =
31 std::shared_ptr<class HdStSimpleLightingShader>;
32using HdRenderPassAovBindingVector = std::vector<HdRenderPassAovBinding>;
33
34TF_DECLARE_REF_PTRS(GlfBindingMap);
35
41{
42public:
43 HDST_API
45 HDST_API
47
49 HDST_API
50 ID ComputeHash() const override;
51 HDST_API
52 std::string GetSource(TfToken const &shaderStageKey) const override;
53 HDST_API
54 void BindResources(int program,
55 HdSt_ResourceBinder const &binder) override;
56 HDST_API
57 void UnbindResources(int program,
58 HdSt_ResourceBinder const &binder) override;
59
61 HDST_API
63
65 HDST_API
66 void RemoveBufferBinding(TfToken const &name);
67
69 HDST_API
71
72 HDST_API
73 void AddBindings(HdStBindingRequestVector *customBindings) override;
74
77 HDST_API
78 void AddResourcesFromTextures(ResourceContext &ctx) const override;
79
81 HDST_API
82 HdSt_MaterialParamVector const& GetParams() const override;
83
85 HDST_API
87 GfMatrix4d const &worldToViewMatrix,
88 GfMatrix4d const &projectionMatrix) override;
89
90 GlfSimpleLightingContextRefPtr GetLightingContext() const {
91 return _lightingContext;
92 };
93
99 HDST_API
100 void AllocateTextureHandles(HdRenderIndex const &renderIndex);
101
104 const HdStTextureHandleSharedPtr &
106 return _domeLightEnvironmentTextureHandle;
107 }
108
111 HDST_API
112 NamedTextureHandleVector const &GetNamedTextureHandles() const override;
113
116 HDST_API
117 const HdStTextureHandleSharedPtr &GetTextureHandle(
118 const TfToken &name) const;
119
120 HdRenderPassAovBindingVector const& GetShadowAovBindings() {
121 return _shadowAovBindings;
122 }
123
124private:
125 SdfPath _GetAovPath(TfToken const &aov, size_t shadowIndex) const;
126 void _ResizeOrCreateBufferForAov(size_t shadowIndex) const;
127 void _CleanupAovBindings();
128
129 GlfSimpleLightingContextRefPtr _lightingContext;
130 bool _useLighting;
131 std::unique_ptr<class HioGlslfx> _glslfx;
132
133 // Lexicographic ordering for stable output between runs.
134 std::map<TfToken, HdStBindingRequest> _customBuffers;
135
136 // The environment map used as source for the dome light textures.
137 //
138 // Handle is allocated in AllocateTextureHandles. Actual loading
139 // happens during commit.
140 HdStTextureHandleSharedPtr _domeLightEnvironmentTextureHandle;
141
142 // Other dome light textures.
143 NamedTextureHandleVector _namedTextureHandles;
144
145 NamedTextureHandleVector _domeLightTextureHandles;
146 NamedTextureHandleVector _shadowTextureHandles;
147
148 HdSt_MaterialParamVector _lightTextureParams;
149
150 HdRenderParam *_renderParam;
151
152 HdRenderPassAovBindingVector _shadowAovBindings;
153 std::vector<std::unique_ptr<HdStRenderBuffer>> _shadowAovBuffers;
154};
155
156
157PXR_NAMESPACE_CLOSE_SCOPE
158
159#endif // PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:104
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:109
A lighting shader base class.
The context available in implementations of AddResourcesFromTextures.
Definition: shaderCode.h:184
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)
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 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.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Standard pointer typedefs.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
A renderpass AOV represents a binding of some output of the rendering process to an output buffer.
Definition: aov.h:100