HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_MaterialTypes.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GR_MaterialTypes.h (GR Library, C++)
7  *
8  * COMMENTS:
9  */
10 #ifndef GR_MaterialTypes_h
11 #define GR_MaterialTypes_h
12 
13 #include "GR_API.h"
14 #include "GR_Material.h"
15 
16 #ifdef USE_VULKAN
17 #include <RV/RV_ShaderProgram.h>
18 #include <RV/RV_TypePtrs.h>
19 #endif
20 
21 #include <RE/RE_Material.h>
22 #include <SYS/SYS_Align.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_StringMap.h>
25 #include <UT/UT_Matrix4.h>
26 #include <UT/UT_UniquePtr.h>
27 #include <UT/UT_VectorTypes.h>
28 #include <UT/UT_Vector2.h>
29 #include <UT/UT_Vector3.h>
30 
31 class RV_ShaderProgram;
33 class RV_ShaderBlock;
34 class RV_TextureParms;
35 class RV_VKImage;
36 class GT_DataArray;
37 
38 #define PARMKEY(NAME) static exint NAME();
39 
40 #define MATPARM(TYPE, NAME) \
41  TYPE get##NAME() const { return mySimpleBlock.NAME; } \
42  void set##NAME(const TYPE &v) \
43  { if(mySimpleBlock.NAME != v) { mySimpleBlock.NAME=v; myBlockDirtyFlag=true; } } \
44  PARMKEY(NAME)
45 
46 #ifdef USE_VULKAN
47 #define TEXMAP_PARM(NAME, MAP) \
48  UT_StringHolder get##NAME() const { return my##NAME; } \
49  void set##NAME(const UT_StringHolder &v) \
50  { if(my##NAME != v) { my##NAME=v; my##MAP.reset(); myTexDirtyFlag=true; } } \
51  void set##NAME##Fallback(const UT_Vector4F &f) \
52  { if(my##NAME##Fallback!=f) { my##NAME##Fallback=f; myTexDirtyFlag=true; }} \
53  PARMKEY(NAME); \
54  UT_StringHolder my##NAME; \
55  UT_Vector4F my##NAME##Fallback; \
56  RV_TextureRef my##MAP
57 
58 #else
59 #define TEXMAP_PARM(NAME, MAP) \
60  UT_StringHolder get##NAME() const { return my##NAME; } \
61  void set##NAME(const UT_StringHolder &v) \
62  { if(my##NAME != v) { my##NAME=v; myTexDirtyFlag=true; } } \
63  void set##NAME##Fallback(const UT_Vector4F &f) \
64  { if(my##NAME##Fallback!=f) { my##NAME##Fallback=f; myTexDirtyFlag=true; }} \
65  PARMKEY(NAME); \
66  UT_Vector4F my##NAME##Fallback; \
67  UT_StringHolder my##NAME
68 #endif
69 
70 
71 ///
73 {
74 public:
75  // setPARM() / getPARM()
76  MATPARM(UT_Vector3F, Diff);
77  MATPARM(UT_Vector3F, Spec);
78  MATPARM(UT_Vector3F, Emit);
79  MATPARM(UT_Vector3F, MetalColor);
80  MATPARM(UT_Vector3F, SheenColor);
81  MATPARM(fpreal32, DiffRough);
82  MATPARM(fpreal32, SpecRough);
83  MATPARM(fpreal32, SpecTint);
85  MATPARM(fpreal32, IOR);
87  MATPARM(fpreal32, AlphaPara);
88  MATPARM(fpreal32, AlphaCutoff);
90  MATPARM(fpreal32, CoatIntensity);
91  MATPARM(fpreal32, CoatRough);
92  MATPARM(fpreal32, SheenIntensity);
93  MATPARM(fpreal32, SheenRough);
94  MATPARM(int32, SpecModel);
95  MATPARM(int32, CoatSpecModel);
96  MATPARM(int32, UseGeoColor);
97  MATPARM(int32, UsePackedColor);
98  MATPARM(int32, HasTextures);
99 
100  void update(const GR_MaterialParms &options) override;
103  bool &created) override;
104  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
105 
107  { myVertexOverrides = ovr; }
109  { return myVertexOverrides; }
110 
111 protected:
113  MaterialType type = SIMPLE_SURFACE);
115 
116  friend class GR_Material;
117 
118 private:
119  struct SimpleMaterialBlock
120  {
121  // Not using explicit padding (SYS_ALIGN16) on the Vector3 fields
122  // because then sizeof(SimpleMaterialBlock) would report a size that
123  // includes the "padding required to place such an object in an array",
124  // which disagrees with the size determined by SPIR-V reflection.
125  // https://en.cppreference.com/w/cpp/language/sizeof
126  UT_Vector3F Diff = { 1.0, 1.0, 1.0 };
127  fpreal32 Padding0;
128  UT_Vector3F Spec = { 1.0, 1.0, 1.0 };
129  fpreal32 Padding1;
130  UT_Vector3F Emit = { 0.0, 0.0, 0.0 };
131  fpreal32 Padding2;
132  UT_Vector3F MetalColor = { 1.0, 1.0, 1.0 };
133  fpreal32 Padding3;
134  UT_Vector3F SheenColor = { 1.0, 1.0, 1.0 };
135 
136  fpreal32 DiffRough = 0.5;
137  fpreal32 SpecRough = 0.3;
138  fpreal32 SpecTint = 1.0;
139  fpreal32 Metal = 0.0;
140  fpreal32 IOR = 1.33;
141  fpreal32 Alpha = 1.0;
142  fpreal32 AlphaPara = 1.0;
143  fpreal32 AlphaCutoff = 0.0;
144  int32 AlphaMode = ALPHA_BLEND;
145  fpreal32 CoatIntensity = 0.0;
146  fpreal32 CoatRough = 0.1;
147  fpreal32 SheenIntensity = 0.0;
148  fpreal32 SheenRough = 0.1;
149  int32 SpecModel = 2;
150  int32 CoatSpecModel = 2;
151  int32 UseGeoColor = 1;
152  int32 UsePackedColor = 1;
153  int32 HasTextures = 0;
154  } mySimpleBlock;
155 #ifdef USE_VULKAN
156  UT_UniquePtr<RV_ShaderBlock> mySimpleMatBlock;
157 #endif
158  UT_StringMap<UT_StringHolder> myVertexOverrides;
159 };
160 
161 
162 /// More of a builtin material for the MatCap display mode
164 {
165 public:
166  TEXMAP_PARM(DiffuseMap, DiffuseID);
167  TEXMAP_PARM(EmissionMap, EmissionID);
168  MATPARM(fpreal32, Intensity);
169 
170  void setUDIM(const UT_Vector4i &udim)
171  { mySimpleBlock.udim_area = udim; myBlockDirtyFlag = true; }
172 
173  void update(const GR_MaterialParms &options) override;
176  bool &created) override;
177  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
178 
179  void dirtyTextures() override { myTexDirtyFlag = true; }
180 
181 protected:
183  MaterialType type = MATCAP_SURFACE);
185 
186  friend class GR_Material;
187 
188  struct
189  {
191  fpreal32 Intensity = 1.0;
192  } mySimpleBlock;
193 
194  bool myTexDirtyFlag = true;
195 #ifdef USE_VULKAN
196  UT_UniquePtr<RV_ShaderBlock> myMatCapBlock;
197 #endif
198 };
199 
200 #undef MATPARM
201 
202 // Film Material ------------------------------------------------------------
203 
204 #define TEX_PARM(TYPE, NAME) \
205  TYPE get##NAME() const { return myTextureBlock.NAME; } \
206  void set##NAME(const TYPE &v) \
207  { if(myTextureBlock.NAME != v) \
208  { myTextureBlock.NAME=v; myTexBlockDirtyFlag=true; } \
209  } \
210  PARMKEY(NAME)
211 
213 {
214 public:
215  ~GR_FilmMaterial() override;
216 
217  TEXMAP_PARM(DiffuseMap, DiffuseID);
218  TEXMAP_PARM(OpacityMap, OpacityID);
219  TEXMAP_PARM(SpecularMap, SpecularID);
220  TEXMAP_PARM(EmissionMap, EmissionID);
221  TEXMAP_PARM(NormalMap, NormalID);
222  TEXMAP_PARM(RoughMap, RoughID);
223  TEXMAP_PARM(OcclusionMap, OcclusionID);
224  TEXMAP_PARM(MetallicMap, MetallicID);
225  TEXMAP_PARM(CoatIntMap, CoatIntID);
226  TEXMAP_PARM(CoatRoughMap, CoatRoughID);
227  TEXMAP_PARM(ReflectIntMap, ReflectIntID);
228  TEXMAP_PARM(DisplaceMap, DisplaceID);
229 
230  TEX_PARM(UT_Matrix4F, DiffuseUV);
231  TEX_PARM(UT_Matrix4F, SpecularUV);
232  TEX_PARM(UT_Matrix4F, OpacityUV);
233  TEX_PARM(UT_Matrix4F, EmissionUV);
234  TEX_PARM(UT_Matrix4F, NormalUV);
235  TEX_PARM(UT_Matrix4F, RoughUV);
236  TEX_PARM(UT_Matrix4F, OcclusionUV);
237  TEX_PARM(UT_Matrix4F, MetallicUV);
238  TEX_PARM(UT_Matrix4F, CoatIntUV);
239  TEX_PARM(UT_Matrix4F, CoatRoughUV);
240  TEX_PARM(UT_Matrix4F, ReflectIntUV);
241  TEX_PARM(UT_Matrix4F, DisplaceUV);
242 
243  TEX_PARM(int32, HasDiffuse);
244  TEX_PARM(int32, HasSpecular);
245  TEX_PARM(int32, HasOpacity);
246  TEX_PARM(int32, HasEmission);
247  TEX_PARM(int32, HasNormal);
248  TEX_PARM(int32, HasRough);
249  TEX_PARM(int32, HasOcclusion);
250  TEX_PARM(int32, HasMetallic);
251  TEX_PARM(int32, HasCoatInt);
252  TEX_PARM(int32, HasCoatRough);
253  TEX_PARM(int32, HasReflectInt);
254  TEX_PARM(int32, HasDisplace);
255 
256  TEX_PARM(int32, HasDiffuseUV);
257  TEX_PARM(int32, HasSpecularUV);
258  TEX_PARM(int32, HasOpacityUV);
259  TEX_PARM(int32, HasEmissionUV);
260  TEX_PARM(int32, HasNormalUV);
261  TEX_PARM(int32, HasRoughUV);
262  TEX_PARM(int32, HasOcclusionUV);
263  TEX_PARM(int32, HasMetallicUV);
264  TEX_PARM(int32, HasCoatIntUV);
265  TEX_PARM(int32, HasCoatRoughUV);
266  TEX_PARM(int32, HasReflectIntUV);
267  TEX_PARM(int32, HasDisplaceUV);
268 
269  // Components
270  TEX_PARM(UT_Vector4F, RoughComp);
271  TEX_PARM(UT_Vector4F, OcclusionComp);
272  TEX_PARM(UT_Vector4F, MetallicComp);
273  TEX_PARM(UT_Vector4F, CoatIntComp);
274  TEX_PARM(UT_Vector4F, CoatRoughComp);
275  TEX_PARM(UT_Vector4F, OpacityComp);
276  TEX_PARM(UT_Vector4F, ReflectIntComp);
277 
278  // UDIM
279  TEX_PARM(UT_Vector4i, DiffuseUDIMArea);
280  TEX_PARM(UT_Vector4i, SpecularUDIMArea);
281  TEX_PARM(UT_Vector4i, OpacityUDIMArea);
282  TEX_PARM(UT_Vector4i, EmissionUDIMArea);
283  TEX_PARM(UT_Vector4i, NormalUDIMArea);
284  TEX_PARM(UT_Vector4i, RoughUDIMArea);
285  TEX_PARM(UT_Vector4i, OcclusionUDIMArea);
286  TEX_PARM(UT_Vector4i, MetallicUDIMArea);
287  TEX_PARM(UT_Vector4i, CoatIntUDIMArea);
288  TEX_PARM(UT_Vector4i, CoatRoughUDIMArea);
289  TEX_PARM(UT_Vector4i, ReflectIntUDIMArea);
290  TEX_PARM(UT_Vector4i, DisplaceUDIMArea);
291 
292  // Specific texture parms
293  // NORMAL
294  TEX_PARM(int32, NormalMapType);
295  TEX_PARM(UT_Vector2F, NormalMapScaleShift);
296  TEX_PARM(UT_Vector2F, NormalMapScale);
297  TEX_PARM(UT_Vector2F, NormalMapFlip);
298 
299  // DISPLACEMENT
300  TEX_PARM(int32, DisplaceSpace);
301  TEX_PARM(fpreal32, DisplaceScale);
302  TEX_PARM(fpreal32, DisplaceOffset);
303  TEX_PARM(fpreal32, DisplaceQuality);
304  TEX_PARM(int32, DisplaceYUp);
305 
306  TEX_PARM(int32, InvertOpacity );
307  TEX_PARM(int32, InvertRough );
308  TEX_PARM(int32, ReflectAsIOR);
309 
310  // Texture and UV wrapping
311  void setUVSet(const UT_StringRef &set) { myUVSet = set; }
312  const UT_StringHolder &getUVSet() const { return myUVSet; }
313 
314 #ifdef USE_VULKAN
315  void setTextureWrapU(RV_TextureWrap u) { myUWrap = u; }
316  RV_TextureWrap getTextureWrapU() const { return myUWrap; }
317 
318  void setTextureWrapV(RV_TextureWrap v) { myVWrap = v; }
319  RV_TextureWrap getTextureWrapV() const { return myVWrap; }
320 #endif
321 
322  // Update functions
323  void update(const GR_MaterialParms &options) override;
326  bool &created) override;
327  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
328 
329  void dirtyTextures() override { myTexDirtyFlag = true; dirty(true); }
330 
331  bool bindForCompute(RV_Render *r,
333  const GR_DisplayOption &opts) override;
334 
335 protected:
338 
339  friend class GR_Material;
340 private:
341  class TexturedBlock
342  {
343  public:
344  UT_Matrix4F DiffuseUV;
345  UT_Matrix4F SpecularUV;
346  UT_Matrix4F OpacityUV;
347  UT_Matrix4F EmissionUV;
348  UT_Matrix4F NormalUV;
349  UT_Matrix4F RoughUV;
350  UT_Matrix4F DisplaceUV;
351  UT_Matrix4F OcclusionUV;
352  UT_Matrix4F MetallicUV;
353  UT_Matrix4F CoatIntUV;
354  UT_Matrix4F CoatRoughUV;
355  UT_Matrix4F ReflectIntUV;
356 
357  UT_Vector4F RoughComp = {1.,0.,0.,0.};
358  UT_Vector4F OcclusionComp = {1.,0.,0.,0.};
359  UT_Vector4F MetallicComp = {1.,0.,0.,0.};
360  UT_Vector4F CoatIntComp = {1.,0.,0.,0.};
361  UT_Vector4F CoatRoughComp = {1.,0.,0.,0.};
362  UT_Vector4F OpacityComp = {1.,0.,0.,0.};
363  UT_Vector4F ReflectIntComp= {1.,0.,0.,0.};
364 
365  UT_Vector4i DiffuseUDIMArea = {0,0,0,0};
366  UT_Vector4i SpecularUDIMArea = {0,0,0,0};
367  UT_Vector4i OpacityUDIMArea = {0,0,0,0};
368  UT_Vector4i EmissionUDIMArea = {0,0,0,0};
369  UT_Vector4i NormalUDIMArea = {0,0,0,0};
370  UT_Vector4i RoughUDIMArea = {0,0,0,0};
371  UT_Vector4i DisplaceUDIMArea = {0,0,0,0};
372  UT_Vector4i OcclusionUDIMArea = {0,0,0,0};
373  UT_Vector4i MetallicUDIMArea = {0,0,0,0};
374  UT_Vector4i CoatIntUDIMArea = {0,0,0,0};
375  UT_Vector4i CoatRoughUDIMArea = {0,0,0,0};
376  UT_Vector4i ReflectIntUDIMArea = {0,0,0,0};
377 
378  UT_Vector2F NormalMapScaleShift = {1., 0.};
379  UT_Vector2F NormalMapScale = {1., 1.};
380  UT_Vector2F NormalMapFlip = {1., 1.};
381 
382  int32 HasDiffuse = false;
383  int32 HasSpecular = false;
384  int32 HasOpacity = false;
385  int32 HasEmission = false;
386  int32 HasNormal = false;
387  int32 HasRough = false;
388  int32 HasDisplace = false;
389  int32 HasOcclusion = false;
390  int32 HasMetallic = false;
391  int32 HasCoatInt = false;
392  int32 HasCoatRough = false;
393  int32 HasReflectInt = false;
394 
395  int32 HasDiffuseUV = false;
396  int32 HasSpecularUV = false;
397  int32 HasOpacityUV = false;
398  int32 HasEmissionUV = false;
399  int32 HasNormalUV = false;
400  int32 HasRoughUV = false;
401  int32 HasDisplaceUV = false;
402  int32 HasOcclusionUV = false;
403  int32 HasMetallicUV = false;
404  int32 HasCoatIntUV = false;
405  int32 HasCoatRoughUV = false;
406  int32 HasReflectIntUV = false;
407 
408  int32 NormalMapType = 0;
409 
410  int32 DisplaceSpace = 0;
411  fpreal32 DisplaceScale = 1.0;
412  fpreal32 DisplaceOffset = 0.0;
413  fpreal32 DisplaceQuality = 1.0;
414  int32 DisplaceYUp = true;
415 
416  int32 InvertOpacity = false;
417  int32 InvertRough = false;
418  int32 ReflectAsIOR = false;
419  } myTextureBlock;
420 
421  bool myTexDirtyFlag = true;
422  bool myTexBlockDirtyFlag = true;
423 
424  UT_StringHolder myUVSet;
425 #ifdef USE_VULKAN
428 
429  UT_UniquePtr<RV_ShaderBlock> myTextureMatBlock;
430  UT_UniquePtr<RV_ShaderBlock> myDisplaceMatBlock;
432 #endif
433 };
434 #undef TEX_PARM
435 
436 
437 
438 #define HAIR_PARM(TYPE, NAME) \
439  TYPE get##NAME() const { return myHairBlock.NAME; } \
440  void set##NAME(const TYPE &v) \
441  { if(myHairBlock.NAME != v) { myHairBlock.NAME=v; myBlockDirtyFlag=true; } } \
442  PARMKEY(NAME)
444 {
445 public:
446  struct Defaults {
447  static constexpr fpreal32 DiffIntensity = 0.5;
448  static constexpr UT_Vector3F DiffRootColor = {1.0, 1.0, 1.0};
449  static constexpr UT_Vector3F DiffTipColor = {1.0, 1.0, 1.0};
450  static constexpr int32 DiffUseBaseMap = 0;
451  static constexpr int32 DiffUseBlendRamp = 0;
452  static constexpr fpreal32 SpecIntensity = 0.2;
453  static constexpr fpreal32 SpecAngle = 0.0;
454  static constexpr UT_Vector3F SpecRootColor = {1.0, 1.0, 1.0};
455  static constexpr UT_Vector3F SpecTipColor = {1.0, 1.0, 1.0};
456  static constexpr fpreal32 SpecShift = 0.0;
457  static constexpr int32 SpecUseBaseMap = 0;
458  static constexpr int32 SpecUseBlendRamp = 0;
459  static constexpr fpreal32 HairAlpha = 1.0;
460  static constexpr int32 AlphaUseRamp = 0;
461  static constexpr int32 RandomDiffHue = 0;
462  static constexpr UT_Vector2F RandomDiffHueRange = {0.5, 1.0};
463  static constexpr int32 RandomDiffSat = 0;
464  static constexpr UT_Vector2F RandomDiffSatRange = {0.5, 1.0};
465  static constexpr int32 RandomDiffInt = 0;
466  static constexpr UT_Vector2F RandomDiffIntRange = {0.5, 1.0};
467  static constexpr int32 RandomSpecInt = 0;
468  static constexpr UT_Vector2F RandomSpecIntRange = {0.5, 1.0};
469  static constexpr fpreal32 Metal = 0.0;
470  static constexpr UT_Vector3F MetalColor = {1.0, 1.0, 1.0};
471  static constexpr UT_Vector4i DiffuseUDIMArea = {0,0,0,0};
472  static constexpr UT_Vector4i SpecularUDIMArea = {0,0,0,0};
473  static constexpr UT_Vector4i OpacityUDIMArea = {0,0,0,0};
474  static constexpr UT_Vector4i EmissionUDIMArea = {0,0,0,0};
475  };
476 
477  HAIR_PARM(fpreal32, DiffIntensity);
478  HAIR_PARM(UT_Vector3F, DiffRootColor);
479  HAIR_PARM(UT_Vector3F, DiffTipColor);
480 
481  HAIR_PARM(fpreal32, SpecIntensity);
482  HAIR_PARM(fpreal32, SpecAngle);
483  HAIR_PARM(UT_Vector3F, SpecRootColor);
484  HAIR_PARM(UT_Vector3F, SpecTipColor);
485  HAIR_PARM(fpreal32, SpecShift);
486 
487  HAIR_PARM(fpreal32, HairAlpha);
488 
489  HAIR_PARM(int32, RandomDiffHue);
490  HAIR_PARM(UT_Vector2F, RandomDiffHueRange);
491  HAIR_PARM(int32, RandomDiffSat);
492  HAIR_PARM(UT_Vector2F, RandomDiffSatRange);
493  HAIR_PARM(int32, RandomDiffInt);
494  HAIR_PARM(UT_Vector2F, RandomDiffIntRange);
495  HAIR_PARM(int32, RandomSpecInt);
496  HAIR_PARM(UT_Vector2F, RandomSpecIntRange);
497 
499  HAIR_PARM(UT_Vector3F, MetalColor);
500 
501  TEXMAP_PARM(DiffRootTipBlendMap, DiffRootTipBlendID);
502  TEXMAP_PARM(SpecRootTipBlendMap, SpecRootTipBlendID);
503  TEXMAP_PARM(AlphaRootTipBlendMap, AlphaRootTipBlendID);
504  TEXMAP_PARM(DiffuseMap, DiffuseID);
505  TEXMAP_PARM(OpacityMap, OpacityID);
506  TEXMAP_PARM(SpecularMap, SpecularID);
507  TEXMAP_PARM(EmissionMap, EmissionID);
508 
509  HAIR_PARM(int32, HasDiffRootTipBlend);
510  HAIR_PARM(int32, HasSpecRootTipBlend);
511  HAIR_PARM(int32, HasAlphaRootTipBlend);
512  HAIR_PARM(int32, HasDiffuse);
513  HAIR_PARM(int32, HasSpecular);
514 
515  HAIR_PARM(int32, HasDiffuseUV);
516  HAIR_PARM(int32, HasSpecularUV);
517 
518  HAIR_PARM(UT_Matrix4F, DiffuseUV);
519  HAIR_PARM(UT_Matrix4F, SpecularUV);
520 
521  HAIR_PARM(UT_Vector4i, DiffuseUDIMArea);
522  HAIR_PARM(UT_Vector4i, SpecularUDIMArea);
523 
524  void update(const GR_MaterialParms &options) override;
527  bool &created) override;
528  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
529 
530  void dirtyTextures() override { myTexDirtyFlag = true; }
531 
532 protected:
535 
536  friend class GR_Material;
537 private:
538  class HairBlock
539  {
540  public:
541  // reordered to minimise padding
542  SYS_ALIGN16 UT_Matrix4F DiffuseUV;
543  SYS_ALIGN16 UT_Matrix4F SpecularUV;
544 
545  SYS_ALIGN16 UT_Vector4i DiffuseUDIMArea = Defaults::DiffuseUDIMArea;
546  SYS_ALIGN16 UT_Vector4i SpecularUDIMArea = Defaults::SpecularUDIMArea;
547 
548  SYS_ALIGN16 UT_Vector3F DiffRootColor = Defaults::DiffRootColor;
549  SYS_ALIGN16 UT_Vector3F DiffTipColor = Defaults::DiffTipColor;
550  SYS_ALIGN16 UT_Vector3F SpecRootColor = Defaults::SpecRootColor;
551  SYS_ALIGN16 UT_Vector3F SpecTipColor = Defaults::SpecTipColor;
552 
553  UT_Vector2F RandomDiffHueRange =
554  Defaults::RandomDiffHueRange;
555  UT_Vector2F RandomDiffSatRange =
556  Defaults::RandomDiffSatRange;
557  UT_Vector2F RandomDiffIntRange =
558  Defaults::RandomDiffIntRange;
559  UT_Vector2F RandomSpecIntRange =
560  Defaults::RandomSpecIntRange;
561 
562  SYS_ALIGN16 UT_Vector3F MetalColor = Defaults::MetalColor;
563 
564  fpreal32 DiffIntensity = Defaults::DiffIntensity;
565 
566  fpreal32 SpecIntensity = Defaults::SpecIntensity;
567  fpreal32 SpecAngle = Defaults::SpecAngle;
568  fpreal32 SpecShift = Defaults::SpecShift;
569 
570  fpreal32 HairAlpha = Defaults::HairAlpha;
571 
572  int32 RandomDiffHue = Defaults::RandomDiffHue;
573  int32 RandomDiffSat = Defaults::RandomDiffSat;
574  int32 RandomDiffInt = Defaults::RandomDiffInt;
575  int32 RandomSpecInt = Defaults::RandomSpecInt;
576  fpreal32 Metal = Defaults::Metal;
577 
578  int32 HasDiffRootTipBlend = false;
579  int32 HasSpecRootTipBlend = false;
580  int32 HasAlphaRootTipBlend = false;
581  int32 HasDiffuse = false;
582  int32 HasSpecular = false;
583 
584  // are these necessary? why not just use an identity UV xform?
585  int32 HasDiffuseUV = false;
586  int32 HasSpecularUV = false;
587  } myHairBlock;
588 
589  bool myTexDirtyFlag = true;
590 
591 #ifdef USE_VULKAN
592  UT_UniquePtr<RV_ShaderBlock> myHairMatBlock;
593 #endif
594 };
595 
597 {
598 public:
599 
600  bool bindInt (const UT_StringRef &name, int32 value);
601  bool bindInts(const UT_StringRef &name, const UT_Array<int32> &values);
602 
603  bool bindFloat (const UT_StringRef &name, fpreal32 value);
604  bool bindFloats(const UT_StringRef &name, const UT_Array<fpreal32> &values);
605  bool bindFloat2(const UT_StringRef &name, const UT_Vector2D &value);
606  bool bindFloat3(const UT_StringRef &name, const UT_Vector3D &value);
607  bool bindFloat4(const UT_StringRef &name, const UT_Vector4D &value);
608  bool bindMatrix3(const UT_StringRef &name, const UT_Matrix3D &value);
609  bool bindMatrix4(const UT_StringRef &name, const UT_Matrix4D &value);
610 
611  bool bindTexture(const UT_StringRef &name,
612  const UT_StringRef &map_path,
613  bool is_color,
614  int ncomps,
615  const UT_Vector4F &fallback_color,
616  const RV_TextureParms *tex_parms = nullptr);
617 
619  { if (id != mySurfShaderID) { resetResources(); }
620  mySurfShaderID = id;
621  }
623  { if (id != myCurveShaderID) { resetResources(); }
624  myCurveShaderID = id; }
626  { if (id != myDisplaceShaderID) { resetResources(); }
627  myDisplaceShaderID = id;
628  }
630  { mySurfShaderID=myCurveShaderID=myDisplaceShaderID = 0;
631  resetResources(); }
632 
633 #ifdef USE_VULKAN
634  RV_ShaderProgram *getSurfaceShader() const override;
635  RV_ShaderProgram *getCurveShader() const override;
636  RV_ShaderCompute *getDisplaceShader() const override;
637 #endif
639 
640  void update(const GR_MaterialParms &options) override;
643  bool &created) override;
644  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
645 
646  // Cache name for the compiled info of a shader graph
648  { myCachedName = std::move(name); }
649  const UT_StringHolder &cachedName() const { return myCachedName; }
650 
651  // Cache name unique to a specific material object, even for
652  // materials that reference the same shader graph
654  {
655  if (myCachedName.isEmpty())
656  return;
657  name.format("{}?{}", myCachedName, id());
658  }
660  {
661  if (myCachedName.isEmpty())
662  return;
663  name.format("{}?{}&curve", myCachedName, id());
664  }
665 
666  void setShaderDirty(bool dirty) { myShaderDirty = dirty; }
667  bool isShaderDirty() const { return myShaderDirty; }
668 
669  void setMatXNodeVersion(int64 version) { myMatXVersion = version; }
670  int64 getMatXNodeVersion() const { return myMatXVersion; }
671 
672  void dirtyTextures() override { myTexturesDirty = true; }
673 
674  void setShaderCompiled(bool comp) { myShaderCompiled = comp; }
675  bool isShaderCompiled() const { return myShaderCompiled; }
676 
677  void setSurfShaderAssigned(bool comp) { mySurfShaderAssigned = comp; }
678  bool isSurfShaderAssigned() const { return mySurfShaderAssigned; }
679 
680  void setCurveShaderAssigned(bool comp) { myCurveShaderAssigned = comp; }
681  bool isCurveShaderAssigned() const { return myCurveShaderAssigned; }
682 
683  void setDisplaceShaderAssigned(bool comp) { myDisplaceShaderAssigned = comp;}
684  bool isDisplaceShaderAssigned() const { return myDisplaceShaderAssigned; }
685 
687  { myShaderCompileKey = std::move(key); }
688  const UT_StringHolder &shaderCompileKey() { return myShaderCompileKey; }
689 
690  void setFreeCB(UT_Functor1<void, GR_MatXMaterial*> cb) { myFreeCB = cb; }
691 
692  bool bindForCompute(RV_Render *r,
694  const GR_DisplayOption &opts) override;
695 
696 protected:
697  GR_MatXMaterial(const UT_StringHolder &name);
698  ~GR_MatXMaterial() override;
699 
701 
702  friend class GR_Material;
703 
704  void resetResources();
705 
706 private:
707  UT_StringHolder myCachedName;
708  bool myShaderDirty = true;
709  bool myTexturesDirty = true;
710  bool myBadShader = false;
711  bool myShaderCompiled = true;
712  bool mySurfShaderAssigned = false;
713  bool myCurveShaderAssigned = false;
714  bool myDisplaceShaderAssigned = false;
715  exint myMatXVersion = 0;
716  struct TextureDef
717  {
719  bool is_color = true;
720  int components = 4;
721  UT_Vector4F fallback = { 1.,1.,1.,1.};
722 #ifdef USE_VULKAN
723  RV_TextureParms tex_parms = RV_TextureParms();
724 #endif
725  };
726  UT_StringMap<TextureDef> myTextures;
727 #ifdef USE_VULKAN
728  void bindTextures(RV_Render *r,
730  const GR_DisplayOption *opts);
731 
735  UT_UniquePtr<RV_ShaderBlock> myFragUniformBlock;
736  UT_UniquePtr<RV_ShaderBlock> myTessUniformBlock;
737  UT_StringMap<RV_TextureRef> myTextureRefs;
738 #endif
739  UT_StringHolder myShaderCompileKey;
741  exint mySurfShaderID=0;
742  exint myCurveShaderID=0;
743  exint myDisplaceShaderID=0;
745 };
746 
747 #define LAYER_INST(NAME, TYPE) \
748 TYPE get##NAME(int idx) const { return myLayer.layer[idx].NAME; } \
749 void set##NAME(int idx, const TYPE &v) \
750 { if(myLayer.layer[idx].NAME != v) { myLayer.layer[idx].NAME=v; myLayerDirtyFlag=true; } } \
751  PARMKEY(NAME)
752 
753 
754 #define LAYER_PARM(NAME, TYPE) \
755  TYPE get##NAME() const { return myLayer.NAME; } \
756  void set##NAME(const TYPE &v) \
757  { if(myLayer.NAME != v) { myLayer.NAME=v; myLayerDirtyFlag=true; } } \
758  PARMKEY(NAME)
759 
761 {
762 public:
763  void updateDisplaceMap(RV_Render *r,
764  GT_DataArray *disp,
765  UT_Vector2i res);
766  void updateNormalMap(RV_Render *r,
767  GT_DataArray *nml,
768  UT_Vector2i res);
769  void updateColorMap(RV_Render *r,
771  UT_Vector2i res);
772  void updateBlendMap(RV_Render *r,
774  UT_Vector2i res);
775 
776  TEXMAP_PARM(RoughMap, RoughID);
777  TEXMAP_PARM(SpecularMap, SpecularID);
778  TEXMAP_PARM(EmissionMap, EmissionID);
779  TEXMAP_PARM(Layer1Map, Layer1ID);
780  TEXMAP_PARM(Layer2Map, Layer2ID);
781  TEXMAP_PARM(Layer3Map, Layer3ID);
782  TEXMAP_PARM(Layer4Map, Layer4ID);
783  TEXMAP_PARM(Layer5Map, Layer5ID);
784  TEXMAP_PARM(Layer6Map, Layer6ID);
785  TEXMAP_PARM(Layer7Map, Layer7ID);
786  TEXMAP_PARM(Layer8Map, Layer8ID);
787  TEXMAP_PARM(Layer9Map, Layer9ID);
788  TEXMAP_PARM(Layer10Map, Layer10ID);
789 
790  LAYER_PARM(Diff, UT_Vector3F);
791  LAYER_PARM(Spec, UT_Vector3F);
792  LAYER_PARM(SpecRough, fpreal32);
793  LAYER_PARM(SpecModel, int32);
795  LAYER_PARM(NumUVSets, int32);
796  LAYER_PARM(UseBlendMap, int32);
797  LAYER_PARM(HasTriplanar, int32);
798 
799  LAYER_INST(UVTransform, UT_Matrix4F);
800  LAYER_INST(Tint, UT_Vector4F);
801  LAYER_INST(TriplanarBlend, UT_Vector3F);
802  LAYER_INST(TriplanarOffset, UT_Vector3F);
803  LAYER_INST(TriplanarScale, fpreal32);
804  LAYER_INST(TriplanarSharp, fpreal32);
805  LAYER_INST(Rough, fpreal32);
806  LAYER_INST(UseTint, int32);
807  LAYER_INST(HasMap, int32);
808  LAYER_INST(UseTriplanar, int32);
809 
810  PARMKEY(ClampToEdge);
811 
812  void update(const GR_MaterialParms &options) override;
815  bool &created) override;
816  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
817 
818  void copy(const GR_HeightfieldMaterial *src);
819 
820 protected:
823 
824  friend class GR_Material;
825 private:
826  struct Layer
827  {
828  UT_Matrix4F UVTransform;
829  UT_Vector4F Tint = { 1,1,1,1};
830  UT_Vector3F TriplanarBlend = {1,1,1};
831  fpreal32 dummy1 = 0.0;
832  UT_Vector3F TriplanarOffset = {0,0,0};
833  fpreal32 TriplanarScale = 1.0;
834  fpreal32 TriplanarSharp = 1.0;
835  fpreal32 Rough = 1.0;
836  int32 UseTint = true;
837  int32 HasMap = false;
838  int32 UseTriplanar = false;
839  UT_Vector3F dummy2 = {0,0,0};
840  }; // padded to 144B
841 
842  class HFLayers
843  {
844  public:
845  UT_Vector3F Diff = {0.5,0.5,0.5};
846  fpreal32 SpecRough = 0.1;
847  UT_Vector3F Spec = {0.0, 0.0, 0.0};
848  int32 SpecModel = 2; // GGX
849  fpreal32 Quality = 1.0;
850  int32 NumUVSets = 1;
851  int32 UseBlendMap = false;
852  int32 HasTriplanar = false;
853  Layer layer[10];
854  } myLayer;
855 
856 
857  bool myTexDirtyFlag = true;
858  bool myLayerDirtyFlag = true;
859  int64 myDisplaceVersion = 0;
860  int64 myNormalVersion = 0;
861  int64 myColorVersion = 0;
862  int64 myBlendVersion = 0;
863  bool myClampToEdge[10];
864 #ifdef USE_VULKAN
865  UT_UniquePtr<RV_VKImage> myDisplaceMap;
866  UT_UniquePtr<RV_VKImage> myNormalMap;
867  UT_UniquePtr<RV_VKImage> myColorMap;
868  UT_UniquePtr<RV_VKImage> myBlendMap;
869  UT_UniquePtr<RV_ShaderBlock> myLayerBlock;
870 #endif
871 };
872 
873 #undef TEXMAP_PARM
874 #undef TEXMAP_PARM_VK
875 #undef PARMKEY
876 
877 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
void dirty(bool dirty=true)
Definition: GR_Material.h:102
const UT_StringHolder & getUVSet() const
virtual RV_ShaderProgram * getSurfaceShader() const
Definition: GR_Material.h:169
GT_API const UT_StringHolder filename
int int32
Definition: SYS_Types.h:39
bool isShaderCompiled() const
void dirtyTextures() override
bool isDisplaceShaderAssigned() const
#define LAYER_INST(NAME, TYPE)
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
const GLdouble * v
Definition: glcorearb.h:837
#define LAYER_PARM(NAME, TYPE)
#define TEX_PARM(TYPE, NAME)
void dirtyTextures() override
const UT_StringHolder & shaderCompileKey()
virtual void update(const GR_MaterialParms &options)=0
int64 getMatXNodeVersion() const
GLsizei const GLfloat * value
Definition: glcorearb.h:824
UT_NON_COPYABLE(GR_Material)
virtual bool bindForCompute(RV_Render *r, RV_ShaderProgramBase *shader, const GR_DisplayOption &opts)
int64 exint
Definition: SYS_Types.h:125
virtual bool initMaterialSetForRender(RV_Render *r, RV_ShaderProgramBase *shader, bool &created)=0
void setUVSet(const UT_StringRef &set)
void update(const GR_MaterialParms &options) override
void setMatXNodeVersion(int64 version)
float fpreal32
Definition: SYS_Types.h:200
#define TEXMAP_PARM(NAME, MAP)
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_NON_COPYABLE(GR_SimpleMaterial)
void dirtyTextures() override
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
Definition: simd.h:4949
void setCurveShaderAssigned(bool comp)
Quality
Definition: oidn.hpp:322
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
void setDisplaceShaderAssigned(bool comp)
Compute shader object.
void setShaderDirty(bool dirty)
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
bool isCurveShaderAssigned() const
void setCachedName(UT_StringHolder &name)
void setUDIM(const UT_Vector4i &udim)
constexpr auto set(type rhs) -> int
Definition: core.h:610
virtual RV_ShaderCompute * getDisplaceShader() const
Definition: GR_Material.h:171
void setShaderCompileKey(UT_StringHolder &key)
#define PARMKEY(NAME)
void setVertexOverrides(const UT_StringMap< UT_StringHolder > &ovr)
#define GR_API
Definition: GR_API.h:10
RV_TextureWrap
Definition: RV_Type.h:150
#define SYS_ALIGN16
Definition: SYS_Align.h:100
long long int64
Definition: SYS_Types.h:116
const UT_StringMap< UT_StringHolder > & vertexOverrides() const
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual bool initBlocks(RV_Render *r, const GR_DisplayOption *opts)=0
const UT_StringHolder & cachedName() const
#define MATPARM(TYPE, NAME)
bool initMaterialSetForRender(RV_Render *r, RV_ShaderProgramBase *shader, bool &created) override
GT_API const UT_StringHolder version
GLuint shader
Definition: glcorearb.h:785
size_t format(const char *fmt, const Args &...args)
More of a builtin material for the MatCap display mode.
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
GLuint color
Definition: glcorearb.h:1261
void makeUniqueCachedName(UT_WorkBuffer &name) const
bool isSurfShaderAssigned() const
virtual RV_ShaderProgram * getCurveShader() const
Definition: GR_Material.h:170
void setSurfShaderAssigned(bool comp)
UT_StringMap< GR_Material::InputType > & inputs()
void setSurfaceShader(exint id)
#define HAIR_PARM(TYPE, NAME)
GLboolean r
Definition: glcorearb.h:1222
bool isShaderDirty() const
This is a fast, non-string access and cut-down version of UT_Options.
Definition: GR_Material.h:331
void makeCachedCurveName(UT_WorkBuffer &name) const
GA_API const UT_StringHolder Alpha
bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override
void setShaderCompiled(bool comp)
void setCurveShader(exint id)
void setFreeCB(UT_Functor1< void, GR_MatXMaterial * > cb)
void dirtyTextures() override
GLenum src
Definition: glcorearb.h:1793
void setDisplaceShader(exint id)
exint id() const
Definition: GR_SceneItem.h:24