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  TEXMAP_PARM(DiffuseMap, DiffuseID);
216  TEXMAP_PARM(OpacityMap, OpacityID);
217  TEXMAP_PARM(SpecularMap, SpecularID);
218  TEXMAP_PARM(EmissionMap, EmissionID);
219  TEXMAP_PARM(NormalMap, NormalID);
220  TEXMAP_PARM(RoughMap, RoughID);
221  TEXMAP_PARM(OcclusionMap, OcclusionID);
222  TEXMAP_PARM(MetallicMap, MetallicID);
223  TEXMAP_PARM(CoatIntMap, CoatIntID);
224  TEXMAP_PARM(CoatRoughMap, CoatRoughID);
225  TEXMAP_PARM(ReflectIntMap, ReflectIntID);
226  TEXMAP_PARM(DisplaceMap, DisplaceID);
227 
228  TEX_PARM(UT_Matrix4F, DiffuseUV);
229  TEX_PARM(UT_Matrix4F, SpecularUV);
230  TEX_PARM(UT_Matrix4F, OpacityUV);
231  TEX_PARM(UT_Matrix4F, EmissionUV);
232  TEX_PARM(UT_Matrix4F, NormalUV);
233  TEX_PARM(UT_Matrix4F, RoughUV);
234  TEX_PARM(UT_Matrix4F, OcclusionUV);
235  TEX_PARM(UT_Matrix4F, MetallicUV);
236  TEX_PARM(UT_Matrix4F, CoatIntUV);
237  TEX_PARM(UT_Matrix4F, CoatRoughUV);
238  TEX_PARM(UT_Matrix4F, ReflectIntUV);
239  TEX_PARM(UT_Matrix4F, DisplaceUV);
240 
241  TEX_PARM(int32, HasDiffuse);
242  TEX_PARM(int32, HasSpecular);
243  TEX_PARM(int32, HasOpacity);
244  TEX_PARM(int32, HasEmission);
245  TEX_PARM(int32, HasNormal);
246  TEX_PARM(int32, HasRough);
247  TEX_PARM(int32, HasOcclusion);
248  TEX_PARM(int32, HasMetallic);
249  TEX_PARM(int32, HasCoatInt);
250  TEX_PARM(int32, HasCoatRough);
251  TEX_PARM(int32, HasReflectInt);
252  TEX_PARM(int32, HasDisplace);
253 
254  TEX_PARM(int32, HasDiffuseUV);
255  TEX_PARM(int32, HasSpecularUV);
256  TEX_PARM(int32, HasOpacityUV);
257  TEX_PARM(int32, HasEmissionUV);
258  TEX_PARM(int32, HasNormalUV);
259  TEX_PARM(int32, HasRoughUV);
260  TEX_PARM(int32, HasOcclusionUV);
261  TEX_PARM(int32, HasMetallicUV);
262  TEX_PARM(int32, HasCoatIntUV);
263  TEX_PARM(int32, HasCoatRoughUV);
264  TEX_PARM(int32, HasReflectIntUV);
265  TEX_PARM(int32, HasDisplaceUV);
266 
267  // Components
268  TEX_PARM(UT_Vector4F, RoughComp);
269  TEX_PARM(UT_Vector4F, OcclusionComp);
270  TEX_PARM(UT_Vector4F, MetallicComp);
271  TEX_PARM(UT_Vector4F, CoatIntComp);
272  TEX_PARM(UT_Vector4F, CoatRoughComp);
273  TEX_PARM(UT_Vector4F, OpacityComp);
274  TEX_PARM(UT_Vector4F, ReflectIntComp);
275 
276  // UDIM
277  TEX_PARM(UT_Vector4i, DiffuseUDIMArea);
278  TEX_PARM(UT_Vector4i, SpecularUDIMArea);
279  TEX_PARM(UT_Vector4i, OpacityUDIMArea);
280  TEX_PARM(UT_Vector4i, EmissionUDIMArea);
281  TEX_PARM(UT_Vector4i, NormalUDIMArea);
282  TEX_PARM(UT_Vector4i, RoughUDIMArea);
283  TEX_PARM(UT_Vector4i, OcclusionUDIMArea);
284  TEX_PARM(UT_Vector4i, MetallicUDIMArea);
285  TEX_PARM(UT_Vector4i, CoatIntUDIMArea);
286  TEX_PARM(UT_Vector4i, CoatRoughUDIMArea);
287  TEX_PARM(UT_Vector4i, ReflectIntUDIMArea);
288  TEX_PARM(UT_Vector4i, DisplaceUDIMArea);
289 
290  // Specific texture parms
291  // NORMAL
292  TEX_PARM(int32, NormalMapType);
293  TEX_PARM(UT_Vector2F, NormalMapScaleShift);
294  TEX_PARM(UT_Vector2F, NormalMapScale);
295  TEX_PARM(UT_Vector2F, NormalMapFlip);
296 
297  // DISPLACEMENT
298  TEX_PARM(int32, DisplaceSpace);
299  TEX_PARM(fpreal32, DisplaceScale);
300  TEX_PARM(fpreal32, DisplaceOffset);
301  TEX_PARM(fpreal32, DisplaceQuality);
302  TEX_PARM(int32, DisplaceYUp);
303 
304  TEX_PARM(int32, InvertOpacity );
305  TEX_PARM(int32, InvertRough );
306  TEX_PARM(int32, ReflectAsIOR);
307 
308  // Texture and UV wrapping
309  void setUVSet(const UT_StringRef &set) { myUVSet = set; }
310  const UT_StringHolder &getUVSet() const { return myUVSet; }
311 
312 #ifdef USE_VULKAN
313  void setTextureWrapU(RV_TextureWrap u) { myUWrap = u; }
314  RV_TextureWrap getTextureWrapU() const { return myUWrap; }
315 
316  void setTextureWrapV(RV_TextureWrap v) { myVWrap = v; }
317  RV_TextureWrap getTextureWrapV() const { return myVWrap; }
318 #endif
319 
320  // Update functions
321  void update(const GR_MaterialParms &options) override;
324  bool &created) override;
325  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
326 
327  void dirtyTextures() override { myTexDirtyFlag = true; dirty(true); }
328 
329 protected:
332 
333  friend class GR_Material;
334 private:
335  class TexturedBlock
336  {
337  public:
338  UT_Matrix4F DiffuseUV;
339  UT_Matrix4F SpecularUV;
340  UT_Matrix4F OpacityUV;
341  UT_Matrix4F EmissionUV;
342  UT_Matrix4F NormalUV;
343  UT_Matrix4F RoughUV;
344  UT_Matrix4F DisplaceUV;
345  UT_Matrix4F OcclusionUV;
346  UT_Matrix4F MetallicUV;
347  UT_Matrix4F CoatIntUV;
348  UT_Matrix4F CoatRoughUV;
349  UT_Matrix4F ReflectIntUV;
350 
351  UT_Vector4F RoughComp = {1.,0.,0.,0.};
352  UT_Vector4F OcclusionComp = {1.,0.,0.,0.};
353  UT_Vector4F MetallicComp = {1.,0.,0.,0.};
354  UT_Vector4F CoatIntComp = {1.,0.,0.,0.};
355  UT_Vector4F CoatRoughComp = {1.,0.,0.,0.};
356  UT_Vector4F OpacityComp = {1.,0.,0.,0.};
357  UT_Vector4F ReflectIntComp= {1.,0.,0.,0.};
358 
359  UT_Vector4i DiffuseUDIMArea = {0,0,0,0};
360  UT_Vector4i SpecularUDIMArea = {0,0,0,0};
361  UT_Vector4i OpacityUDIMArea = {0,0,0,0};
362  UT_Vector4i EmissionUDIMArea = {0,0,0,0};
363  UT_Vector4i NormalUDIMArea = {0,0,0,0};
364  UT_Vector4i RoughUDIMArea = {0,0,0,0};
365  UT_Vector4i DisplaceUDIMArea = {0,0,0,0};
366  UT_Vector4i OcclusionUDIMArea = {0,0,0,0};
367  UT_Vector4i MetallicUDIMArea = {0,0,0,0};
368  UT_Vector4i CoatIntUDIMArea = {0,0,0,0};
369  UT_Vector4i CoatRoughUDIMArea = {0,0,0,0};
370  UT_Vector4i ReflectIntUDIMArea = {0,0,0,0};
371 
372  UT_Vector2F NormalMapScaleShift = {1., 0.};
373  UT_Vector2F NormalMapScale = {1., 1.};
374  UT_Vector2F NormalMapFlip = {1., 1.};
375 
376  int32 HasDiffuse = false;
377  int32 HasSpecular = false;
378  int32 HasOpacity = false;
379  int32 HasEmission = false;
380  int32 HasNormal = false;
381  int32 HasRough = false;
382  int32 HasDisplace = false;
383  int32 HasOcclusion = false;
384  int32 HasMetallic = false;
385  int32 HasCoatInt = false;
386  int32 HasCoatRough = false;
387  int32 HasReflectInt = false;
388 
389  int32 HasDiffuseUV = false;
390  int32 HasSpecularUV = false;
391  int32 HasOpacityUV = false;
392  int32 HasEmissionUV = false;
393  int32 HasNormalUV = false;
394  int32 HasRoughUV = false;
395  int32 HasDisplaceUV = false;
396  int32 HasOcclusionUV = false;
397  int32 HasMetallicUV = false;
398  int32 HasCoatIntUV = false;
399  int32 HasCoatRoughUV = false;
400  int32 HasReflectIntUV = false;
401 
402  int32 NormalMapType = 0;
403 
404  int32 DisplaceSpace = 0;
405  fpreal32 DisplaceScale = 1.0;
406  fpreal32 DisplaceOffset = 0.0;
407  fpreal32 DisplaceQuality = 1.0;
408  int32 DisplaceYUp = true;
409 
410  int32 InvertOpacity = false;
411  int32 InvertRough = false;
412  int32 ReflectAsIOR = false;
413  } myTextureBlock;
414 
415  bool myTexDirtyFlag = true;
416  bool myTexBlockDirtyFlag = true;
417 
418  UT_StringHolder myUVSet;
419 #ifdef USE_VULKAN
422 
423  UT_UniquePtr<RV_ShaderBlock> myTextureMatBlock;
424 #endif
425 };
426 #undef TEX_PARM
427 
428 
429 
430 #define HAIR_PARM(TYPE, NAME) \
431  TYPE get##NAME() const { return myHairBlock.NAME; } \
432  void set##NAME(const TYPE &v) \
433  { if(myHairBlock.NAME != v) { myHairBlock.NAME=v; myBlockDirtyFlag=true; } } \
434  PARMKEY(NAME)
436 {
437 public:
438  struct Defaults {
439  static constexpr fpreal32 DiffIntensity = 0.5;
440  static constexpr UT_Vector3F DiffRootColor = {1.0, 1.0, 1.0};
441  static constexpr UT_Vector3F DiffTipColor = {1.0, 1.0, 1.0};
442  static constexpr int32 DiffUseBaseMap = 0;
443  static constexpr int32 DiffUseBlendRamp = 0;
444  static constexpr fpreal32 SpecIntensity = 0.2;
445  static constexpr fpreal32 SpecAngle = 0.0;
446  static constexpr UT_Vector3F SpecRootColor = {1.0, 1.0, 1.0};
447  static constexpr UT_Vector3F SpecTipColor = {1.0, 1.0, 1.0};
448  static constexpr fpreal32 SpecShift = 0.0;
449  static constexpr int32 SpecUseBaseMap = 0;
450  static constexpr int32 SpecUseBlendRamp = 0;
451  static constexpr fpreal32 HairAlpha = 1.0;
452  static constexpr int32 AlphaUseRamp = 0;
453  static constexpr int32 RandomDiffHue = 0;
454  static constexpr UT_Vector2F RandomDiffHueRange = {0.5, 1.0};
455  static constexpr int32 RandomDiffSat = 0;
456  static constexpr UT_Vector2F RandomDiffSatRange = {0.5, 1.0};
457  static constexpr int32 RandomDiffInt = 0;
458  static constexpr UT_Vector2F RandomDiffIntRange = {0.5, 1.0};
459  static constexpr int32 RandomSpecInt = 0;
460  static constexpr UT_Vector2F RandomSpecIntRange = {0.5, 1.0};
461  static constexpr fpreal32 Metal = 0.0;
462  static constexpr UT_Vector3F MetalColor = {1.0, 1.0, 1.0};
463  static constexpr UT_Vector4i DiffuseUDIMArea = {0,0,0,0};
464  static constexpr UT_Vector4i SpecularUDIMArea = {0,0,0,0};
465  static constexpr UT_Vector4i OpacityUDIMArea = {0,0,0,0};
466  static constexpr UT_Vector4i EmissionUDIMArea = {0,0,0,0};
467  };
468 
469  HAIR_PARM(fpreal32, DiffIntensity);
470  HAIR_PARM(UT_Vector3F, DiffRootColor);
471  HAIR_PARM(UT_Vector3F, DiffTipColor);
472 
473  HAIR_PARM(fpreal32, SpecIntensity);
474  HAIR_PARM(fpreal32, SpecAngle);
475  HAIR_PARM(UT_Vector3F, SpecRootColor);
476  HAIR_PARM(UT_Vector3F, SpecTipColor);
477  HAIR_PARM(fpreal32, SpecShift);
478 
479  HAIR_PARM(fpreal32, HairAlpha);
480 
481  HAIR_PARM(int32, RandomDiffHue);
482  HAIR_PARM(UT_Vector2F, RandomDiffHueRange);
483  HAIR_PARM(int32, RandomDiffSat);
484  HAIR_PARM(UT_Vector2F, RandomDiffSatRange);
485  HAIR_PARM(int32, RandomDiffInt);
486  HAIR_PARM(UT_Vector2F, RandomDiffIntRange);
487  HAIR_PARM(int32, RandomSpecInt);
488  HAIR_PARM(UT_Vector2F, RandomSpecIntRange);
489 
491  HAIR_PARM(UT_Vector3F, MetalColor);
492 
493  TEXMAP_PARM(DiffRootTipBlendMap, DiffRootTipBlendID);
494  TEXMAP_PARM(SpecRootTipBlendMap, SpecRootTipBlendID);
495  TEXMAP_PARM(AlphaRootTipBlendMap, AlphaRootTipBlendID);
496  TEXMAP_PARM(DiffuseMap, DiffuseID);
497  TEXMAP_PARM(OpacityMap, OpacityID);
498  TEXMAP_PARM(SpecularMap, SpecularID);
499  TEXMAP_PARM(EmissionMap, EmissionID);
500 
501  HAIR_PARM(int32, HasDiffRootTipBlend);
502  HAIR_PARM(int32, HasSpecRootTipBlend);
503  HAIR_PARM(int32, HasAlphaRootTipBlend);
504  HAIR_PARM(int32, HasDiffuse);
505  HAIR_PARM(int32, HasSpecular);
506 
507  HAIR_PARM(int32, HasDiffuseUV);
508  HAIR_PARM(int32, HasSpecularUV);
509 
510  HAIR_PARM(UT_Matrix4F, DiffuseUV);
511  HAIR_PARM(UT_Matrix4F, SpecularUV);
512 
513  HAIR_PARM(UT_Vector4i, DiffuseUDIMArea);
514  HAIR_PARM(UT_Vector4i, SpecularUDIMArea);
515 
516  void update(const GR_MaterialParms &options) override;
519  bool &created) override;
520  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
521 
522  void dirtyTextures() override { myTexDirtyFlag = true; }
523 
524 protected:
527 
528  friend class GR_Material;
529 private:
530  class HairBlock
531  {
532  public:
533  // reordered to minimise padding
534  SYS_ALIGN16 UT_Matrix4F DiffuseUV;
535  SYS_ALIGN16 UT_Matrix4F SpecularUV;
536 
537  SYS_ALIGN16 UT_Vector4i DiffuseUDIMArea = Defaults::DiffuseUDIMArea;
538  SYS_ALIGN16 UT_Vector4i SpecularUDIMArea = Defaults::SpecularUDIMArea;
539 
540  SYS_ALIGN16 UT_Vector3F DiffRootColor = Defaults::DiffRootColor;
541  SYS_ALIGN16 UT_Vector3F DiffTipColor = Defaults::DiffTipColor;
542  SYS_ALIGN16 UT_Vector3F SpecRootColor = Defaults::SpecRootColor;
543  SYS_ALIGN16 UT_Vector3F SpecTipColor = Defaults::SpecTipColor;
544 
545  UT_Vector2F RandomDiffHueRange =
546  Defaults::RandomDiffHueRange;
547  UT_Vector2F RandomDiffSatRange =
548  Defaults::RandomDiffSatRange;
549  UT_Vector2F RandomDiffIntRange =
550  Defaults::RandomDiffIntRange;
551  UT_Vector2F RandomSpecIntRange =
552  Defaults::RandomSpecIntRange;
553 
554  SYS_ALIGN16 UT_Vector3F MetalColor = Defaults::MetalColor;
555 
556  fpreal32 DiffIntensity = Defaults::DiffIntensity;
557 
558  fpreal32 SpecIntensity = Defaults::SpecIntensity;
559  fpreal32 SpecAngle = Defaults::SpecAngle;
560  fpreal32 SpecShift = Defaults::SpecShift;
561 
562  fpreal32 HairAlpha = Defaults::HairAlpha;
563 
564  int32 RandomDiffHue = Defaults::RandomDiffHue;
565  int32 RandomDiffSat = Defaults::RandomDiffSat;
566  int32 RandomDiffInt = Defaults::RandomDiffInt;
567  int32 RandomSpecInt = Defaults::RandomSpecInt;
568  fpreal32 Metal = Defaults::Metal;
569 
570  int32 HasDiffRootTipBlend = false;
571  int32 HasSpecRootTipBlend = false;
572  int32 HasAlphaRootTipBlend = false;
573  int32 HasDiffuse = false;
574  int32 HasSpecular = false;
575 
576  // are these necessary? why not just use an identity UV xform?
577  int32 HasDiffuseUV = false;
578  int32 HasSpecularUV = false;
579  } myHairBlock;
580 
581  bool myTexDirtyFlag = true;
582 
583 #ifdef USE_VULKAN
584  UT_UniquePtr<RV_ShaderBlock> myHairMatBlock;
585 #endif
586 };
587 
589 {
590 public:
591 
592  bool bindInt (const UT_StringRef &name, int32 value);
593  bool bindInts(const UT_StringRef &name, const UT_Array<int32> &values);
594 
595  bool bindFloat (const UT_StringRef &name, fpreal32 value);
596  bool bindFloats(const UT_StringRef &name, const UT_Array<fpreal32> &values);
597  bool bindFloat2(const UT_StringRef &name, const UT_Vector2D &value);
598  bool bindFloat3(const UT_StringRef &name, const UT_Vector3D &value);
599  bool bindFloat4(const UT_StringRef &name, const UT_Vector4D &value);
600  bool bindMatrix3(const UT_StringRef &name, const UT_Matrix3D &value);
601  bool bindMatrix4(const UT_StringRef &name, const UT_Matrix4D &value);
602 
603  bool bindTexture(const UT_StringRef &name,
604  const UT_StringRef &map_path,
605  bool is_color,
606  const UT_Vector4F &fallback_color,
607  const RV_TextureParms *tex_parms = nullptr);
608 
609  void enableLighting(bool enable)
610  {
611  if(enable != myEnableLighting)
612  {
613  myEnableLighting = enable;
614  myBlockDirtyFlag = true;
615  }
616  }
617 
619  {
620  if (id != mySurfShaderID) { resetResources(); }
621  mySurfShaderID = id;
622  }
623 
625  { if (id != mySurfShaderID) { resetResources(); }
626  myCurveShaderID = id; }
627 
628 #ifdef USE_VULKAN
629  RV_ShaderProgram *getSurfaceShader() const override;
630  RV_ShaderProgram *getCurveShader() const override;
631 #endif
632 
633  void update(const GR_MaterialParms &options) override;
636  bool &created) override;
637  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
638 
639  // Cache name for the compiled info of a shader graph
641  { myCachedName = std::move(name); }
642  const UT_StringHolder &cachedName() const { return myCachedName; }
643 
644  // Cache name unique to a specific material object, even for
645  // materials that reference the same shader graph
647  {
648  if (myCachedName.isEmpty())
649  return;
650  name.format("{}?{}", myCachedName, id());
651  }
653  {
654  if (myCachedName.isEmpty())
655  return;
656  name.format("{}?{}&curve", myCachedName, id());
657  }
658 
659  void setShaderDirty(bool dirty) { myShaderDirty = dirty; }
660  bool isShaderDirty() const { return myShaderDirty; }
661 
662  void setMatXNodeVersion(int64 version) { myMatXVersion = version; }
663  int64 getMatXNodeVersion() const { return myMatXVersion; }
664 
665  void dirtyTextures() override { myTexturesDirty = true; }
666 
667  void setShaderCompiled(bool comp) { myShaderCompiled = comp; }
668  bool isShaderCompiled() const { return myShaderCompiled; }
669 
670  void setSurfShaderAssigned(bool comp) { mySurfShaderAssigned = comp; }
671  bool isSurfShaderAssigned() const { return mySurfShaderAssigned; }
672 
673  void setCurveShaderAssigned(bool comp) { myCurveShaderAssigned = comp; }
674  bool isCurveShaderAssigned() const { return myCurveShaderAssigned; }
675 
676 protected:
677  GR_MatXMaterial(const UT_StringHolder &name);
678  ~GR_MatXMaterial() override;
679 
681 
682  friend class GR_Material;
683 
684  void resetResources();
685 
686 private:
687  UT_StringHolder myCachedName;
688  bool myShaderDirty = true;
689  bool myTexturesDirty = true;
690  bool myEnableLighting = true;
691  bool myBadShader = false;
692  bool myShaderCompiled = true;
693  bool mySurfShaderAssigned = false;
694  bool myCurveShaderAssigned = false;
695  exint myMatXVersion = 0;
696  struct TextureDef
697  {
699  bool is_color = true;
700  UT_Vector4F fallback = { 1.,1.,1.,1.};
701 #ifdef USE_VULKAN
702  RV_TextureParms tex_parms = RV_TextureParms();
703 #endif
704  };
705  UT_StringMap<TextureDef> myTextures;
706 #ifdef USE_VULKAN
707  void bindTextures(RV_Render *r,
709  const GR_DisplayOption *opts);
710 
713  UT_UniquePtr<RV_ShaderBlock> myFragUniformBlock;
714  UT_UniquePtr<RV_ShaderBlock> myTessUniformBlock;
715  UT_StringMap<RV_TextureRef> myTextureRefs;
716 #endif
717 
718  exint mySurfShaderID=0;
719  exint myCurveShaderID=0;
720 };
721 
722 #define LAYER_INST(NAME, TYPE) \
723 TYPE get##NAME(int idx) const { return myLayer.layer[idx].NAME; } \
724 void set##NAME(int idx, const TYPE &v) \
725 { if(myLayer.layer[idx].NAME != v) { myLayer.layer[idx].NAME=v; myLayerDirtyFlag=true; } } \
726  PARMKEY(NAME)
727 
728 
729 #define LAYER_PARM(NAME, TYPE) \
730  TYPE get##NAME() const { return myLayer.NAME; } \
731  void set##NAME(const TYPE &v) \
732  { if(myLayer.NAME != v) { myLayer.NAME=v; myLayerDirtyFlag=true; } } \
733  PARMKEY(NAME)
734 
736 {
737 public:
738  void updateDisplaceMap(RV_Render *r,
739  GT_DataArray *disp,
740  UT_Vector2i res);
741  void updateNormalMap(RV_Render *r,
742  GT_DataArray *nml,
743  UT_Vector2i res);
744  void updateColorMap(RV_Render *r,
746  UT_Vector2i res);
747  void updateBlendMap(RV_Render *r,
749  UT_Vector2i res);
750 
751  TEXMAP_PARM(RoughMap, RoughID);
752  TEXMAP_PARM(SpecularMap, SpecularID);
753  TEXMAP_PARM(EmissionMap, EmissionID);
754  TEXMAP_PARM(Layer1Map, Layer1ID);
755  TEXMAP_PARM(Layer2Map, Layer2ID);
756  TEXMAP_PARM(Layer3Map, Layer3ID);
757  TEXMAP_PARM(Layer4Map, Layer4ID);
758  TEXMAP_PARM(Layer5Map, Layer5ID);
759  TEXMAP_PARM(Layer6Map, Layer6ID);
760  TEXMAP_PARM(Layer7Map, Layer7ID);
761  TEXMAP_PARM(Layer8Map, Layer8ID);
762  TEXMAP_PARM(Layer9Map, Layer9ID);
763  TEXMAP_PARM(Layer10Map, Layer10ID);
764 
765  LAYER_PARM(Diff, UT_Vector3F);
766  LAYER_PARM(Spec, UT_Vector3F);
767  LAYER_PARM(SpecRough, fpreal32);
768  LAYER_PARM(SpecModel, int32);
770  LAYER_PARM(NumUVSets, int32);
771  LAYER_PARM(UseBlendMap, int32);
772  LAYER_PARM(HasTriplanar, int32);
773 
774  LAYER_INST(UVTransform, UT_Matrix4F);
775  LAYER_INST(Tint, UT_Vector4F);
776  LAYER_INST(TriplanarBlend, UT_Vector3F);
777  LAYER_INST(TriplanarOffset, UT_Vector3F);
778  LAYER_INST(TriplanarScale, fpreal32);
779  LAYER_INST(TriplanarSharp, fpreal32);
780  LAYER_INST(Rough, fpreal32);
781  LAYER_INST(UseTint, int32);
782  LAYER_INST(HasMap, int32);
783  LAYER_INST(UseTriplanar, int32);
784 
785  PARMKEY(ClampToEdge);
786 
787  void update(const GR_MaterialParms &options) override;
790  bool &created) override;
791  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
792 
793  void copy(const GR_HeightfieldMaterial *src);
794 
795 protected:
798 
799  friend class GR_Material;
800 private:
801  struct Layer
802  {
803  UT_Matrix4F UVTransform;
804  UT_Vector4F Tint = { 1,1,1,1};
805  UT_Vector3F TriplanarBlend = {1,1,1};
806  fpreal32 dummy1 = 0.0;
807  UT_Vector3F TriplanarOffset = {0,0,0};
808  fpreal32 TriplanarScale = 1.0;
809  fpreal32 TriplanarSharp = 1.0;
810  fpreal32 Rough = 0.0;
811  int32 UseTint = true;
812  int32 HasMap = false;
813  int32 UseTriplanar = false;
814  UT_Vector3F dummy2 = {0,0,0};
815  }; // padded to 144B
816 
817  class HFLayers
818  {
819  public:
820  UT_Vector3F Diff = {0.5,0.5,0.5};
821  fpreal32 SpecRough = 0.0;
822  UT_Vector3F Spec = {0.3, 0.3, 0.3};
823  int32 SpecModel = 2; // GGX
824  fpreal32 Quality = 1.0;
825  int32 NumUVSets = 1;
826  int32 UseBlendMap = false;
827  int32 HasTriplanar = false;
828  Layer layer[10];
829  } myLayer;
830 
831 
832  bool myTexDirtyFlag = true;
833  bool myLayerDirtyFlag = true;
834  int64 myDisplaceVersion = 0;
835  int64 myNormalVersion = 0;
836  int64 myColorVersion = 0;
837  int64 myBlendVersion = 0;
838  bool myClampToEdge[10];
839 #ifdef USE_VULKAN
840  UT_UniquePtr<RV_VKImage> myDisplaceMap;
841  UT_UniquePtr<RV_VKImage> myNormalMap;
842  UT_UniquePtr<RV_VKImage> myColorMap;
843  UT_UniquePtr<RV_VKImage> myBlendMap;
844  UT_UniquePtr<RV_ShaderBlock> myLayerBlock;
845 #endif
846 };
847 
848 #undef TEXMAP_PARM
849 #undef TEXMAP_PARM_VK
850 #undef PARMKEY
851 
852 #endif
void enableLighting(bool enable)
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
void dirty(bool dirty=true)
Definition: GR_Material.h:99
const UT_StringHolder & getUVSet() const
virtual RV_ShaderProgram * getSurfaceShader() const
Definition: GR_Material.h:162
GT_API const UT_StringHolder filename
int int32
Definition: SYS_Types.h:39
bool isShaderCompiled() const
void dirtyTextures() override
#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
virtual void update(const GR_MaterialParms &options)=0
int64 getMatXNodeVersion() const
bool initMaterialSetForRender(RV_Render *r, RV_ShaderProgram *shader, bool &created) override
UT_NON_COPYABLE(GR_Material)
int64 exint
Definition: SYS_Types.h:125
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:4784
void setCurveShaderAssigned(bool comp)
Quality
Definition: oidn.hpp:322
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)
#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:147
#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)
GT_API const UT_StringHolder version
virtual bool initMaterialSetForRender(RV_Render *r, RV_ShaderProgram *shader, bool &created)=0
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:163
void setSurfShaderAssigned(bool comp)
void setSurfaceShader(exint id)
Definition: core.h:1131
#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:323
void makeCachedCurveName(UT_WorkBuffer &name) const
type
Definition: core.h:1059
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 dirtyTextures() override
GLenum src
Definition: glcorearb.h:1793
exint id() const
Definition: GR_SceneItem.h:24