Loading...
Searching...
No Matches
material.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_HD_ST_MATERIAL_H
8#define PXR_IMAGING_HD_ST_MATERIAL_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdSt/api.h"
12#include "pxr/imaging/hdSt/materialNetwork.h"
13#include "pxr/imaging/hdSt/shaderCode.h"
14#include "pxr/imaging/hd/material.h"
15#include "pxr/imaging/hf/perfLog.h"
16
17#include <memory>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21using HdSt_MaterialNetworkShaderSharedPtr =
22 std::shared_ptr<class HdSt_MaterialNetworkShader>;
23
24class HioGlslfx;
25
26class HdStMaterial final: public HdMaterial
27{
28public:
29 HF_MALLOC_TAG_NEW("new HdStMaterial");
30
35 struct VolumeMaterialData final
36 {
38 std::string source;
39 HdSt_MaterialParamVector params;
40 };
41
42 HDST_API
43 HdStMaterial(SdfPath const& id);
44 HDST_API
45 ~HdStMaterial() override;
46
48 HDST_API
49 void Sync(HdSceneDelegate *sceneDelegate,
50 HdRenderParam *renderParam,
51 HdDirtyBits *dirtyBits) override;
52
53 HDST_API
54 void Finalize(HdRenderParam *renderParam) override;
55
59 HDST_API
60 HdDirtyBits GetInitialDirtyBitsMask() const override;
61
64 HDST_API
65 HdSt_MaterialNetworkShaderSharedPtr GetMaterialNetworkShader() const;
66
69 inline const VolumeMaterialData &GetVolumeMaterialData() const;
70
75 inline bool HasPtex() const;
76
78 inline bool HasLimitSurfaceEvaluation() const;
79
80 // Returns true if the material has a displacement terminal.
81 inline bool HasDisplacement() const;
82
83 inline bool IsUsingFallbackShader() const;
84
85 // Returns the material's render pass tag.
86 inline const TfToken& GetMaterialTag() const;
87
91 HDST_API
92 void SetMaterialNetworkShader(
93 HdSt_MaterialNetworkShaderSharedPtr &shaderCode);
94
95private:
96 // Processes the texture descriptors from a material network to
97 // create textures using the Storm texture system.
98 //
99 // Adds buffer specs/sources necessary for textures, e.g., bindless
100 // handles or sampling transform for field textures.
101 void _ProcessTextureDescriptors(
102 HdSceneDelegate * sceneDelegate,
103 HdStResourceRegistrySharedPtr const& resourceRegistry,
104 std::weak_ptr<HdStShaderCode> const &shaderCode,
105 HdStMaterialNetwork::TextureDescriptorVector const &descs,
106 HdStShaderCode::NamedTextureHandleVector * texturesFromStorm,
107 HdBufferSpecVector * specs,
108 HdBufferSourceSharedPtrVector * sources);
109
110 bool
111 _GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
112
113 void _InitFallbackShader();
114
115 static HioGlslfx *_fallbackGlslfx;
116
117 HdSt_MaterialNetworkShaderSharedPtr _materialNetworkShader;
118 VolumeMaterialData _volumeMaterialData;
119
120 bool _isInitialized : 1;
121 bool _hasPtex : 1;
122 bool _hasLimitSurfaceEvaluation : 1;
123 bool _hasDisplacement : 1;
124 bool _isUsingFallbackShader : 1;
125
126 TfToken _materialTag;
127 size_t _textureHash;
128
129 HdStMaterialNetwork _networkProcessor;
130};
131
132inline bool HdStMaterial::HasPtex() const
133{
134 return _hasPtex;
135}
136
137inline bool HdStMaterial::HasLimitSurfaceEvaluation() const
138{
139 return _hasLimitSurfaceEvaluation;
140}
141
142inline bool HdStMaterial::HasDisplacement() const
143{
144 return _hasDisplacement;
145}
146
147inline const TfToken& HdStMaterial::GetMaterialTag() const
148{
149 return _materialTag;
150}
151
152inline bool HdStMaterial::IsUsingFallbackShader() const
153{
154 return _isUsingFallbackShader;
155}
156
158HdStMaterial::GetVolumeMaterialData() const {
159 return _volumeMaterialData;
160}
161
162
163PXR_NAMESPACE_CLOSE_SCOPE
164
165#endif // PXR_IMAGING_HD_ST_MATERIAL_H
Hydra Schema for a material object.
Definition: material.h:23
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.
virtual HD_API void Finalize(HdRenderParam *renderParam)
Finalizes object resources.
virtual HdDirtyBits GetInitialDirtyBitsMask() const =0
Returns the minimal set of dirty bits to place in the change tracker for use in the first sync of thi...
virtual void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits)=0
Synchronizes state from the delegate to this object.
Helps HdStMaterial process a Hydra material network into shader source code and parameters values.
A class representing the config and shader source of a glslfx file.
Definition: glslfx.h:134
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:280
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
A map with string keys and VtValue values.
Definition: dictionary.h:52
For volumes, the corresponding draw items do not use the HdStShaderCode produced by HdStMaterial.
Definition: material.h:36
std::string source
glslfx source code for volume
Definition: material.h:38