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 
106 protected:
108  MaterialType type = SIMPLE_SURFACE);
110 
111  friend class GR_Material;
112 
113 private:
114  struct SimpleMaterialBlock
115  {
116  // Not using explicit padding (SYS_ALIGN16) on the Vector3 fields
117  // because then sizeof(SimpleMaterialBlock) would report a size that
118  // includes the "padding required to place such an object in an array",
119  // which disagrees with the size determined by SPIR-V reflection.
120  // https://en.cppreference.com/w/cpp/language/sizeof
121  UT_Vector3F Diff = { 1.0, 1.0, 1.0 };
122  fpreal32 Padding0;
123  UT_Vector3F Spec = { 1.0, 1.0, 1.0 };
124  fpreal32 Padding1;
125  UT_Vector3F Emit = { 0.0, 0.0, 0.0 };
126  fpreal32 Padding2;
127  UT_Vector3F MetalColor = { 1.0, 1.0, 1.0 };
128  fpreal32 Padding3;
129  UT_Vector3F SheenColor = { 1.0, 1.0, 1.0 };
130 
131  fpreal32 DiffRough = 0.5;
132  fpreal32 SpecRough = 0.3;
133  fpreal32 SpecTint = 1.0;
134  fpreal32 Metal = 0.0;
135  fpreal32 IOR = 1.33;
136  fpreal32 Alpha = 1.0;
137  fpreal32 AlphaPara = 1.0;
138  fpreal32 AlphaCutoff = 0.0;
139  int32 AlphaMode = ALPHA_BLEND;
140  fpreal32 CoatIntensity = 0.0;
141  fpreal32 CoatRough = 0.1;
142  fpreal32 SheenIntensity = 0.0;
143  fpreal32 SheenRough = 0.1;
144  int32 SpecModel = 2;
145  int32 CoatSpecModel = 2;
146  int32 UseGeoColor = 1;
147  int32 UsePackedColor = 1;
148  int32 HasTextures = 0;
149  } mySimpleBlock;
150 #ifdef USE_VULKAN
151  UT_UniquePtr<RV_ShaderBlock> mySimpleMatBlock;
152 #endif
153 };
154 
155 
156 /// More of a builtin material for the MatCap display mode
158 {
159 public:
160  TEXMAP_PARM(DiffuseMap, DiffuseID);
161  TEXMAP_PARM(EmissionMap, EmissionID);
162  MATPARM(fpreal32, Intensity);
163 
164  void setUDIM(const UT_Vector4i &udim)
165  { mySimpleBlock.udim_area = udim; myBlockDirtyFlag = true; }
166 
167  void update(const GR_MaterialParms &options) override;
170  bool &created) override;
171  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
172 
173  void dirtyTextures() override { myTexDirtyFlag = true; }
174 
175 protected:
177  MaterialType type = MATCAP_SURFACE);
179 
180  friend class GR_Material;
181 
182  struct
183  {
185  fpreal32 Intensity = 1.0;
186  } mySimpleBlock;
187 
188  bool myTexDirtyFlag = true;
189 #ifdef USE_VULKAN
190  UT_UniquePtr<RV_ShaderBlock> myMatCapBlock;
191 #endif
192 };
193 
194 #undef MATPARM
195 
196 // Film Material ------------------------------------------------------------
197 
198 #define TEX_PARM(TYPE, NAME) \
199  TYPE get##NAME() const { return myTextureBlock.NAME; } \
200  void set##NAME(const TYPE &v) \
201  { if(myTextureBlock.NAME != v) \
202  { myTextureBlock.NAME=v; myTexBlockDirtyFlag=true; } \
203  } \
204  PARMKEY(NAME)
205 
207 {
208 public:
209  TEXMAP_PARM(DiffuseMap, DiffuseID);
210  TEXMAP_PARM(OpacityMap, OpacityID);
211  TEXMAP_PARM(SpecularMap, SpecularID);
212  TEXMAP_PARM(EmissionMap, EmissionID);
213  TEXMAP_PARM(NormalMap, NormalID);
214  TEXMAP_PARM(RoughMap, RoughID);
215  TEXMAP_PARM(OcclusionMap, OcclusionID);
216  TEXMAP_PARM(MetallicMap, MetallicID);
217  TEXMAP_PARM(CoatIntMap, CoatIntID);
218  TEXMAP_PARM(CoatRoughMap, CoatRoughID);
219  TEXMAP_PARM(ReflectIntMap, ReflectIntID);
220  TEXMAP_PARM(DisplaceMap, DisplaceID);
221 
222  TEX_PARM(UT_Matrix4F, DiffuseUV);
223  TEX_PARM(UT_Matrix4F, SpecularUV);
224  TEX_PARM(UT_Matrix4F, OpacityUV);
225  TEX_PARM(UT_Matrix4F, EmissionUV);
226  TEX_PARM(UT_Matrix4F, NormalUV);
227  TEX_PARM(UT_Matrix4F, RoughUV);
228  TEX_PARM(UT_Matrix4F, OcclusionUV);
229  TEX_PARM(UT_Matrix4F, MetallicUV);
230  TEX_PARM(UT_Matrix4F, CoatIntUV);
231  TEX_PARM(UT_Matrix4F, CoatRoughUV);
232  TEX_PARM(UT_Matrix4F, ReflectIntUV);
233  TEX_PARM(UT_Matrix4F, DisplaceUV);
234 
235  TEX_PARM(int32, HasDiffuse);
236  TEX_PARM(int32, HasSpecular);
237  TEX_PARM(int32, HasOpacity);
238  TEX_PARM(int32, HasEmission);
239  TEX_PARM(int32, HasNormal);
240  TEX_PARM(int32, HasRough);
241  TEX_PARM(int32, HasOcclusion);
242  TEX_PARM(int32, HasMetallic);
243  TEX_PARM(int32, HasCoatInt);
244  TEX_PARM(int32, HasCoatRough);
245  TEX_PARM(int32, HasReflectInt);
246  TEX_PARM(int32, HasDisplace);
247 
248  TEX_PARM(int32, HasDiffuseUV);
249  TEX_PARM(int32, HasSpecularUV);
250  TEX_PARM(int32, HasOpacityUV);
251  TEX_PARM(int32, HasEmissionUV);
252  TEX_PARM(int32, HasNormalUV);
253  TEX_PARM(int32, HasRoughUV);
254  TEX_PARM(int32, HasOcclusionUV);
255  TEX_PARM(int32, HasMetallicUV);
256  TEX_PARM(int32, HasCoatIntUV);
257  TEX_PARM(int32, HasCoatRoughUV);
258  TEX_PARM(int32, HasReflectIntUV);
259  TEX_PARM(int32, HasDisplaceUV);
260 
261  // Components
262  TEX_PARM(UT_Vector4F, RoughComp);
263  TEX_PARM(UT_Vector4F, OcclusionComp);
264  TEX_PARM(UT_Vector4F, MetallicComp);
265  TEX_PARM(UT_Vector4F, CoatIntComp);
266  TEX_PARM(UT_Vector4F, CoatRoughComp);
267  TEX_PARM(UT_Vector4F, OpacityComp);
268  TEX_PARM(UT_Vector4F, ReflectIntComp);
269 
270  // UDIM
271  TEX_PARM(UT_Vector4i, DiffuseUDIMArea);
272  TEX_PARM(UT_Vector4i, SpecularUDIMArea);
273  TEX_PARM(UT_Vector4i, OpacityUDIMArea);
274  TEX_PARM(UT_Vector4i, EmissionUDIMArea);
275  TEX_PARM(UT_Vector4i, NormalUDIMArea);
276  TEX_PARM(UT_Vector4i, RoughUDIMArea);
277  TEX_PARM(UT_Vector4i, OcclusionUDIMArea);
278  TEX_PARM(UT_Vector4i, MetallicUDIMArea);
279  TEX_PARM(UT_Vector4i, CoatIntUDIMArea);
280  TEX_PARM(UT_Vector4i, CoatRoughUDIMArea);
281  TEX_PARM(UT_Vector4i, ReflectIntUDIMArea);
282  TEX_PARM(UT_Vector4i, DisplaceUDIMArea);
283 
284  // Specific texture parms
285  // NORMAL
286  TEX_PARM(int32, NormalMapType);
287  TEX_PARM(UT_Vector2F, NormalMapScaleShift);
288  TEX_PARM(UT_Vector2F, NormalMapScale);
289  TEX_PARM(UT_Vector2F, NormalMapFlip);
290 
291  // DISPLACEMENT
292  TEX_PARM(int32, DisplaceSpace);
293  TEX_PARM(fpreal32, DisplaceScale);
294  TEX_PARM(fpreal32, DisplaceOffset);
295  TEX_PARM(fpreal32, DisplaceQuality);
296  TEX_PARM(int32, DisplaceYUp);
297 
298  TEX_PARM(int32, InvertOpacity );
299  TEX_PARM(int32, InvertRough );
300  TEX_PARM(int32, ReflectAsIOR);
301 
302  // Texture and UV wrapping
303  void setUVSet(const UT_StringRef &set) { myUVSet = set; }
304  const UT_StringHolder &getUVSet() const { return myUVSet; }
305 
306 #ifdef USE_VULKAN
307  void setTextureWrapU(RV_TextureWrap u) { myUWrap = u; }
308  RV_TextureWrap getTextureWrapU() const { return myUWrap; }
309 
310  void setTextureWrapV(RV_TextureWrap v) { myVWrap = v; }
311  RV_TextureWrap getTextureWrapV() const { return myVWrap; }
312 #endif
313 
314  // Update functions
315  void update(const GR_MaterialParms &options) override;
318  bool &created) override;
319  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
320 
321  void dirtyTextures() override { myTexDirtyFlag = true; dirty(true); }
322 
323 protected:
326 
327  friend class GR_Material;
328 private:
329  class TexturedBlock
330  {
331  public:
332  UT_Matrix4F DiffuseUV;
333  UT_Matrix4F SpecularUV;
334  UT_Matrix4F OpacityUV;
335  UT_Matrix4F EmissionUV;
336  UT_Matrix4F NormalUV;
337  UT_Matrix4F RoughUV;
338  UT_Matrix4F DisplaceUV;
339  UT_Matrix4F OcclusionUV;
340  UT_Matrix4F MetallicUV;
341  UT_Matrix4F CoatIntUV;
342  UT_Matrix4F CoatRoughUV;
343  UT_Matrix4F ReflectIntUV;
344 
345  UT_Vector4F RoughComp = {1.,0.,0.,0.};
346  UT_Vector4F OcclusionComp = {1.,0.,0.,0.};
347  UT_Vector4F MetallicComp = {1.,0.,0.,0.};
348  UT_Vector4F CoatIntComp = {1.,0.,0.,0.};
349  UT_Vector4F CoatRoughComp = {1.,0.,0.,0.};
350  UT_Vector4F OpacityComp = {1.,0.,0.,0.};
351  UT_Vector4F ReflectIntComp= {1.,0.,0.,0.};
352 
353  UT_Vector4i DiffuseUDIMArea = {0,0,0,0};
354  UT_Vector4i SpecularUDIMArea = {0,0,0,0};
355  UT_Vector4i OpacityUDIMArea = {0,0,0,0};
356  UT_Vector4i EmissionUDIMArea = {0,0,0,0};
357  UT_Vector4i NormalUDIMArea = {0,0,0,0};
358  UT_Vector4i RoughUDIMArea = {0,0,0,0};
359  UT_Vector4i DisplaceUDIMArea = {0,0,0,0};
360  UT_Vector4i OcclusionUDIMArea = {0,0,0,0};
361  UT_Vector4i MetallicUDIMArea = {0,0,0,0};
362  UT_Vector4i CoatIntUDIMArea = {0,0,0,0};
363  UT_Vector4i CoatRoughUDIMArea = {0,0,0,0};
364  UT_Vector4i ReflectIntUDIMArea = {0,0,0,0};
365 
366  UT_Vector2F NormalMapScaleShift = {1., 0.};
367  UT_Vector2F NormalMapScale = {1., 1.};
368  UT_Vector2F NormalMapFlip = {1., 1.};
369 
370  int32 HasDiffuse = false;
371  int32 HasSpecular = false;
372  int32 HasOpacity = false;
373  int32 HasEmission = false;
374  int32 HasNormal = false;
375  int32 HasRough = false;
376  int32 HasDisplace = false;
377  int32 HasOcclusion = false;
378  int32 HasMetallic = false;
379  int32 HasCoatInt = false;
380  int32 HasCoatRough = false;
381  int32 HasReflectInt = false;
382 
383  int32 HasDiffuseUV = false;
384  int32 HasSpecularUV = false;
385  int32 HasOpacityUV = false;
386  int32 HasEmissionUV = false;
387  int32 HasNormalUV = false;
388  int32 HasRoughUV = false;
389  int32 HasDisplaceUV = false;
390  int32 HasOcclusionUV = false;
391  int32 HasMetallicUV = false;
392  int32 HasCoatIntUV = false;
393  int32 HasCoatRoughUV = false;
394  int32 HasReflectIntUV = false;
395 
396  int32 NormalMapType = 0;
397 
398  int32 DisplaceSpace = 0;
399  fpreal32 DisplaceScale = 1.0;
400  fpreal32 DisplaceOffset = 0.0;
401  fpreal32 DisplaceQuality = 1.0;
402  int32 DisplaceYUp = true;
403 
404  int32 InvertOpacity = false;
405  int32 InvertRough = false;
406  int32 ReflectAsIOR = false;
407  } myTextureBlock;
408 
409  bool myTexDirtyFlag = true;
410  bool myTexBlockDirtyFlag = true;
411 
412  UT_StringHolder myUVSet;
413 #ifdef USE_VULKAN
416 
417  UT_UniquePtr<RV_ShaderBlock> myTextureMatBlock;
418 #endif
419 };
420 #undef TEX_PARM
421 
422 
423 
424 #define HAIR_PARM(TYPE, NAME) \
425  TYPE get##NAME() const { return myHairBlock.NAME; } \
426  void set##NAME(const TYPE &v) \
427  { if(myHairBlock.NAME != v) { myHairBlock.NAME=v; myBlockDirtyFlag=true; } } \
428  PARMKEY(NAME)
430 {
431 public:
432  struct Defaults {
433  static constexpr fpreal32 DiffIntensity = 0.5;
434  static constexpr UT_Vector3F DiffRootColor = {1.0, 1.0, 1.0};
435  static constexpr UT_Vector3F DiffTipColor = {1.0, 1.0, 1.0};
436  static constexpr int32 DiffUseBaseMap = 0;
437  static constexpr int32 DiffUseBlendRamp = 0;
438  static constexpr fpreal32 SpecIntensity = 0.2;
439  static constexpr fpreal32 SpecAngle = 0.0;
440  static constexpr UT_Vector3F SpecRootColor = {1.0, 1.0, 1.0};
441  static constexpr UT_Vector3F SpecTipColor = {1.0, 1.0, 1.0};
442  static constexpr fpreal32 SpecShift = 0.0;
443  static constexpr int32 SpecUseBaseMap = 0;
444  static constexpr int32 SpecUseBlendRamp = 0;
445  static constexpr fpreal32 HairAlpha = 1.0;
446  static constexpr int32 AlphaUseRamp = 0;
447  static constexpr int32 RandomDiffHue = 0;
448  static constexpr UT_Vector2F RandomDiffHueRange = {0.5, 1.0};
449  static constexpr int32 RandomDiffSat = 0;
450  static constexpr UT_Vector2F RandomDiffSatRange = {0.5, 1.0};
451  static constexpr int32 RandomDiffInt = 0;
452  static constexpr UT_Vector2F RandomDiffIntRange = {0.5, 1.0};
453  static constexpr int32 RandomSpecInt = 0;
454  static constexpr UT_Vector2F RandomSpecIntRange = {0.5, 1.0};
455  static constexpr fpreal32 Metal = 0.0;
456  static constexpr UT_Vector3F MetalColor = {1.0, 1.0, 1.0};
457  static constexpr UT_Vector4i DiffuseUDIMArea = {0,0,0,0};
458  static constexpr UT_Vector4i SpecularUDIMArea = {0,0,0,0};
459  static constexpr UT_Vector4i OpacityUDIMArea = {0,0,0,0};
460  static constexpr UT_Vector4i EmissionUDIMArea = {0,0,0,0};
461  };
462 
463  HAIR_PARM(fpreal32, DiffIntensity);
464  HAIR_PARM(UT_Vector3F, DiffRootColor);
465  HAIR_PARM(UT_Vector3F, DiffTipColor);
466 
467  HAIR_PARM(fpreal32, SpecIntensity);
468  HAIR_PARM(fpreal32, SpecAngle);
469  HAIR_PARM(UT_Vector3F, SpecRootColor);
470  HAIR_PARM(UT_Vector3F, SpecTipColor);
471  HAIR_PARM(fpreal32, SpecShift);
472 
473  HAIR_PARM(fpreal32, HairAlpha);
474 
475  HAIR_PARM(int32, RandomDiffHue);
476  HAIR_PARM(UT_Vector2F, RandomDiffHueRange);
477  HAIR_PARM(int32, RandomDiffSat);
478  HAIR_PARM(UT_Vector2F, RandomDiffSatRange);
479  HAIR_PARM(int32, RandomDiffInt);
480  HAIR_PARM(UT_Vector2F, RandomDiffIntRange);
481  HAIR_PARM(int32, RandomSpecInt);
482  HAIR_PARM(UT_Vector2F, RandomSpecIntRange);
483 
485  HAIR_PARM(UT_Vector3F, MetalColor);
486 
487  TEXMAP_PARM(DiffRootTipBlendMap, DiffRootTipBlendID);
488  TEXMAP_PARM(SpecRootTipBlendMap, SpecRootTipBlendID);
489  TEXMAP_PARM(AlphaRootTipBlendMap, AlphaRootTipBlendID);
490  TEXMAP_PARM(DiffuseMap, DiffuseID);
491  TEXMAP_PARM(OpacityMap, OpacityID);
492  TEXMAP_PARM(SpecularMap, SpecularID);
493  TEXMAP_PARM(EmissionMap, EmissionID);
494 
495  HAIR_PARM(int32, HasDiffRootTipBlend);
496  HAIR_PARM(int32, HasSpecRootTipBlend);
497  HAIR_PARM(int32, HasAlphaRootTipBlend);
498  HAIR_PARM(int32, HasDiffuse);
499  HAIR_PARM(int32, HasSpecular);
500 
501  HAIR_PARM(int32, HasDiffuseUV);
502  HAIR_PARM(int32, HasSpecularUV);
503 
504  HAIR_PARM(UT_Matrix4F, DiffuseUV);
505  HAIR_PARM(UT_Matrix4F, SpecularUV);
506 
507  HAIR_PARM(UT_Vector4i, DiffuseUDIMArea);
508  HAIR_PARM(UT_Vector4i, SpecularUDIMArea);
509 
510  void update(const GR_MaterialParms &options) override;
513  bool &created) override;
514  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
515 
516  void dirtyTextures() override { myTexDirtyFlag = true; }
517 
518 protected:
521 
522  friend class GR_Material;
523 private:
524  class HairBlock
525  {
526  public:
527  // reordered to minimise padding
528  SYS_ALIGN16 UT_Matrix4F DiffuseUV;
529  SYS_ALIGN16 UT_Matrix4F SpecularUV;
530 
531  SYS_ALIGN16 UT_Vector4i DiffuseUDIMArea = Defaults::DiffuseUDIMArea;
532  SYS_ALIGN16 UT_Vector4i SpecularUDIMArea = Defaults::SpecularUDIMArea;
533 
534  SYS_ALIGN16 UT_Vector3F DiffRootColor = Defaults::DiffRootColor;
535  SYS_ALIGN16 UT_Vector3F DiffTipColor = Defaults::DiffTipColor;
536  SYS_ALIGN16 UT_Vector3F SpecRootColor = Defaults::SpecRootColor;
537  SYS_ALIGN16 UT_Vector3F SpecTipColor = Defaults::SpecTipColor;
538 
539  UT_Vector2F RandomDiffHueRange =
540  Defaults::RandomDiffHueRange;
541  UT_Vector2F RandomDiffSatRange =
542  Defaults::RandomDiffSatRange;
543  UT_Vector2F RandomDiffIntRange =
544  Defaults::RandomDiffIntRange;
545  UT_Vector2F RandomSpecIntRange =
546  Defaults::RandomSpecIntRange;
547 
548  SYS_ALIGN16 UT_Vector3F MetalColor = Defaults::MetalColor;
549 
550  fpreal32 DiffIntensity = Defaults::DiffIntensity;
551 
552  fpreal32 SpecIntensity = Defaults::SpecIntensity;
553  fpreal32 SpecAngle = Defaults::SpecAngle;
554  fpreal32 SpecShift = Defaults::SpecShift;
555 
556  fpreal32 HairAlpha = Defaults::HairAlpha;
557 
558  int32 RandomDiffHue = Defaults::RandomDiffHue;
559  int32 RandomDiffSat = Defaults::RandomDiffSat;
560  int32 RandomDiffInt = Defaults::RandomDiffInt;
561  int32 RandomSpecInt = Defaults::RandomSpecInt;
562  fpreal32 Metal = Defaults::Metal;
563 
564  int32 HasDiffRootTipBlend = false;
565  int32 HasSpecRootTipBlend = false;
566  int32 HasAlphaRootTipBlend = false;
567  int32 HasDiffuse = false;
568  int32 HasSpecular = false;
569 
570  // are these necessary? why not just use an identity UV xform?
571  int32 HasDiffuseUV = false;
572  int32 HasSpecularUV = false;
573  } myHairBlock;
574 
575  bool myTexDirtyFlag = true;
576 
577 #ifdef USE_VULKAN
578  UT_UniquePtr<RV_ShaderBlock> myHairMatBlock;
579 #endif
580 };
581 
583 {
584 public:
585 
586  bool bindInt (const UT_StringRef &name, int32 value);
587  bool bindInts(const UT_StringRef &name, const UT_Array<int32> &values);
588 
589  bool bindFloat (const UT_StringRef &name, fpreal32 value);
590  bool bindFloats(const UT_StringRef &name, const UT_Array<fpreal32> &values);
591  bool bindFloat2(const UT_StringRef &name, const UT_Vector2D &value);
592  bool bindFloat3(const UT_StringRef &name, const UT_Vector3D &value);
593  bool bindFloat4(const UT_StringRef &name, const UT_Vector4D &value);
594  bool bindMatrix3(const UT_StringRef &name, const UT_Matrix3D &value);
595  bool bindMatrix4(const UT_StringRef &name, const UT_Matrix4D &value);
596 
597  bool bindTexture(const UT_StringRef &name,
598  const UT_StringRef &map_path,
599  bool is_color,
600  const UT_Vector4F &fallback_color,
601  const RV_TextureParms *tex_parms = nullptr);
602 
603  void enableLighting(bool enable)
604  {
605  if(enable != myEnableLighting)
606  {
607  myEnableLighting = enable;
608  myBlockDirtyFlag = true;
609  }
610  }
611 
613  {
614  if (id != mySurfShaderID) { resetResources(); }
615  mySurfShaderID = id;
616  }
617 
619  { if (id != mySurfShaderID) { resetResources(); }
620  myCurveShaderID = id; }
621 
622 #ifdef USE_VULKAN
623  RV_ShaderProgram *getSurfaceShader() const override;
624  RV_ShaderProgram *getCurveShader() const override;
625 #endif
626 
627  void update(const GR_MaterialParms &options) override;
630  bool &created) override;
631  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
632 
634  { myCachedName = std::move(name); }
635  const UT_StringHolder &cachedName() const { return myCachedName; }
636 
638  {
639  if (myCachedName.isEmpty())
640  return;
641  name.format("{}?curve", myCachedName);
642  }
643 
644  void setShaderDirty(bool dirty) { myShaderDirty = dirty; }
645  bool isShaderDirty() const { return myShaderDirty; }
646 
647  void setMatXNodeVersion(int64 version) { myMatXVersion = version; }
648  int64 getMatXNodeVersion() const { return myMatXVersion; }
649 
650  void dirtyTextures() override { myTexturesDirty = true; }
651 
652  void setShaderCompiled(bool comp) { myShaderCompiled = comp; }
653  bool isShaderCompiled() const { return myShaderCompiled; }
654 
655  void setSurfShaderAssigned(bool comp) { mySurfShaderAssigned = comp; }
656  bool isSurfShaderAssigned() const { return mySurfShaderAssigned; }
657 
658  void setCurveShaderAssigned(bool comp) { myCurveShaderAssigned = comp; }
659  bool isCurveShaderAssigned() const { return myCurveShaderAssigned; }
660 
661 protected:
662  GR_MatXMaterial(const UT_StringHolder &name);
663  ~GR_MatXMaterial() override;
664 
666 
667  friend class GR_Material;
668 
669  void resetResources();
670 
671 private:
672  UT_StringHolder myCachedName;
673  bool myShaderDirty = true;
674  bool myTexturesDirty = true;
675  bool myEnableLighting = true;
676  bool myBadShader = false;
677  bool myShaderCompiled = true;
678  bool mySurfShaderAssigned = false;
679  bool myCurveShaderAssigned = false;
680  exint myMatXVersion = 0;
681  struct TextureDef
682  {
684  bool is_color = true;
685  UT_Vector4F fallback = { 1.,1.,1.,1.};
686 #ifdef USE_VULKAN
687  RV_TextureParms tex_parms = RV_TextureParms();
688 #endif
689  };
690  UT_StringMap<TextureDef> myTextures;
691 #ifdef USE_VULKAN
692  void bindTextures(RV_Render *r,
694  const GR_DisplayOption *opts);
695 
698  UT_UniquePtr<RV_ShaderBlock> myFragUniformBlock;
699  UT_UniquePtr<RV_ShaderBlock> myTessUniformBlock;
700  UT_StringMap<RV_TextureRef> myTextureRefs;
701 #endif
702 
703  exint mySurfShaderID=0;
704  exint myCurveShaderID=0;
705 };
706 
707 #define LAYER_INST(NAME, TYPE) \
708 TYPE get##NAME(int idx) const { return myLayer.layer[idx].NAME; } \
709 void set##NAME(int idx, const TYPE &v) \
710 { if(myLayer.layer[idx].NAME != v) { myLayer.layer[idx].NAME=v; myLayerDirtyFlag=true; } } \
711  PARMKEY(NAME)
712 
713 
714 #define LAYER_PARM(NAME, TYPE) \
715  TYPE get##NAME() const { return myLayer.NAME; } \
716  void set##NAME(const TYPE &v) \
717  { if(myLayer.NAME != v) { myLayer.NAME=v; myLayerDirtyFlag=true; } } \
718  PARMKEY(NAME)
719 
721 {
722 public:
723  void updateDisplaceMap(RV_Render *r,
724  GT_DataArray *disp,
725  UT_Vector2i res);
726  void updateNormalMap(RV_Render *r,
727  GT_DataArray *nml,
728  UT_Vector2i res);
729  void updateColorMap(RV_Render *r,
731  UT_Vector2i res);
732  void updateBlendMap(RV_Render *r,
734  UT_Vector2i res);
735 
736  TEXMAP_PARM(RoughMap, RoughID);
737  TEXMAP_PARM(SpecularMap, SpecularID);
738  TEXMAP_PARM(EmissionMap, EmissionID);
739  TEXMAP_PARM(Layer1Map, Layer1ID);
740  TEXMAP_PARM(Layer2Map, Layer2ID);
741  TEXMAP_PARM(Layer3Map, Layer3ID);
742  TEXMAP_PARM(Layer4Map, Layer4ID);
743  TEXMAP_PARM(Layer5Map, Layer5ID);
744  TEXMAP_PARM(Layer6Map, Layer6ID);
745  TEXMAP_PARM(Layer7Map, Layer7ID);
746  TEXMAP_PARM(Layer8Map, Layer8ID);
747  TEXMAP_PARM(Layer9Map, Layer9ID);
748  TEXMAP_PARM(Layer10Map, Layer10ID);
749 
750  LAYER_PARM(Diff, UT_Vector3F);
751  LAYER_PARM(Spec, UT_Vector3F);
752  LAYER_PARM(SpecRough, fpreal32);
753  LAYER_PARM(SpecModel, int32);
755  LAYER_PARM(NumUVSets, int32);
756  LAYER_PARM(UseBlendMap, int32);
757  LAYER_PARM(HasTriplanar, int32);
758 
759  LAYER_INST(UVTransform, UT_Matrix4F);
760  LAYER_INST(Tint, UT_Vector4F);
761  LAYER_INST(TriplanarBlend, UT_Vector3F);
762  LAYER_INST(TriplanarOffset, UT_Vector3F);
763  LAYER_INST(TriplanarScale, fpreal32);
764  LAYER_INST(TriplanarSharp, fpreal32);
765  LAYER_INST(Rough, fpreal32);
766  LAYER_INST(UseTint, int32);
767  LAYER_INST(HasMap, int32);
768  LAYER_INST(UseTriplanar, int32);
769 
770  PARMKEY(ClampToEdge);
771 
772  void update(const GR_MaterialParms &options) override;
775  bool &created) override;
776  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
777 
778 protected:
781 
782  friend class GR_Material;
783 private:
784  struct Layer
785  {
786  UT_Matrix4F UVTransform;
787  UT_Vector4F Tint = { 1,1,1,1};
788  UT_Vector3F TriplanarBlend = {1,1,1};
789  fpreal32 dummy1 = 0.0;
790  UT_Vector3F TriplanarOffset = {0,0,0};
791  fpreal32 TriplanarScale = 1.0;
792  fpreal32 TriplanarSharp = 1.0;
793  fpreal32 Rough = 0.0;
794  int32 UseTint = true;
795  int32 HasMap = false;
796  int32 UseTriplanar = false;
797  UT_Vector3F dummy2 = {0,0,0};
798  }; // padded to 144B
799 
800  class HFLayers
801  {
802  public:
803  UT_Vector3F Diff = {0.5,0.5,0.5};
804  fpreal32 SpecRough = 0.0;
805  UT_Vector3F Spec = {0.3, 0.3, 0.3};
806  int32 SpecModel = 2; // GGX
807  fpreal32 Quality = 1.0;
808  int32 NumUVSets = 1;
809  int32 UseBlendMap = false;
810  int32 HasTriplanar = false;
811  Layer layer[10];
812  } myLayer;
813 
814 
815  bool myTexDirtyFlag = true;
816  bool myLayerDirtyFlag = true;
817  int64 myDisplaceVersion = 0;
818  int64 myNormalVersion = 0;
819  int64 myColorVersion = 0;
820  int64 myBlendVersion = 0;
821  bool myClampToEdge[10];
822 #ifdef USE_VULKAN
823  UT_UniquePtr<RV_VKImage> myDisplaceMap;
824  UT_UniquePtr<RV_VKImage> myNormalMap;
825  UT_UniquePtr<RV_VKImage> myColorMap;
826  UT_UniquePtr<RV_VKImage> myBlendMap;
827  UT_UniquePtr<RV_ShaderBlock> myLayerBlock;
828 #endif
829 };
830 
831 #undef TEXMAP_PARM
832 #undef TEXMAP_PARM_VK
833 #undef PARMKEY
834 
835 #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)
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 makeCachedCurveName(UT_WorkBuffer name) const
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)
#define GR_API
Definition: GR_API.h:10
RV_TextureWrap
Definition: RV_Type.h:141
#define SYS_ALIGN16
Definition: SYS_Align.h:100
long long int64
Definition: SYS_Types.h:116
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
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
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
exint id() const
Definition: GR_SceneItem.h:24