HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_Material.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: Render Library (C++)
7  *
8  * COMMENTS: Material definition for lit geometry
9  *
10  */
11 
12 #ifndef __RE_Material_h__
13 #define __RE_Material_h__
14 
15 #include "RE_API.h"
16 #include <DEP/DEP_MicroNode.h>
17 #include <SYS/SYS_AtomicInt.h>
18 #include <UT/UT_Color.h>
19 #include <UT/UT_IntArray.h>
20 #include <UT/UT_NonCopyable.h>
21 #include <UT/UT_Options.h>
22 #include <UT/UT_Rect.h>
23 #include <UT/UT_String.h>
24 #include <UT/UT_UniquePtr.h>
25 #include <UT/UT_Vector3.h>
26 #include <UT/UT_ValArray.h>
27 #include <UT/UT_XformOrder.h>
28 #include "RE_Types.h"
29 #include "RE_TextureTypes.h"
30 #include "RE_TextureMap.h"
31 #include "RE_UniformBlock.h"
32 
33 class RE_OGLRender;
34 class RE_OGLTexture;
35 class RE_Render;
36 class RE_Shader;
37 class RE_Texture2DMap;
38 class RE_TextureMap;
39 class RE_TextureCubeMap;
40 
42 {
43 public:
44  /// This class is used to provide texture parameters for each texture layer
46  virtual ~RE_TextureCallback();
47 
49  {
64 
70 
71  GAME_BLEND
72  };
73 
74  virtual int getNumLayers() const { return 1; }
75  virtual void updateAllSources(RE_Material *mat,
76  const UT_Options *opts,
77  fpreal time) {}
78  virtual RE_TextureMap *createTexture(RE_Render *r, int layer,
79  RE_TexMapType type,
80  UT_String &uvsetname);
81 
82  /// Returns the amount of main memory (NOT graphics memory!)
83  /// owned by this RE_TextureCallback.
84  virtual int64 getMemoryUsage(bool inclusive) const = 0;
85 
86  static bool fetchRegOrUDIM(const UT_StringHolder &tex_name,
87  const UT_StringHolder &node_path,
88  RE_TextureMap *&map);
89 };
90 
92 {
93 public:
94  explicit RE_Material(const char *materialName);
95 
96  const UT_StringHolder &
97  getMaterialName() const { return myMaterialName; }
98  int getUniqueId() const { return myUniqueId; }
99 
100  int64 getVersion() const { return myVersion; }
101  void setVersion(int64 v) { myVersion = v; }
102 
103  void dirty(bool dirty = true) { myDirtyFlag = dirty; }
104  bool isDirty(fpreal time) const
105  {
106  if(myDirtyFlag)
107  return true;
108  if(myTimeDep && !SYSisEqual(time, myTime))
109  return true;
110  return false;
111  }
112 
113  void setTimeDependent(bool timedep, fpreal t = 0.0)
114  {
115  myTimeDep = timedep;
116  myTime = timedep ? t : 0.0;
117  }
118  bool isTimeDependent() const { return myTimeDep; }
119  fpreal getCurrentTime() const { return myTime; }
120 
121  void incref() { myRefCount.add(1); }
122  void decref()
123  {
124  if (!myRefCount.add(-1))
125  delete this;
126  }
127 
128  void setNodePath(UT_StringHolder path, int node_id);
129  const UT_StringHolder &
130  getNodePath() const { return myNodePath; }
131  int getNodeId() const { return myNodeID; }
132 
133  // Parameter overrides
134  void setOverrides(const UT_Options *overrides);
135  const UT_Options &getOverrides() const { return myOverrides; }
136  bool hasOverrides() const { return myOverrides.getNumOptions()>0; }
137 
138  // Vertex array overrides
140  { myVertexOverrides = ovr; }
142  { return myVertexOverrides; }
143 
145  {
149  TERRAIN_SURFACE
150  };
151  void setMaterialType(RE_MaterialType type);
152  RE_MaterialType getMaterialType() const { return myMaterialType; }
153 
154  void markDefaultShader(bool def) { myDefaultShader = def; }
155  bool isDefaultShader() const { return myDefaultShader; }
156 
157  void assignShader(RE_Shader *sh,
159  bool owned = true);
160  void assignShader(UT_UniquePtr<RE_Shader> &&sh,
162 
163  // methods to deal with textures
164  void clearTexture(RE_Render *r);
165  void clearDiffuseMap();
166 
167  // General diffuse texture, 1 allowed per layer.
168  RE_TextureHolder getTexture(RE_Render *r, int layer);
169 
170  // Extra textures, only 1 allowed for the first layer.
171  RE_TextureHolder getSpecularMap(RE_Render *r);
172  RE_TextureHolder getBumpMap(RE_Render *r);
173  RE_TextureHolder getNormalMap(RE_Render *r);
174  RE_TextureHolder getOpacityMap(RE_Render *r);
175  RE_TextureHolder getDisplaceMap(RE_Render *r);
176  RE_TextureHolder getEmissionMap(RE_Render *r);
177  RE_TextureHolder getRoughnessMap(RE_Render *r);
178  RE_TextureHolder getOcclusionMap(RE_Render *r);
179  RE_TextureHolder getMetallicMap(RE_Render *r);
180  RE_TextureHolder getCoatIntensityMap(RE_Render *r);
181  RE_TextureHolder getCoatRoughnessMap(RE_Render *r);
182  RE_TextureHolder getReflectionAmountMap(RE_Render *r);
183 
184  RE_TextureHolder getHairDiffuseMap(RE_Render *r);
185  RE_TextureHolder getHairSpecularMap(RE_Render *r);
186  RE_TextureHolder getHairDiffuseRamp(RE_Render *r);
187  RE_TextureHolder getHairSpecularRamp(RE_Render *r);
188  RE_TextureHolder getHairAlphaRamp(RE_Render *r);
189 
190  // Environment map to affect specular reflection. One allowed for layer 0.
191  RE_TextureHolder getEnvMap(RE_Render *r);
192 
193  void clearTextureLayer(int layer);
194 
195  // In order for these to return the correct value, the corresponding
196  // get..() method must be called first.
197  bool hasSpecularMap() const { return mySpecMap.myTex.isValid(); }
198  bool hasBumpMap() const { return myBumpMap.myTex.isValid(); }
199  bool hasNormalMap() const { return myNormalMap.myTex.isValid(); }
200  bool hasOpacityMap() const{ return myOpacityMap.myTex.isValid(); }
201  bool hasDisplaceMap() const{return myDisplaceMap.myTex.isValid();}
202  bool hasEnvMap() const { return myEnvMap.isValid(); }
203  bool hasEmissionMap() const
204  { return myEmissionMap.myTex.isValid(); }
205  bool hasRoughnessMap() const
206  { return myRoughMap.myTex.isValid(); }
207  bool hasOcclusionMap() const
208  { return myOcclusionMap.myTex.isValid(); }
209  bool hasMetallicMap() const
210  { return myMetallicMap.myTex.isValid(); }
211  bool hasCoatRoughnessMap() const
212  { return myCoatRoughMap.myTex.isValid(); }
213  bool hasCoatIntensityMap() const
214  { return myCoatIntMap.myTex.isValid(); }
216  { return myReflectAmountMap.myTex.isValid(); }
217 
218  bool hasHairDiffuseMap() const{ return myHairDiffMap.isValid(); }
219  bool hasHairSpecularMap() const{ return myHairSpecMap.isValid();}
220  bool hasHairDiffuseRamp() const{ return myHairDiffRamp.isValid();}
221  bool hasHairSpecularRamp() const{return myHairSpecRamp.isValid();}
222  bool hasHairAlphaRamp() const{ return myHairAlphaRamp.isValid(); }
223 
224  // Query the material if it is opaque or transparent. 'check_diffuse_alpha'
225  // will check the diffuse texture's alpha channel.
226  bool isTransparent(bool check_diffuse_alpha) const;
227 
228  // Returns true if this material has a texture map (diffuse, bump, etc).
229  bool isTextured() const { return myTexturedFlag; }
230 
231  // Returns true if textures are used, and the uvsets used by all layers of
232  // the
233  bool getUVSets(UT_Map<UT_StringHolder, int> &uvsets) const;
234 
235  // Return the texture coord set used by 'layer'
236  const UT_StringHolder &getLayerUVSet(int layer) const;
237 
238  // This allows the creator of this object to hook up a callback
239  // with which an instance of RE_Material could ask for a texture
240  // if and when the texture is needed. The presence of a callback
241  // marks this material as being textured, so only set when necessary.
242  void setCallback(RE_TextureCallback *cb);
243  RE_TextureCallback *getCallback() { return myTexCallback; }
244 
245  void setTextureFormat(RE_TextureCompress format);
246  RE_TextureCompress getTextureFormat() const { return myTexFormat; }
247 
248  void limitTextureSize(bool limit, int w, int h);
249  bool limitTextureSize() const { return myLimitTextureSize; }
250  void getMaxTextureSize(int &w,int &h)
251  { myMaxTextureW = w;
252  myMaxTextureH = h; }
253 
254  void setTextureScale(float sc);
255  float getTextureScale() const { return myTextureScale; }
256 
257  void setTextureMemLimitMB(int mem);
258  int getTextureMemLimitMB() const { return myTextureMemLimitMB; }
259 
260  void mipMapTextures(bool yes);
261  bool mipMapTextures() const { return myMipMapTextures; }
262 
263  void setAnisotropySamples(int samp);
264  int getAnisotropySamples() const { return myTextureAnisotropy; }
265 
266  void allowShaders(bool yes) { myAllowShaders = yes; }
267  bool allowShaders() const { return myAllowShaders; }
268 
269  // methods to deal with lighting
270  void doLighting(bool yes );
271  bool isLit() const { return myDoLighting; }
272 
273  RE_Shader *createShader(RE_Render *r,
274  const char *name = 0,
277  { return myShader[sht]; }
280  { return myOwnShader[sht]; }
281 
282  /// caches the source for the shader in the material.
283  void setShaderSource(const char *vert_src,
284  const char *geom_src,
285  const char *frag_src,
286  RE_ShaderTarget ptype
288 
289  /// checks this materials' shader against the source, and returns true if
290  /// it matches.
291  bool hasShaderSource(const char *vert_src,
292  const char *geom_src,
293  const char *frag_src,
294  RE_ShaderTarget ptype
296 
297  void setShaderProgram(const char *program_file);
298  bool hasShaderProgram(const char *program_file) const;
301  { return myShaderProgramFile.isstring() ||
302  myVertexSource[ptype].isstring() ||
303  myGeometrySource[ptype].isstring() ||
304  myFragmentSource[ptype].isstring(); }
305  bool customShaderDirty() const { return myCustomShaderDirty; }
306 
307  void removeShader();
308 
309  // methods to access and change the material information
310  float amb( unsigned idx ) const { return myAmb[idx]; }
311  UT_Vector3F amb() const { return myAmb; }
312  float diff( unsigned idx ) const { return myDiff[idx]; }
313  UT_Vector3F diff() const { return myDiff; }
314  float spec( unsigned idx ) const { return mySpec[idx]; }
315  UT_Vector3F spec() const { return mySpec; }
316  float emit( unsigned idx ) const { return myEmit[idx]; }
317  UT_Vector3F emit() const { return myEmit; }
318  UT_Vector3F metallicEdgeTint() const { return myMetallicEdge; }
319  float metallic() const { return myMetallic; }
320  float alpha() const { return myAlpha; }
321  float roughness() const { return myRoughness; }
322  float reflection() const { return myReflection; }
323  float coatRoughness() const { return myCoatRough; }
324  float coatIntensity() const { return myCoatIntensity; }
325  float diffuseRoughness() const { return myDiffRoughness; }
326 
327  /// Sets the perpendicular and parallel alpha factors. If the parallel
328  /// alpha is less than zero, they are assumed to be the same.
329  void setAlpha( float alpha_perp, float alpha_para = -1.0 );
330 
331  /// If true, the shader generates its own alpha independent of the material
332  /// parameters. This indicates that the material requires a transparency
333  /// pass, since the renderer can otherwise not determine this from the
334  /// shader code.
336  { myShaderAlphaFlag = enabled; }
337  bool hasShaderAlpha() const { return myShaderAlphaFlag; }
338 
339  // give roughness: this method will calculate shininess needed by OGL
340  void setRoughness( float r );
341 
342  // give shininess: this method will enforce sh within [0.001, 1e10]
343  void setShininess( float sh );
344 
345  void setDiffuseRoughness(fpreal r);
346 
347  void setAmb( float r, float g, float b );
348  void setDiff( float r, float g, float b );
349  void setSpec( float r, float g, float b );
350  void setEmit( float r, float g, float b );
351  void setMetallic(float metal);
352  void setMetallicEdge(const UT_Vector3F &metal);
353 
354  void setAmbient( UT_Color col );
355  void setDiffuse( UT_Color col );
356  void setSpecular( UT_Color col );
357  void setEmission( UT_Color col );
358 
359  void setAmbient( const UT_Vector3F &col );
360  void setDiffuse( const UT_Vector3F &col );
361  void setSpecular( const UT_Vector3F &col );
362  void setEmission( const UT_Vector3F &col );
363 
364  void setSpecularTint(fpreal t);
365  fpreal getSpecularTint() const { return mySpecTint; }
366 
367  enum { PHONG=0, BLINN=1, GGX=2, SPEC_ANGLE=3 };
368  void setSpecularModel(int spec_model);
369  int getSpecularModel() const { return mySpecModel; }
370  void setCoatSpecularModel(int spec_model);
371  int getCoatSpecuarModel() const { return myCoatModel; }
372  void setCoatIntensity(fpreal i);
373  fpreal getCoatIntensity() const { return myCoatIntensity; }
374  void setCoatRoughness(fpreal r);
375  fpreal getCoatRoughness() const { return myCoatRough; }
376 
377  void setIOR(float ior);
378  fpreal getIOR() const { return myIOR; }
379 
380  void setReflection(float r, bool explicit_r);
381  fpreal getReflection() const;
382 
383  void usePackedColor(bool enable);
384  void useGeometryColor(bool enable);
385  bool usePackedColor() const { return myUsePackedColor; }
386  bool useGeometryColor() const { return myUseGeoColor; }
387 
388  // returns true if reflection was explicity set, not derived from IoR.
389  bool hasExplicitReflection() const { return myExplicitReflection; }
390 
391  // Parameters for the bump, spec, opac, env, disp and normal maps.
392  enum re_NormalMapType { NMLMAP_TANGENT=0, NMLMAP_WORLD=1, NMLMAP_OBJECT=2 };
393 
394  void setOpacityMapParms(bool invert);
395  void setNormalParms(re_NormalMapType type, bool bias,
397  bool flip_x, bool flip_y, bool flip_z);
398  void setEnvParms(float scale, const UT_Vector3 &rot,
399  const UT_XformOrder &rord);
400 
401  enum re_Displace {
405  DISPLACE_VECTOR_OBJECT };
406  void setDisplaceParms(float scale, float offset,
407  re_Displace vector_space, bool y_up);
408  void setRoughParms(bool invert_map, int component);
409  void setOcclusionParms(int component);
410  void setMetallicParms(int component);
411  void setCoatRoughnessParms(int component);
412  void setCoatIntensityParms(int component);
413  void setReflectionAmountParms(int component, bool affect_ior);
414 
415  // Hair parameters
416  void enableHairParameters(bool e) { myHairMaterialEnabled = e; }
417 
418  void setHairDiffuse(float intensity,
419  UT_Vector3F root_col,
420  UT_Vector3F tip_col,
421  bool use_map,
422  bool use_ramp);
423 
424  void setHairSpecular(float intensity,
425  float angle,
426  float shift,
427  UT_Vector3F root_col,
428  UT_Vector3F tip_col,
429  bool use_map,
430  bool use_ramp);
431  void setHairAlpha(float alpha,
432  bool use_alpha_ramp);
433 
434  // randomize hue, sat, and intensity of diffuse (and specular intensity)
435  void setHairRandomize(bool random_hue, UT_Vector2F hue_range,
436  bool random_sat, UT_Vector2F sat_range,
437  bool random_int, UT_Vector2F int_range,
438  bool random_spec_int,
439  UT_Vector2F spec_int_range);
440 
441  // Game shader
442 
443  // Use a transformed UV set.
444  void setUVTransform(int layer,
445  UT_Vector2F t,
446  fpreal r,
447  UT_Vector2F s);
448  void getUVTransform(int layer,
449  UT_Vector2F &t,
450  fpreal &r,
451  UT_Vector2F &s ) const;
452  void setUVLayerTint(int layer, bool use_tint, UT_Vector4F tint);
453 
454  // Use triplanar projection.
455  void setUVTriplanar(int layer,
456  fpreal scale = 1.0,
457  fpreal sharp = 1.0,
458  UT_Vector3F blend =UT_Vector3F(1.0f),
460  bool isUVTriplanar(int layer) const;
461  fpreal getUVTriplanarSharp(int layer) const;
462  fpreal getUVTriplanarScale(int layer) const;
463  UT_Vector3F getUVTriplanarBlend(int layer) const;
464  UT_Vector3F getUVTriplanarOffset(int layer) const;
465  bool getUVLayerUseTint(int layer) const;
466  UT_Vector4F getUVLayerTint(int layer) const;
467 
468 
469  // For environment lights, which temporarily apply their map to any
470  // materials that don't already have an env map.
471  static void setEnvMapOverride(RE_TextureHolder env_map,
472  const UT_Matrix3F &rot,
473  const UT_Vector3F &col);
474  static void clearEnvMapOverride();
475  static RE_TextureHolder getEnvMapOverride();
476 
477  void setReflectionMap(RE_Texture *map) { myReflectMap = map; }
478  void clearReflectionMap() { myReflectMap = NULL; }
479 
480 #ifdef UT_DEBUG
481  // debug output
482  void output();
483 #endif
484 
485  RE_MaterialPtr cloneWithoutTexture() const;
486 
487  void loadTextureMaps(RE_Render *r);
488 
489  // Adds an explicit map to 'maptype' which is not overriden by the
490  // RE_TextureCallback. NULL is acceptable (blocks the RE_TextureCB map).
491  void assignTextureMap(RE_Texture *tex,
493  int index = 0);
494  // Remove the explicit map from 'maptype', allowing RE_TextureCallback to
495  // be called for the map.
496  void removeTextureMap(RE_TextureCallback::RE_TexMapType maptype,
497  int index = 0);
498 
500  { return myMaterialType==FILM_SURFACE ?myNumDiffuseLayers :1; }
501 
502  bool updateShaderForMaterial(RE_Render *r,
503  int layer,
504  bool lit,
505  bool textured,
507  RE_Shader *shader = NULL);
508  void restoreShader(RE_Render *r,
510 
511  /// Returns the amount of main memory (NOT graphics memory!)
512  /// owned by this RE_Material.
513  int64 getMemoryUsage(bool inclusive) const;
514 
515 
516  void writeMaterialParmsToBlockGL4(RE_Render *r,
517  RE_UniformBlock *block,
518  int material_idx,
519  int layer,
520  bool lit,
521  bool textured);
522  // For bindless texturing.
523  void makeTexturesResident(RE_Render *r);
524  void removeTexturesFromResident(RE_Render *r);
525 
526  DEP_MicroNode &dependencies() { return myDepNode; }
527 
529  { return myMaterialBlock; }
531  { return myHairMaterialBlock; }
533  { return myGameMaterialBlock; }
534 private:
535 
536  void loadShaderAttribNames();
537 
538  class re_MaterialTextureMap
539  {
540  public:
541  re_MaterialTextureMap()
542  : myMap(NULL), myHasMap(0), myMapIndex(-1),
543  myArrayMapIndex(-1), myTexCoords(0), myComponent(0),
544  myExplicitMap(false) {}
545 
546  RE_TextureMap *myMap;
547  RE_TextureHolder myTex;
548  UT_StringHolder myUVSet;
549  int myHasMap;
550  UT_DimRect myUDIMArea;
551  int myMapIndex;
552  int myArrayMapIndex;
553  int myTexCoords;
554  int myComponent;
555  bool myExplicitMap;
556  };
557  re_MaterialTextureMap *fetchMapInfo(RE_TextureCallback::RE_TexMapType t,
558  int index);
559 
560  RE_TextureHolder fetchTexture(RE_Render *r, RE_TextureMap *map,
561  bool allow_mipmap = true);
562  RE_TextureHolder fetchMap(RE_Render *r,
564  re_MaterialTextureMap &map,
565  bool promote_1chan_to_rgb = false);
566 
567  bool checkForMap(re_MaterialTextureMap &map, bool textured);
568  bool bindTextureMap(RE_Render *r, re_MaterialTextureMap &map,
569  const char *udim_stride_name,
570  const char *component_name = NULL);
571 private:
572  ~RE_Material(); // No subclassing
573 
574  void updateHairMaterialForShader(RE_Render *r,
575  bool textured,
576  RE_ShaderTarget sht,
577  RE_Shader *sh);
578  void updateGameMaterialForShader(RE_Render *r,
579  bool textured,
580  RE_ShaderTarget sht,
581  RE_Shader *sh);
582 
583  // -- Bindless texturing support
584  void makeResident(RE_Render *r, RE_TextureHolder texmap);
585  void removeResident(RE_Render *r, RE_TextureHolder texmap);
586  bool bindTextureHandle(RE_Render *r,
587  re_MaterialTextureMap &map,
588  RE_UniformBlock *material_block,
589  int material_index,
590  const char *texture_name);
591  // --
592 
593  UT_Vector4F getComponentVector(int comp) const;
594 
595  DEP_MicroNode myDepNode;
596  RE_TextureCallback *myTexCallback;
597  UT_Vector3F myAmb;
598  UT_Vector3F myDiff;
599  UT_Vector3F mySpec;
600  UT_Vector3F myEmit;
601  UT_Vector3F myMetallicEdge;
602  float myMetallic;
603  float myAlpha;
604  float myRoughness;
605  float myDiffRoughness;
606  float mySpecTint;
607  RE_MaterialType myMaterialType;
608 
609  // I own map if if I created my RE_OGLTex
611 
612  RE_TextureHolder myEnvMap;
613  RE_Texture *myReflectMap; // always temporary during a render
614 
615  RE_TextureHolder myHairDiffMap;
616  RE_TextureHolder myHairSpecMap;
617  RE_TextureHolder myHairDiffRamp;
618  RE_TextureHolder myHairSpecRamp;
619  RE_TextureHolder myHairAlphaRamp;
620 
621  re_MaterialTextureMap mySpecMap;
622  re_MaterialTextureMap myOpacityMap;
623  re_MaterialTextureMap myBumpMap;
624  re_MaterialTextureMap myRoughMap;
625  re_MaterialTextureMap myEmissionMap;
626  re_MaterialTextureMap myNormalMap;
627  re_MaterialTextureMap myDisplaceMap;
628  re_MaterialTextureMap myOcclusionMap;
629  re_MaterialTextureMap myMetallicMap;
630  re_MaterialTextureMap myCoatRoughMap;
631  re_MaterialTextureMap myCoatIntMap;
632  re_MaterialTextureMap myReflectAmountMap;
633  re_MaterialTextureMap myGameBlendMap;
634 
635 
636  // The above maps are only valid pointers if myRenderCount is equal to
637  // RE_OGLRender::getRenderCount.
638  int64 myRenderCount;
639 
640 
641  UT_StringHolder myMaterialName;
642  UT_StringHolder myNodePath;
643  int myNodeID;
644  UT_Options myOverrides;
645  UT_StringMap<UT_StringHolder> myVertexOverrides;
646  unsigned myDoLighting:1,
647  myMipMapTextures:1,
648  myLimitTextureSize:1,
649  myDefaultShader:1,
650  myAllowShaders:1,
651  myTrivialTextureAlpha:1,
652  myInvertRoughMap:1,
653  myCustomShaderDirty:1;
654  int myTextureAnisotropy;
655  int myNumDiffuseLayers;
656 
657  RE_TextureCompress myTexFormat;
658  int myMaxTextureW, myMaxTextureH;
659  float myTextureScale;
660  int myTextureMemLimitMB;
661  float myAlphaPara;
662  bool myShaderAlphaFlag;
663  bool myUseGeoColor;
664  bool myUsePackedColor;
665  bool myDirtyFlag;
666 
667  // Specular parms
668  fpreal myIOR;
669  fpreal32 myReflection;
670  int mySpecModel;
671  bool myReflectAsIOR;
672  bool myExplicitReflection;
673 
674  // Coat parms
675  fpreal myCoatRough;
676  fpreal myCoatIntensity;
677  int myCoatModel;
678 
679  // normal map parms
680  bool myNormalBias;
681  bool myNormalFlipX;
682  bool myNormalFlipY;
683  bool myNormalFlipZ;
684  UT_Vector2F myNormalScale;
685  re_NormalMapType myNormalMapType;
686 
687  // environment map parms
688  UT_Vector3 myEnvRotation;
689  float myEnvScale;
690  UT_XformOrder myEnvRotOrder;
691 
692  // displacement map parms
693  float myDisplaceScale;
694  float myDisplaceOffset;
695  re_Displace myDisplaceSpace;
696  bool myDisplaceYUp;
697 
698  bool myOpacityMapInvert;
699  int myRoughComp;
700  int myOcclusionComp;
701  int myMetallicComp;
702 
703  RE_Shader *myShader[RE_SHADER_NUM_TARGETS];
704  bool myOwnShader[RE_SHADER_NUM_TARGETS];
705  UT_String myVertexSource[RE_SHADER_NUM_TARGETS];
706  UT_String myGeometrySource[RE_SHADER_NUM_TARGETS];
707  UT_String myFragmentSource[RE_SHADER_NUM_TARGETS];
708  UT_String myShaderProgramFile;
709 
710  RE_UniformBlockHandle myMaterialBlock;
711  int myMaterialOverride;
712  bool myMatBlockDirty;
713  bool myMatBlockHasEnvMapTexture;
714  bool myMatBlockHasReflectMapTexture;
715  bool myMatBlockHasDiffuseTexture;
716  bool myTexturedFlag;
717 
718  // Hair parameters
719  class re_HairCompParms
720  {
721  public:
722  re_HairCompParms() : intensity(0.5), shift(0.0), angle(1.0),
723  root_col(1,1,1), tip_col(1,1,1),
724  use_ramp(false), use_map(false) {}
725  float intensity;
726  float angle;
727  float shift;
728  UT_Vector3F root_col;
729  UT_Vector3F tip_col;
730  bool use_ramp;
731  bool use_map;
732  };
733  struct re_HairRandomParms
734  {
735  re_HairRandomParms() : randomize(false) {}
736  bool randomize;
738  };
739 
740  bool myHairMaterialEnabled;
741  re_HairCompParms myHairDiffuse;
742  re_HairCompParms myHairSpecular;
743  float myHairAlpha;
744  bool myHairUseAlphaRamp;
745  re_HairRandomParms myHairRandomDiffHue;
746  re_HairRandomParms myHairRandomDiffSat;
747  re_HairRandomParms myHairRandomDiffInt;
748  re_HairRandomParms myHairRandomSpecInt;
749  RE_UniformBlockHandle myHairMaterialBlock;
750  int myHairMatBlockIndex;
751  int myHairRandomTextureIndex;
752  int myHairDiffBaseMapIndex;
753  UT_DimRect myHairDiffBaseMapUDIMArea;
754  UT_DimRect myHairSpecBaseMapUDIMArea;
755 
756  RE_TextureHolder myRandomTexture;
757 
758  // cached texture units for 'myLastMatShader'.
759  void *myLastMatShader;
760  int myLastMatShaderSerial;
761 
762  int myMatBlockDiffuseIndex;
763  int myMatBlockDiffuseArrayIndex;
764 
765  int myMatBlockEnvMapIndex;
766  int myMatBlockReflectMapIndex;
767  int myMatBlockIndex;
768  int myHairMaterialOverride;
769 
770  // hair material block.
771  void *myLastHairShader;
772  int myLastHairShaderSerial;
773  int myHairDiffIndex;
774  int myHairDiffArrayIndex;
775  int myHairSpecIndex;
776  int myHairSpecArrayIndex;
777  int myHairDiffRampIndex;
778  int myHairSpecRampIndex;
779  int myHairAlphaRampIndex;
780  int myMatBlockHairIndex;
781 
782  // game shader material block
783  RE_UniformBlockHandle myGameMaterialBlock;
784  int myGameMaterialOverride;
785 
786  struct re_GameLayer
787  {
788  re_GameLayer() : triplanar(false), scale(1,1), trans(0,0), rot(0),
789  sharp(1), unit(-1), tpscale(1), transform(1.0),
790  tpblend(1,1,1), tpoff(0,0,0), use_tint(false),
791  tint(1.0, 1.0, 1.0, 1.0) {}
792  bool triplanar;
795  float rot;
796  float sharp;
797  float tpscale;
798  UT_Vector3F tpblend;
799  UT_Vector3F tpoff;
801  bool use_tint;
802  UT_Vector4F tint;
803 
804  // unit for shader
805  int unit;
806  };
807  UT_Array<re_GameLayer> myGameLayers;
808  const RE_Shader *myLastGameShader;
809  int myLastGameShaderSerial;
810  int myGameBlendIndex;
811  int myGameMatBlockIndex;
812 
813  int myPrevSeamlessCubeMap;
814 
815  bool myTimeDep;
816  fpreal myTime;
817 
818  SYS_AtomicInt32 myRefCount;
819  int64 myUniqueId;
820  int64 myVersion;
821 };
822 
823 static inline void intrusive_ptr_add_ref(RE_Material *m) { m->incref(); }
824 static inline void intrusive_ptr_release(RE_Material *m) { m->decref(); }
825 
826 inline void
828 {
829  setAmb(col.x(), col.y(), col.z());
830 }
831 inline void
833 {
834  setDiff(col.x(), col.y(), col.z());
835 }
836 inline void
838 {
839  setSpec(col.x(), col.y(), col.z());
840 }
841 inline void
843 {
844  setEmit(col.x(), col.y(), col.z());
845 }
846 
847 
848 // This contains a list of materials for drawing a given geometry, and is
849 // normally used as a transient list of materials during a redraw.
850 // This class does not own the materials as they are also held in
851 // a higher-level cache as well.
852 class RE_API RE_MaterialAtlas : public UT_Map<int,RE_MaterialPtr>
853 {
854 public:
855  // Default material for unassigned prims.
857  { return myDefault; }
858 
859  // Factory default material if materials are disabled.
861  { return myFactory; }
862 
863  bool isDirty(fpreal time) const;
864 
865  RE_MaterialPtr get(int material_id) const
866  {
867  if(material_id == -1)
868  return myDefault ? myDefault : myFactory;
869  const_iterator entry = find(material_id);
870  if(entry != end())
871  return entry->second;
872 
873  return NULL;
874  }
875 
876 
877  // Add a new material to the atlas
878  void add(const RE_MaterialPtr &material)
879  { (*this)[ material->getUniqueId() ] = material; }
880 
881  // Set the default material, which will be used if no other material
882  // assignments are present.
883  void setDefaultMaterial(const RE_MaterialPtr &material,bool add_list=true)
884  { myDefault = material; if(add_list && material) add(material); }
885 
886  // Sets the factory default material, which is used when all materials
887  // are turned off (as the default material may be the object material).
888  void setFactoryMaterial(const RE_MaterialPtr &material,bool add_list=true)
889  { myFactory = material; if(add_list && material) add(material); }
890 
891 private:
892  RE_MaterialPtr myDefault;
893  RE_MaterialPtr myFactory;
894 };
895 
896 #endif
void setDiffuse(UT_Color col)
bool mipMapTextures() const
Definition: RE_Material.h:261
RE_TextureCallback * getCallback()
Definition: RE_Material.h:243
UT_Vector3F spec() const
Definition: RE_Material.h:315
bool hasOverrides() const
Definition: RE_Material.h:136
bool hasHairDiffuseMap() const
Definition: RE_Material.h:218
float alpha() const
Definition: RE_Material.h:320
void setVersion(int64 v)
Definition: RE_Material.h:101
GLenum GLint * range
Definition: glcorearb.h:1924
bool hasOpacityMap() const
Definition: RE_Material.h:200
int64 getVersion() const
Definition: RE_Material.h:100
float reflection() const
Definition: RE_Material.h:322
Unsorted map container.
Definition: UT_Map.h:83
const UT_StringHolder & getNodePath() const
Definition: RE_Material.h:130
void dirty(bool dirty=true)
Definition: RE_Material.h:103
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1298
void incref()
Definition: RE_Material.h:121
#define RE_API
Definition: RE_API.h:10
bool isTimeDependent() const
Definition: RE_Material.h:118
GLboolean invert
Definition: glcorearb.h:548
bool hasBumpMap() const
Definition: RE_Material.h:198
GT_API const UT_StringHolder time
const GLdouble * v
Definition: glcorearb.h:836
UT_Vector3F diff() const
Definition: RE_Material.h:313
png_infop int * unit
Definition: png.h:2536
float roughness() const
Definition: RE_Material.h:321
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
const RE_UniformBlockHandle & hairBlock() const
Definition: RE_Material.h:530
GA_API const UT_StringHolder rot
void setEmit(float r, float g, float b)
GLboolean GLboolean g
Definition: glcorearb.h:1221
float metallic() const
Definition: RE_Material.h:319
int getSpecularModel() const
Definition: RE_Material.h:369
void setShaderAlpha(bool enabled)
Definition: RE_Material.h:335
bool hasShaderAlpha() const
Definition: RE_Material.h:337
const RE_MaterialPtr & getDefaultMaterial() const
Definition: RE_Material.h:856
void decref()
Definition: RE_Material.h:122
void intrusive_ptr_release(PXR_NS::Sdf_Identity *p)
Definition: identity.h:81
void setSpecular(UT_Color col)
bool hasCoatIntensityMap() const
Definition: RE_Material.h:213
const UT_Options & getOverrides() const
Definition: RE_Material.h:135
void setSpec(float r, float g, float b)
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glcorearb.h:2538
bool hasRoughnessMap() const
Definition: RE_Material.h:205
fpreal getCurrentTime() const
Definition: RE_Material.h:119
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:498
int getTextureMemLimitMB() const
Definition: RE_Material.h:258
const UT_StringMap< UT_StringHolder > & vertexOverrides() const
Definition: RE_Material.h:141
void setAmb(float r, float g, float b)
int getAnisotropySamples() const
Definition: RE_Material.h:264
png_uint_32 i
Definition: png.h:2877
bool isShaderOwned(RE_ShaderTarget sht=RE_SHADER_TARGET_TRIANGLE) const
Definition: RE_Material.h:278
png_infop png_bytep * trans
Definition: png.h:2520
virtual int getNumLayers() const
Definition: RE_Material.h:74
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:502
RE_MaterialType getMaterialType() const
Definition: RE_Material.h:152
long long int64
Definition: SYS_Types.h:107
GA_API const UT_StringHolder scale
bool hasHairSpecularRamp() const
Definition: RE_Material.h:221
float amb(unsigned idx) const
Definition: RE_Material.h:310
GLfloat f
Definition: glcorearb.h:1925
DEP_MicroNode & dependencies()
Definition: RE_Material.h:526
void setFactoryMaterial(const RE_MaterialPtr &material, bool add_list=true)
Definition: RE_Material.h:888
const RE_UniformBlockHandle & materialBlock() const
Definition: RE_Material.h:528
bool hasDisplaceMap() const
Definition: RE_Material.h:201
int getCoatSpecuarModel() const
Definition: RE_Material.h:371
const RE_UniformBlockHandle & gameMatBlock() const
Definition: RE_Material.h:532
bool hasHairDiffuseRamp() const
Definition: RE_Material.h:220
bool hasReflectionAmountMap() const
Definition: RE_Material.h:215
bool hasNormalMap() const
Definition: RE_Material.h:199
void setReflectionMap(RE_Texture *map)
Definition: RE_Material.h:477
bool usePackedColor() const
Definition: RE_Material.h:385
GLuint GLuint end
Definition: glcorearb.h:474
bool limitTextureSize() const
Definition: RE_Material.h:249
fpreal getIOR() const
Definition: RE_Material.h:378
GLintptr offset
Definition: glcorearb.h:664
void setTimeDependent(bool timedep, fpreal t=0.0)
Definition: RE_Material.h:113
bool customShaderDirty() const
Definition: RE_Material.h:305
bool hasMetallicMap() const
Definition: RE_Material.h:209
void intrusive_ptr_add_ref(PXR_NS::Sdf_Identity *p)
Definition: identity.h:78
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:472
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:111
GLuint const GLchar * name
Definition: glcorearb.h:785
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
virtual void updateAllSources(RE_Material *mat, const UT_Options *opts, fpreal time)
Definition: RE_Material.h:75
GA_API const UT_StringHolder transform
void setEmission(UT_Color col)
bool isLit() const
Definition: RE_Material.h:271
fpreal getCoatIntensity() const
Definition: RE_Material.h:373
bool hasOcclusionMap() const
Definition: RE_Material.h:207
void markDefaultShader(bool def)
Definition: RE_Material.h:154
int getUniqueId() const
Definition: RE_Material.h:98
bool hasSpecularMap() const
Definition: RE_Material.h:197
bool allowShaders() const
Definition: RE_Material.h:267
void enableHairParameters(bool e)
Definition: RE_Material.h:416
float diff(unsigned idx) const
Definition: RE_Material.h:312
void setDefaultMaterial(const RE_MaterialPtr &material, bool add_list=true)
Definition: RE_Material.h:883
UT_Vector3T< fpreal32 > UT_Vector3F
RE_Shader * getShader(RE_ShaderTarget sht=RE_SHADER_TARGET_TRIANGLE) const
Definition: RE_Material.h:276
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
float emit(unsigned idx) const
Definition: RE_Material.h:316
float coatRoughness() const
Definition: RE_Material.h:323
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:500
GLuint shader
Definition: glcorearb.h:784
double fpreal
Definition: SYS_Types.h:270
A map of string to various well defined value types.
Definition: UT_Options.h:42
float diffuseRoughness() const
Definition: RE_Material.h:325
bool hasCoatRoughnessMap() const
Definition: RE_Material.h:211
float spec(unsigned idx) const
Definition: RE_Material.h:314
float coatIntensity() const
Definition: RE_Material.h:324
void setDiff(float r, float g, float b)
void clearReflectionMap()
Definition: RE_Material.h:478
bool hasEnvMap() const
Definition: RE_Material.h:202
const RE_MaterialPtr & getFactoryMaterial() const
Definition: RE_Material.h:860
bool useGeometryColor() const
Definition: RE_Material.h:386
void setVertexOverrides(const UT_StringMap< UT_StringHolder > &ovr)
Definition: RE_Material.h:139
UT_Vector3F metallicEdgeTint() const
Definition: RE_Material.h:318
bool hasHairAlphaRamp() const
Definition: RE_Material.h:222
bool hasEmissionMap() const
Definition: RE_Material.h:203
GLuint index
Definition: glcorearb.h:785
RE_TextureCompress getTextureFormat() const
Definition: RE_Material.h:246
void setAmbient(UT_Color col)
UT_Vector3F amb() const
Definition: RE_Material.h:311
const UT_StringHolder & getMaterialName() const
Definition: RE_Material.h:97
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
int getNodeId() const
Definition: RE_Material.h:131
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
UT_Vector3F emit() const
Definition: RE_Material.h:317
void add(const RE_MaterialPtr &material)
Definition: RE_Material.h:878
GLboolean r
Definition: glcorearb.h:1221
void getMaxTextureSize(int &w, int &h)
Definition: RE_Material.h:250
RE_ShaderTarget
Definition: RE_Types.h:250
bool hasExplicitReflection() const
Definition: RE_Material.h:389
RE_TextureCompress
bool isDirty(fpreal time) const
Definition: RE_Material.h:104
fpreal getCoatRoughness() const
Definition: RE_Material.h:375
Base::const_iterator const_iterator
Definition: UT_Map.h:94
float fpreal32
Definition: SYS_Types.h:191
bool isTextured() const
Definition: RE_Material.h:229
int getNumDiffuseLayers() const
Definition: RE_Material.h:499
bool hasHairSpecularMap() const
Definition: RE_Material.h:219
float getTextureScale() const
Definition: RE_Material.h:255
bool isDefaultShader() const
Definition: RE_Material.h:155
fpreal getSpecularTint() const
Definition: RE_Material.h:365
void allowShaders(bool yes)
Definition: RE_Material.h:266
bool hasCustomShader(RE_ShaderTarget ptype=RE_SHADER_TARGET_TRIANGLE) const
Definition: RE_Material.h:299