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 #endif
19 
20 #include <RE/RE_Material.h>
21 #include <SYS/SYS_Align.h>
22 #include <UT/UT_StringHolder.h>
23 #include <UT/UT_StringMap.h>
24 #include <UT/UT_Matrix4.h>
25 #include <UT/UT_UniquePtr.h>
26 #include <UT/UT_VectorTypes.h>
27 #include <UT/UT_Vector2.h>
28 #include <UT/UT_Vector3.h>
29 
30 class RV_ShaderProgram;
32 class RV_ShaderBlock;
33 class RV_VKImage;
34 class GT_DataArray;
35 
36 #define PARMKEY(NAME) static exint NAME();
37 
38 #define MATPARM(TYPE, NAME) \
39  TYPE get##NAME() const { return mySimpleBlock.NAME; } \
40  void set##NAME(const TYPE &v) \
41  { if(mySimpleBlock.NAME != v) { mySimpleBlock.NAME=v; myBlockDirtyFlag=true; } } \
42  PARMKEY(NAME)
43 
44 ///
46 {
47 public:
48  // setPARM() / getPARM()
49  MATPARM(UT_Vector3F, Diff);
50  MATPARM(UT_Vector3F, Spec);
51  MATPARM(UT_Vector3F, Emit);
52  MATPARM(UT_Vector3F, MetalColor);
53  MATPARM(UT_Vector3F, SheenColor);
54  MATPARM(fpreal32, DiffRough);
55  MATPARM(fpreal32, SpecRough);
56  MATPARM(fpreal32, SpecTint);
57  MATPARM(fpreal32, Metal);
58  MATPARM(fpreal32, IOR);
60  MATPARM(fpreal32, AlphaPara);
61  MATPARM(fpreal32, AlphaCutoff);
63  MATPARM(fpreal32, CoatIntensity);
64  MATPARM(fpreal32, CoatRough);
65  MATPARM(fpreal32, SheenIntensity);
66  MATPARM(fpreal32, SheenRough);
67  MATPARM(int32, SpecModel);
68  MATPARM(int32, CoatSpecModel);
69  MATPARM(int32, UseGeoColor);
70  MATPARM(int32, UsePackedColor);
71  MATPARM(int32, HasTextures);
72 
73  void update(const GR_MaterialParms &options) override;
76  bool &created) override;
77  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
78 
79 protected:
81  MaterialType type = SIMPLE_SURFACE);
83 
84  friend class GR_Material;
85 
86 private:
87  struct SimpleMaterialBlock
88  {
89  // Not using explicit padding (SYS_ALIGN16) on the Vector3 fields
90  // because then sizeof(SimpleMaterialBlock) would report a size that
91  // includes the "padding required to place such an object in an array",
92  // which disagrees with the size determined by SPIR-V reflection.
93  // https://en.cppreference.com/w/cpp/language/sizeof
94  UT_Vector3F Diff = { 1.0, 1.0, 1.0 };
95  fpreal32 Padding0;
96  UT_Vector3F Spec = { 1.0, 1.0, 1.0 };
97  fpreal32 Padding1;
98  UT_Vector3F Emit = { 0.0, 0.0, 0.0 };
99  fpreal32 Padding2;
100  UT_Vector3F MetalColor = { 1.0, 1.0, 1.0 };
101  fpreal32 Padding3;
102  UT_Vector3F SheenColor = { 1.0, 1.0, 1.0 };
103 
104  fpreal32 DiffRough = 0.5;
105  fpreal32 SpecRough = 0.3;
106  fpreal32 SpecTint = 1.0;
107  fpreal32 Metal = 0.0;
108  fpreal32 IOR = 1.33;
109  fpreal32 Alpha = 1.0;
110  fpreal32 AlphaPara = 1.0;
111  fpreal32 AlphaCutoff = 0.0;
112  int32 AlphaMode = ALPHA_BLEND;
113  fpreal32 CoatIntensity = 0.0;
114  fpreal32 CoatRough = 0.1;
115  fpreal32 SheenIntensity = 0.0;
116  fpreal32 SheenRough = 0.1;
117  int32 SpecModel = 2;
118  int32 CoatSpecModel = 2;
119  int32 UseGeoColor = 1;
120  int32 UsePackedColor = 1;
121  int32 HasTextures = 0;
122  } mySimpleBlock;
123 #ifdef USE_VULKAN
124  UT_UniquePtr<RV_ShaderBlock> mySimpleMatBlock;
125 #endif
126 };
127 #undef MATPARM
128 
129 // Film Material ------------------------------------------------------------
130 
131 #define TEX_PARM(TYPE, NAME) \
132  TYPE get##NAME() const { return myTextureBlock.NAME; } \
133  void set##NAME(const TYPE &v) \
134  { if(myTextureBlock.NAME != v) \
135  { myTextureBlock.NAME=v; myTexBlockDirtyFlag=true; } \
136  } \
137  PARMKEY(NAME)
138 
139 #ifdef USE_VULKAN
140 #define TEXMAP_PARM(NAME, MAP) \
141  UT_StringHolder get##NAME() const { return my##NAME; } \
142  void set##NAME(const UT_StringHolder &v) \
143  { if(my##NAME != v) { my##NAME=v; my##MAP.reset(); myTexDirtyFlag=true; } } \
144  void set##NAME##Fallback(const UT_Vector4F &f) \
145  { if(my##NAME##Fallback!=f) { my##NAME##Fallback=f; myTexDirtyFlag=true; }} \
146  PARMKEY(NAME); \
147  UT_StringHolder my##NAME; \
148  UT_Vector4F my##NAME##Fallback; \
149  RV_TextureRef my##MAP
150 #else
151 #define TEXMAP_PARM(NAME, MAP) \
152  UT_StringHolder get##NAME() const { return my##NAME; } \
153  void set##NAME(const UT_StringHolder &v) \
154  { if(my##NAME != v) { my##NAME=v; myTexDirtyFlag=true; } } \
155  void set##NAME##Fallback(const UT_Vector4F &f) \
156  { if(my##NAME##Fallback!=f) { my##NAME##Fallback=f; myTexDirtyFlag=true; }} \
157  PARMKEY(NAME); \
158  UT_Vector4F my##NAME##Fallback; \
159  UT_StringHolder my##NAME
160 #endif
161 
163 {
164 public:
165  TEXMAP_PARM(DiffuseMap, DiffuseID);
166  TEXMAP_PARM(OpacityMap, OpacityID);
167  TEXMAP_PARM(SpecularMap, SpecularID);
168  TEXMAP_PARM(EmissionMap, EmissionID);
169  TEXMAP_PARM(NormalMap, NormalID);
170  TEXMAP_PARM(RoughMap, RoughID);
171  TEXMAP_PARM(OcclusionMap, OcclusionID);
172  TEXMAP_PARM(MetallicMap, MetallicID);
173  TEXMAP_PARM(CoatIntMap, CoatIntID);
174  TEXMAP_PARM(CoatRoughMap, CoatRoughID);
175  TEXMAP_PARM(ReflectIntMap, ReflectIntID);
176  TEXMAP_PARM(DisplaceMap, DisplaceID);
177 
178  TEX_PARM(UT_Matrix4F, DiffuseUV);
179  TEX_PARM(UT_Matrix4F, SpecularUV);
180  TEX_PARM(UT_Matrix4F, OpacityUV);
181  TEX_PARM(UT_Matrix4F, EmissionUV);
182  TEX_PARM(UT_Matrix4F, NormalUV);
183  TEX_PARM(UT_Matrix4F, RoughUV);
184  TEX_PARM(UT_Matrix4F, OcclusionUV);
185  TEX_PARM(UT_Matrix4F, MetallicUV);
186  TEX_PARM(UT_Matrix4F, CoatIntUV);
187  TEX_PARM(UT_Matrix4F, CoatRoughUV);
188  TEX_PARM(UT_Matrix4F, ReflectIntUV);
189  TEX_PARM(UT_Matrix4F, DisplaceUV);
190 
191  TEX_PARM(int32, HasDiffuse);
192  TEX_PARM(int32, HasSpecular);
193  TEX_PARM(int32, HasOpacity);
194  TEX_PARM(int32, HasEmission);
195  TEX_PARM(int32, HasNormal);
196  TEX_PARM(int32, HasRough);
197  TEX_PARM(int32, HasOcclusion);
198  TEX_PARM(int32, HasMetallic);
199  TEX_PARM(int32, HasCoatInt);
200  TEX_PARM(int32, HasCoatRough);
201  TEX_PARM(int32, HasReflectInt);
202  TEX_PARM(int32, HasDisplace);
203 
204  TEX_PARM(int32, HasDiffuseUV);
205  TEX_PARM(int32, HasSpecularUV);
206  TEX_PARM(int32, HasOpacityUV);
207  TEX_PARM(int32, HasEmissionUV);
208  TEX_PARM(int32, HasNormalUV);
209  TEX_PARM(int32, HasRoughUV);
210  TEX_PARM(int32, HasOcclusionUV);
211  TEX_PARM(int32, HasMetallicUV);
212  TEX_PARM(int32, HasCoatIntUV);
213  TEX_PARM(int32, HasCoatRoughUV);
214  TEX_PARM(int32, HasReflectIntUV);
215  TEX_PARM(int32, HasDisplaceUV);
216 
217  // Components
218  TEX_PARM(UT_Vector4F, RoughComp);
219  TEX_PARM(UT_Vector4F, OcclusionComp);
220  TEX_PARM(UT_Vector4F, MetallicComp);
221  TEX_PARM(UT_Vector4F, CoatIntComp);
222  TEX_PARM(UT_Vector4F, CoatRoughComp);
223  TEX_PARM(UT_Vector4F, OpacityComp);
224  TEX_PARM(UT_Vector4F, ReflectIntComp);
225 
226  // UDIM
227  TEX_PARM(UT_Vector4i, DiffuseUDIMArea);
228  TEX_PARM(UT_Vector4i, SpecularUDIMArea);
229  TEX_PARM(UT_Vector4i, OpacityUDIMArea);
230  TEX_PARM(UT_Vector4i, EmissionUDIMArea);
231  TEX_PARM(UT_Vector4i, NormalUDIMArea);
232  TEX_PARM(UT_Vector4i, RoughUDIMArea);
233  TEX_PARM(UT_Vector4i, OcclusionUDIMArea);
234  TEX_PARM(UT_Vector4i, MetallicUDIMArea);
235  TEX_PARM(UT_Vector4i, CoatIntUDIMArea);
236  TEX_PARM(UT_Vector4i, CoatRoughUDIMArea);
237  TEX_PARM(UT_Vector4i, ReflectIntUDIMArea);
238  TEX_PARM(UT_Vector4i, DisplaceUDIMArea);
239 
240  // Specific texture parms
241  // NORMAL
242  TEX_PARM(int32, NormalMapType);
243  TEX_PARM(UT_Vector2F, NormalMapScaleShift);
244  TEX_PARM(UT_Vector2F, NormalMapScale);
245  TEX_PARM(UT_Vector2F, NormalMapFlip);
246 
247  // DISPLACEMENT
248  TEX_PARM(int32, DisplaceSpace);
249  TEX_PARM(fpreal32, DisplaceScale);
250  TEX_PARM(fpreal32, DisplaceOffset);
251  TEX_PARM(fpreal32, DisplaceQuality);
252  TEX_PARM(int32, DisplaceYUp);
253 
254  TEX_PARM(int32, InvertOpacity );
255  TEX_PARM(int32, UseMatCap);
256  TEX_PARM(int32, InvertRough );
257  TEX_PARM(int32, ReflectAsIOR);
258 
259  void update(const GR_MaterialParms &options) override;
262  bool &created) override;
263  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
264 
265 protected:
268 
269  friend class GR_Material;
270 private:
271  class TexturedBlock
272  {
273  public:
274  SYS_ALIGN16 UT_Matrix4F DiffuseUV;
275  SYS_ALIGN16 UT_Matrix4F SpecularUV;
276  SYS_ALIGN16 UT_Matrix4F OpacityUV;
277  SYS_ALIGN16 UT_Matrix4F EmissionUV;
278  SYS_ALIGN16 UT_Matrix4F NormalUV;
279  SYS_ALIGN16 UT_Matrix4F RoughUV;
280  SYS_ALIGN16 UT_Matrix4F DisplaceUV;
281  SYS_ALIGN16 UT_Matrix4F OcclusionUV;
282  SYS_ALIGN16 UT_Matrix4F MetallicUV;
283  SYS_ALIGN16 UT_Matrix4F CoatIntUV;
284  SYS_ALIGN16 UT_Matrix4F CoatRoughUV;
285  SYS_ALIGN16 UT_Matrix4F ReflectIntUV;
286 
287  UT_Vector4F RoughComp = {1.,0.,0.,0.};
288  UT_Vector4F OcclusionComp = {1.,0.,0.,0.};
289  UT_Vector4F MetallicComp = {1.,0.,0.,0.};
290  UT_Vector4F CoatIntComp = {1.,0.,0.,0.};
291  UT_Vector4F CoatRoughComp = {1.,0.,0.,0.};
292  UT_Vector4F OpacityComp = {1.,0.,0.,0.};
293  UT_Vector4F ReflectIntComp= {1.,0.,0.,0.};
294 
295  UT_Vector4i DiffuseUDIMArea = {0,0,0,0};
296  UT_Vector4i SpecularUDIMArea = {0,0,0,0};
297  UT_Vector4i OpacityUDIMArea = {0,0,0,0};
298  UT_Vector4i EmissionUDIMArea = {0,0,0,0};
299  UT_Vector4i NormalUDIMArea = {0,0,0,0};
300  UT_Vector4i RoughUDIMArea = {0,0,0,0};
301  UT_Vector4i DisplaceUDIMArea = {0,0,0,0};
302  UT_Vector4i OcclusionUDIMArea = {0,0,0,0};
303  UT_Vector4i MetallicUDIMArea = {0,0,0,0};
304  UT_Vector4i CoatIntUDIMArea = {0,0,0,0};
305  UT_Vector4i CoatRoughUDIMArea = {0,0,0,0};
306  UT_Vector4i ReflectIntUDIMArea = {0,0,0,0};
307 
308  UT_Vector2F NormalMapScaleShift = {1., 0.};
309  UT_Vector2F NormalMapScale = {1., 1.};
310  UT_Vector2F NormalMapFlip = {1., 1.};
311 
312  int32 HasDiffuse = false;
313  int32 HasSpecular = false;
314  int32 HasOpacity = false;
315  int32 HasEmission = false;
316  int32 HasNormal = false;
317  int32 HasRough = false;
318  int32 HasDisplace = false;
319  int32 HasOcclusion = false;
320  int32 HasMetallic = false;
321  int32 HasCoatInt = false;
322  int32 HasCoatRough = false;
323  int32 HasReflectInt = false;
324 
325  int32 HasDiffuseUV = false;
326  int32 HasSpecularUV = false;
327  int32 HasOpacityUV = false;
328  int32 HasEmissionUV = false;
329  int32 HasNormalUV = false;
330  int32 HasRoughUV = false;
331  int32 HasDisplaceUV = false;
332  int32 HasOcclusionUV = false;
333  int32 HasMetallicUV = false;
334  int32 HasCoatIntUV = false;
335  int32 HasCoatRoughUV = false;
336  int32 HasReflectIntUV = false;
337 
338  int32 NormalMapType = 0;
339 
340  int32 DisplaceSpace = 0;
341  fpreal32 DisplaceScale = 1.0;
342  fpreal32 DisplaceOffset = 0.0;
343  fpreal32 DisplaceQuality = 1.0;
344  int32 DisplaceYUp = true;
345 
346  int32 InvertOpacity = false;
347  int32 UseMatCap = false;
348  int32 InvertRough = false;
349  int32 ReflectAsIOR= false;
350  } myTextureBlock;
351 
352  bool myTexDirtyFlag = true;
353  bool myTexBlockDirtyFlag = true;
354 
355 #ifdef USE_VULKAN
356  UT_UniquePtr<RV_ShaderBlock> myTextureMatBlock;
357 #endif
358 };
359 #undef TEX_PARM
360 
361 #define HAIR_PARM(TYPE, NAME) \
362  TYPE get##NAME() const { return myHairBlock.NAME; } \
363  void set##NAME(const TYPE &v) \
364  { if(myHairBlock.NAME != v) { myHairBlock.NAME=v; myBlockDirtyFlag=true; } } \
365  PARMKEY(NAME)
367 {
368 public:
369  struct Defaults {
370  static constexpr fpreal32 DiffIntensity = 0.5;
371  static constexpr UT_Vector3F DiffRootColor = {1.0, 1.0, 1.0};
372  static constexpr UT_Vector3F DiffTipColor = {1.0, 1.0, 1.0};
373  static constexpr int32 DiffUseBaseMap = 0;
374  static constexpr int32 DiffUseBlendRamp = 0;
375  static constexpr fpreal32 SpecIntensity = 0.2;
376  static constexpr fpreal32 SpecAngle = 0.0;
377  static constexpr UT_Vector3F SpecRootColor = {1.0, 1.0, 1.0};
378  static constexpr UT_Vector3F SpecTipColor = {1.0, 1.0, 1.0};
379  static constexpr fpreal32 SpecShift = 0.0;
380  static constexpr int32 SpecUseBaseMap = 0;
381  static constexpr int32 SpecUseBlendRamp = 0;
382  static constexpr fpreal32 HairAlpha = 1.0;
383  static constexpr int32 AlphaUseRamp = 0;
384  static constexpr int32 RandomDiffHue = 0;
385  static constexpr UT_Vector2F RandomDiffHueRange = {0.5, 1.0};
386  static constexpr int32 RandomDiffSat = 0;
387  static constexpr UT_Vector2F RandomDiffSatRange = {0.5, 1.0};
388  static constexpr int32 RandomDiffInt = 0;
389  static constexpr UT_Vector2F RandomDiffIntRange = {0.5, 1.0};
390  static constexpr int32 RandomSpecInt = 0;
391  static constexpr UT_Vector2F RandomSpecIntRange = {0.5, 1.0};
392  static constexpr fpreal32 Metal = 0.0;
393  static constexpr UT_Vector3F MetalColor = {1.0, 1.0, 1.0};
394  static constexpr UT_Vector4i DiffuseUDIMArea = {0,0,0,0};
395  static constexpr UT_Vector4i SpecularUDIMArea = {0,0,0,0};
396  static constexpr UT_Vector4i OpacityUDIMArea = {0,0,0,0};
397  static constexpr UT_Vector4i EmissionUDIMArea = {0,0,0,0};
398  };
399 
400  HAIR_PARM(fpreal32, DiffIntensity);
401  HAIR_PARM(UT_Vector3F, DiffRootColor);
402  HAIR_PARM(UT_Vector3F, DiffTipColor);
403 
404  HAIR_PARM(fpreal32, SpecIntensity);
405  HAIR_PARM(fpreal32, SpecAngle);
406  HAIR_PARM(UT_Vector3F, SpecRootColor);
407  HAIR_PARM(UT_Vector3F, SpecTipColor);
408  HAIR_PARM(fpreal32, SpecShift);
409 
410  HAIR_PARM(fpreal32, HairAlpha);
411 
412  HAIR_PARM(int32, RandomDiffHue);
413  HAIR_PARM(UT_Vector2F, RandomDiffHueRange);
414  HAIR_PARM(int32, RandomDiffSat);
415  HAIR_PARM(UT_Vector2F, RandomDiffSatRange);
416  HAIR_PARM(int32, RandomDiffInt);
417  HAIR_PARM(UT_Vector2F, RandomDiffIntRange);
418  HAIR_PARM(int32, RandomSpecInt);
419  HAIR_PARM(UT_Vector2F, RandomSpecIntRange);
420 
421  HAIR_PARM(fpreal32, Metal);
422  HAIR_PARM(UT_Vector3F, MetalColor);
423 
424  TEXMAP_PARM(DiffRootTipBlendMap, DiffRootTipBlendID);
425  TEXMAP_PARM(SpecRootTipBlendMap, SpecRootTipBlendID);
426  TEXMAP_PARM(AlphaRootTipBlendMap, AlphaRootTipBlendID);
427  TEXMAP_PARM(DiffuseMap, DiffuseID);
428  TEXMAP_PARM(OpacityMap, OpacityID);
429  TEXMAP_PARM(SpecularMap, SpecularID);
430  TEXMAP_PARM(EmissionMap, EmissionID);
431 
432  HAIR_PARM(int32, HasDiffRootTipBlend);
433  HAIR_PARM(int32, HasSpecRootTipBlend);
434  HAIR_PARM(int32, HasAlphaRootTipBlend);
435  HAIR_PARM(int32, HasDiffuse);
436  HAIR_PARM(int32, HasSpecular);
437 
438  HAIR_PARM(int32, HasDiffuseUV);
439  HAIR_PARM(int32, HasSpecularUV);
440 
441  HAIR_PARM(UT_Matrix4F, DiffuseUV);
442  HAIR_PARM(UT_Matrix4F, SpecularUV);
443 
444  HAIR_PARM(UT_Vector4i, DiffuseUDIMArea);
445  HAIR_PARM(UT_Vector4i, SpecularUDIMArea);
446 
447  void update(const GR_MaterialParms &options) override;
450  bool &created) override;
451  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
452 
453 protected:
456 
457  friend class GR_Material;
458 private:
459  class HairBlock
460  {
461  public:
462  // reordered to minimise padding
463  SYS_ALIGN16 UT_Matrix4F DiffuseUV;
464  SYS_ALIGN16 UT_Matrix4F SpecularUV;
465 
466  SYS_ALIGN16 UT_Vector4i DiffuseUDIMArea = Defaults::DiffuseUDIMArea;
467  SYS_ALIGN16 UT_Vector4i SpecularUDIMArea = Defaults::SpecularUDIMArea;
468 
469  SYS_ALIGN16 UT_Vector3F DiffRootColor = Defaults::DiffRootColor;
470  SYS_ALIGN16 UT_Vector3F DiffTipColor = Defaults::DiffTipColor;
471  SYS_ALIGN16 UT_Vector3F SpecRootColor = Defaults::SpecRootColor;
472  SYS_ALIGN16 UT_Vector3F SpecTipColor = Defaults::SpecTipColor;
473 
474  UT_Vector2F RandomDiffHueRange =
475  Defaults::RandomDiffHueRange;
476  UT_Vector2F RandomDiffSatRange =
477  Defaults::RandomDiffSatRange;
478  UT_Vector2F RandomDiffIntRange =
479  Defaults::RandomDiffIntRange;
480  UT_Vector2F RandomSpecIntRange =
481  Defaults::RandomSpecIntRange;
482 
483  SYS_ALIGN16 UT_Vector3F MetalColor = Defaults::MetalColor;
484 
485  fpreal32 DiffIntensity = Defaults::DiffIntensity;
486 
487  fpreal32 SpecIntensity = Defaults::SpecIntensity;
488  fpreal32 SpecAngle = Defaults::SpecAngle;
489  fpreal32 SpecShift = Defaults::SpecShift;
490 
491  fpreal32 HairAlpha = Defaults::HairAlpha;
492 
493  int32 RandomDiffHue = Defaults::RandomDiffHue;
494  int32 RandomDiffSat = Defaults::RandomDiffSat;
495  int32 RandomDiffInt = Defaults::RandomDiffInt;
496  int32 RandomSpecInt = Defaults::RandomSpecInt;
497  fpreal32 Metal = Defaults::Metal;
498 
499  int32 HasDiffRootTipBlend = false;
500  int32 HasSpecRootTipBlend = false;
501  int32 HasAlphaRootTipBlend = false;
502  int32 HasDiffuse = false;
503  int32 HasSpecular = false;
504 
505  // are these necessary? why not just use an identity UV xform?
506  int32 HasDiffuseUV = false;
507  int32 HasSpecularUV = false;
508  } myHairBlock;
509 
510  bool myTexDirtyFlag = true;
511 
512 #ifdef USE_VULKAN
513  UT_UniquePtr<RV_ShaderBlock> myHairMatBlock;
514 #endif
515 };
516 
518 {
519 public:
520 
521  bool bindInt (const UT_StringRef &name, int32 value);
522  bool bindInts(const UT_StringRef &name, const UT_Array<int32> &values);
523 
524  bool bindFloat (const UT_StringRef &name, fpreal32 value);
525  bool bindFloats(const UT_StringRef &name, const UT_Array<fpreal32> &values);
526  bool bindFloat2(const UT_StringRef &name, const UT_Vector2D &value);
527  bool bindFloat3(const UT_StringRef &name, const UT_Vector3D &value);
528  bool bindFloat4(const UT_StringRef &name, const UT_Vector4D &value);
529  bool bindMatrix3(const UT_StringRef &name, const UT_Matrix3D &value);
530  bool bindMatrix4(const UT_StringRef &name, const UT_Matrix4D &value);
531 
532  bool bindTexture(const UT_StringRef &name,
533  const UT_StringRef &map_path,
534  bool is_color,
535  const UT_Vector4F &fallback_color);
536 
537  void enableLighting(bool enable)
538  {
539  if(enable != myEnableLighting)
540  {
541  myEnableLighting = enable;
542  myBlockDirtyFlag = true;
543  }
544  }
545 
547  { mySurfShaderID = id; }
548 
550  { myCurveShaderID = id; }
551 
552 #ifdef USE_VULKAN
553  RV_ShaderProgram *getSurfaceShader() const override;
554  RV_ShaderProgram *getCurveShader() const override;
555 #endif
556 
557  void update(const GR_MaterialParms &options) override;
560  bool &created) override;
561  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
562 
564  { myCachedName = std::move(name); }
565  const UT_StringHolder &cachedName() const { return myCachedName; }
566 
567  void setShaderDirty(bool dirty) { myShaderDirty = dirty; }
568  bool isShaderDirty() const { return myShaderDirty; }
569 
570  void setMatXNodeVersion(int64 version) { myMatXVersion = version; }
571  int64 getMatXNodeVersion() const { return myMatXVersion; }
572 
573  void setShaderCompiled(bool comp) { myShaderCompiled = comp; }
574 
575 protected:
576  GR_MatXMaterial(const UT_StringHolder &name);
578 
579  friend class GR_Material;
580 
581 private:
582  UT_StringHolder myCachedName;
583  bool myShaderDirty = true;
584  bool myTexturesDirty = true;
585  bool myEnableLighting = true;
586  bool myBadShader = false;
587  bool myShaderCompiled = true;
588  exint myMatXVersion = 0;
589  struct TextureDef
590  {
592  bool is_color = true;
593  UT_Vector4F fallback = { 1.,1.,1.,1.};
594  };
595  UT_StringMap<TextureDef> myTextures;
596 #ifdef USE_VULKAN
597  void bindTextures(RV_Render *r,
599  const GR_DisplayOption *opts);
600 
603  UT_UniquePtr<RV_ShaderBlock> myFragUniformBlock;
604  UT_UniquePtr<RV_ShaderBlock> myTessUniformBlock;
605  UT_StringMap<RV_TextureRef> myTextureRefs;
606 #endif
607 
608  exint mySurfShaderID=0;
609  exint myCurveShaderID=0;
610 };
611 
612 #define LAYER_INST(NAME, TYPE) \
613 TYPE get##NAME(int idx) const { return myLayer.layer[idx].NAME; } \
614 void set##NAME(int idx, const TYPE &v) \
615 { if(myLayer.layer[idx].NAME != v) { myLayer.layer[idx].NAME=v; myLayerDirtyFlag=true; } } \
616  PARMKEY(NAME)
617 
618 
619 #define LAYER_PARM(NAME, TYPE) \
620  TYPE get##NAME() const { return myLayer.NAME; } \
621  void set##NAME(const TYPE &v) \
622  { if(myLayer.NAME != v) { myLayer.NAME=v; myLayerDirtyFlag=true; } } \
623  PARMKEY(NAME)
624 
626 {
627 public:
628  void updateDisplaceMap(RV_Render *r,
629  GT_DataArray *disp,
630  UT_Vector2i res);
631  void updateNormalMap(RV_Render *r,
632  GT_DataArray *nml,
633  UT_Vector2i res);
634  void updateColorMap(RV_Render *r,
636  UT_Vector2i res);
637  void updateBlendMap(RV_Render *r,
639  UT_Vector2i res);
640 
641  TEXMAP_PARM(RoughMap, RoughID);
642  TEXMAP_PARM(SpecularMap, SpecularID);
643  TEXMAP_PARM(EmissionMap, EmissionID);
644  TEXMAP_PARM(Layer1Map, Layer1ID);
645  TEXMAP_PARM(Layer2Map, Layer2ID);
646  TEXMAP_PARM(Layer3Map, Layer3ID);
647  TEXMAP_PARM(Layer4Map, Layer4ID);
648  TEXMAP_PARM(Layer5Map, Layer5ID);
649  TEXMAP_PARM(Layer6Map, Layer6ID);
650  TEXMAP_PARM(Layer7Map, Layer7ID);
651  TEXMAP_PARM(Layer8Map, Layer8ID);
652  TEXMAP_PARM(Layer9Map, Layer9ID);
653  TEXMAP_PARM(Layer10Map, Layer10ID);
654 
655  LAYER_PARM(Diff, UT_Vector3F);
656  LAYER_PARM(Spec, UT_Vector3F);
657  LAYER_PARM(SpecRough, fpreal32);
658  LAYER_PARM(SpecModel, int32);
659  LAYER_PARM(Quality, fpreal32);
660  LAYER_PARM(NumUVSets, int32);
661  LAYER_PARM(UseBlendMap, int32);
662  LAYER_PARM(HasTriplanar, int32);
663 
664  LAYER_INST(UVTransform, UT_Matrix4F);
665  LAYER_INST(Tint, UT_Vector4F);
666  LAYER_INST(TriplanarBlend, UT_Vector3F);
667  LAYER_INST(TriplanarOffset, UT_Vector3F);
668  LAYER_INST(TriplanarScale, fpreal32);
669  LAYER_INST(TriplanarSharp, fpreal32);
670  LAYER_INST(Rough, fpreal32);
671  LAYER_INST(UseTint, int32);
672  LAYER_INST(HasMap, int32);
673  LAYER_INST(UseTriplanar, int32);
674 
675  PARMKEY(ClampToEdge);
676 
677  void update(const GR_MaterialParms &options) override;
680  bool &created) override;
681  bool initBlocks(RV_Render *r, const GR_DisplayOption *opts) override;
682 
683 protected:
686 
687  friend class GR_Material;
688 private:
689  struct Layer
690  {
691  SYS_ALIGN(16) UT_Matrix4F UVTransform;
692  UT_Vector4F Tint = { 1,1,1,1};
693  UT_Vector3F TriplanarBlend = {1,1,1};
694  fpreal32 dummy1 = 0.0;
695  UT_Vector3F TriplanarOffset = {0,0,0};
696  fpreal32 TriplanarScale = 1.0;
697  fpreal32 TriplanarSharp = 1.0;
698  fpreal32 Rough = 1.0;
699  int32 UseTint = true;
700  int32 HasMap = false;
701  int32 UseTriplanar = false;
702  UT_Vector2F dummy3 = {0,0};
703  }; // padded to 144B
704 
705  class HFLayers
706  {
707  public:
708  UT_Vector3F Diff = {1.0,1.0,1.0};
709  fpreal32 SpecRough = 0.8;
710  UT_Vector3F Spec = {1.0, 1.0, 1.0};
711  int32 SpecModel = 2; // GGX
712  fpreal32 Quality = 1.0;
713  int32 NumUVSets = 1;
714  int32 UseBlendMap = false;
715  int32 HasTriplanar = false;
716  Layer layer[10];
717  } myLayer;
718 
719 
720  bool myTexDirtyFlag = true;
721  bool myLayerDirtyFlag = true;
722  int64 myDisplaceVersion = 0;
723  int64 myNormalVersion = 0;
724  int64 myColorVersion = 0;
725  int64 myBlendVersion = 0;
726  bool myClampToEdge[10];
727 #ifdef USE_VULKAN
728  UT_UniquePtr<RV_VKImage> myDisplaceMap;
729  UT_UniquePtr<RV_VKImage> myNormalMap;
730  UT_UniquePtr<RV_VKImage> myColorMap;
731  UT_UniquePtr<RV_VKImage> myBlendMap;
732  UT_UniquePtr<RV_ShaderBlock> myLayerBlock;
733 #endif
734 };
735 
736 #undef TEXMAP_PARM
737 #undef TEXMAP_PARM_VK
738 #undef PARMKEY
739 
740 #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
virtual RV_ShaderProgram * getSurfaceShader() const
Definition: GR_Material.h:151
GT_API const UT_StringHolder filename
int int32
Definition: SYS_Types.h:39
#define LAYER_INST(NAME, TYPE)
#define LAYER_PARM(NAME, TYPE)
#define TEX_PARM(TYPE, NAME)
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 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)
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
Definition: simd.h:4784
void setShaderDirty(bool dirty)
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
#define SYS_ALIGN(b)
Definition: SYS_Align.h:101
void setCachedName(UT_StringHolder &name)
#define PARMKEY(NAME)
#define GR_API
Definition: GR_API.h:10
#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
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
GLuint color
Definition: glcorearb.h:1261
virtual RV_ShaderProgram * getCurveShader() const
Definition: GR_Material.h:152
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:283
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)
exint id() const
Definition: GR_SceneItem.h:24