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 // Returns the material's render pass tag.
84 inline const TfToken& GetMaterialTag() const;
85
89 HDST_API
90 void SetMaterialNetworkShader(
91 HdSt_MaterialNetworkShaderSharedPtr &shaderCode);
92
93private:
94 // Processes the texture descriptors from a material network to
95 // create textures using the Storm texture system.
96 //
97 // Adds buffer specs/sources necessary for textures, e.g., bindless
98 // handles or sampling transform for field textures.
99 void _ProcessTextureDescriptors(
100 HdSceneDelegate * sceneDelegate,
101 HdStResourceRegistrySharedPtr const& resourceRegistry,
102 std::weak_ptr<HdStShaderCode> const &shaderCode,
103 HdStMaterialNetwork::TextureDescriptorVector const &descs,
104 HdStShaderCode::NamedTextureHandleVector * texturesFromStorm,
105 HdBufferSpecVector * specs,
106 HdBufferSourceSharedPtrVector * sources);
107
108 bool
109 _GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
110
111 void _InitFallbackShader();
112
113 static HioGlslfx *_fallbackGlslfx;
114
115 HdSt_MaterialNetworkShaderSharedPtr _materialNetworkShader;
116 VolumeMaterialData _volumeMaterialData;
117
118 bool _isInitialized : 1;
119 bool _hasPtex : 1;
120 bool _hasLimitSurfaceEvaluation : 1;
121 bool _hasDisplacement : 1;
122
123 TfToken _materialTag;
124 size_t _textureHash;
125
126 HdStMaterialNetwork _networkProcessor;
127};
128
129inline bool HdStMaterial::HasPtex() const
130{
131 return _hasPtex;
132}
133
134inline bool HdStMaterial::HasLimitSurfaceEvaluation() const
135{
136 return _hasLimitSurfaceEvaluation;
137}
138
139inline bool HdStMaterial::HasDisplacement() const
140{
141 return _hasDisplacement;
142}
143
144inline const TfToken& HdStMaterial::GetMaterialTag() const
145{
146 return _materialTag;
147}
148
150HdStMaterial::GetVolumeMaterialData() const {
151 return _volumeMaterialData;
152}
153
154
155PXR_NAMESPACE_CLOSE_SCOPE
156
157#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:274
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:43
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