12 #ifndef __RE_Material_h__
13 #define __RE_Material_h__
56 if(myDirtyFlag || myDepNode.isDirty())
66 myTime = timedep ?
t : 0.0;
74 if (!myRefCount.add(-1))
85 { myMatNetName = mat_path; }
87 {
return myMatNetName; }
90 void dirtyMatNet(
bool dirty =
true) { myMatNetDirty = dirty; }
95 void setOverrides(
const UT_Options *overrides);
97 bool hasOverrides()
const {
return myOverrides.getNumOptions()>0; }
101 { myVertexOverrides = ovr; }
103 {
return myVertexOverrides; }
113 void setMaterialType(RE_MaterialType
type);
120 void assignShaderRef(
int shader_program_id,
132 void clearDiffuseMap();
134 void reserveDiffuseLayers(
int nlayers);
168 bool mat_changed =
true);
172 bool mat_change =
true);
174 bool mat_change =
true);
176 bool mat_change =
true);
178 bool mat_change =
true);
180 bool mat_change =
true);
182 bool mat_change =
true);
184 bool mat_change =
true);
186 bool mat_change =
true);
188 bool mat_change =
true);
190 bool mat_change =
true);
192 bool mat_change =
true);
194 bool mat_change =
true);
212 static bool fetchRegOrUDIM(
const UT_StringRef &tex_name,
215 bool allow_preload =
false,
216 const char *uvtile_marker =
nullptr);
220 void clearTextureLayer(
int layer);
225 bool hasBumpMap()
const {
return myBumpMap.myTex.isValid(); }
229 bool hasEnvMap()
const {
return myEnvMap.myTex.isValid(); }
231 {
return myEmissionMap.myTex.isValid(); }
233 {
return myRoughMap.myTex.isValid(); }
235 {
return myOcclusionMap.myTex.isValid(); }
237 {
return myMetallicMap.myTex.isValid(); }
239 {
return myCoatRoughMap.myTex.isValid(); }
241 {
return myCoatIntMap.myTex.isValid(); }
243 {
return myReflectAmountMap.myTex.isValid(); }
246 {
return myHairDiffMap.myTex.isValid(); }
248 {
return myHairSpecMap.myTex.isValid(); }
250 {
return myHairDiffRamp.myTex.isValid(); }
252 {
return myHairSpecRamp.myTex.isValid(); }
254 {
return myHairAlphaRamp.myTex.isValid(); }
258 bool isTransparent(
bool check_diffuse_alpha)
const;
273 void setNumMatXTextures(
int num);
281 bool checkForCacheUpdate(
int cache_serial,
fpreal t);
298 void limitTextureSize(
bool limit,
int w,
int h);
304 void setTextureScale(
float sc);
307 void setTextureMemLimitMB(
int mem);
310 void mipMapTextures(
bool yes);
313 void setAnisotropySamples(
int samp);
320 void doLighting(
bool yes );
321 bool isLit()
const {
return myDoLighting; }
324 const char *
name =
nullptr,
329 {
return myOwnShader[sht]; }
332 void setShaderSource(
const char *vert_src,
333 const char *geom_src,
334 const char *frag_src,
340 bool hasShaderSource(
const char *vert_src,
341 const char *geom_src,
342 const char *frag_src,
346 void setShaderProgram(
const char *program_file);
347 bool hasShaderProgram(
const char *program_file)
const;
350 {
return myShaderProgramFile.isstring() ||
351 myVertexSource[ptype].isstring() ||
352 myGeometrySource[ptype].isstring() ||
353 myFragmentSource[ptype].isstring(); }
359 float amb(
unsigned idx )
const {
return myAmb[idx]; }
361 float diff(
unsigned idx )
const {
return myDiff[idx]; }
363 float spec(
unsigned idx )
const {
return mySpec[idx]; }
365 float emit(
unsigned idx )
const {
return myEmit[idx]; }
369 float alpha()
const {
return myAlpha; }
378 void setAlpha(
float alpha_perp,
float alpha_para = -1.0 );
387 void setAlphaMode(AlphaMode
mode);
389 {
return myAlphaMode; }
391 void setAlphaCutoff(
fpreal alpha_val);
394 return (myAlphaMode != IGNORE_ALPHA) ? myAlphaCutoff : 0.0;
403 { myShaderAlphaFlag =
enabled; }
407 void setRoughness(
float r );
410 void setShininess(
float sh );
412 void setDiffuseRoughness(
fpreal r);
414 void setAmb(
float r,
float g,
float b );
415 void setDiff(
float r,
float g,
float b );
416 void setSpec(
float r,
float g,
float b );
417 void setEmit(
float r,
float g,
float b );
418 void setMetallic(
float metal);
431 void setSpecularTint(
fpreal t);
434 enum { PHONG=0, BLINN=1, GGX=2, SPEC_ANGLE=3 };
435 void setSpecularModel(
int spec_model);
437 void setCoatSpecularModel(
int spec_model);
439 void setCoatIntensity(
fpreal i);
441 void setCoatRoughness(
fpreal r);
444 void setIOR(
float ior);
447 void setReflection(
float r,
bool explicit_r);
448 fpreal getReflection()
const;
450 void usePackedColor(
bool enable);
451 void useGeometryColor(
bool enable);
461 return myNeedsTangentSpace ||
462 (myNormalMap.myMap &&
463 myNormalMapType == NMLMAP_TANGENT);
469 void setOpacityMapParms(
bool invert,
int component);
470 void setNormalParms(re_NormalMapType
type,
bool bias,
472 bool flip_x,
bool flip_y,
bool flip_z);
480 DISPLACE_VECTOR_OBJECT };
481 void setDisplaceParms(
float scale,
float offset,
float quality,
482 re_Displace vector_space,
bool y_up);
485 void setRoughParms(
bool invert_map,
int component);
486 void setOcclusionParms(
int component);
487 void setMetallicParms(
int component);
488 void setCoatRoughnessParms(
int component);
489 void setCoatIntensityParms(
int component);
490 void setReflectionAmountParms(
int component,
bool affect_ior);
491 void setEmissionParms(
bool use_matcap);
493 bool hasDisplacement()
const;
495 void setUVTransform(RE_TexMapType maptype,
498 void clearUVTransform(RE_TexMapType maptype,
504 void setHairDiffuse(
float intensity,
510 void setHairSpecular(
float intensity,
517 void setHairAlpha(
float alpha,
518 bool use_alpha_ramp);
521 void setHairRandomize(
bool random_hue,
UT_Vector2F hue_range,
524 bool random_spec_int,
530 void clearGameLayers();
531 void setUVTransform(
int layer,
535 void getUVTransform(
int layer,
543 void setUVTriplanar(
int layer,
548 bool isUVTriplanar(
int layer)
const;
549 fpreal getUVTriplanarSharp(
int layer)
const;
550 fpreal getUVTriplanarScale(
int layer)
const;
553 bool getUVLayerUseTint(
int layer)
const;
555 fpreal getUVLayerRough(
int layer)
const;
563 static void clearEnvMapOverride();
579 bool loadTextureMaps(
RE_Render *
r,
bool preload_only =
false);
589 RE_TexMapType maptype,
592 void removeTextureMap(RE_TexMapType maptype,
597 RE_TexMapType maptype,
600 void clearTextureMap(RE_TexMapType maptype,
607 {
return myMaterialType==FILM_SURFACE ?myNumDiffuseLayers :1; }
609 bool updateShaderForMaterial(
615 bool allow_partial =
false);
621 int64 getMemoryUsage(
bool inclusive)
const;
624 void writeMaterialParmsToBlockGL4(
RE_Render *
r,
632 void removeTexturesFromResident(
RE_Render *
r);
636 void updateMaterialBlock(
int layer,
bool textured);
639 {
return myMaterialBlock; }
641 {
return myHairMaterialBlock; }
643 {
return myGameMaterialBlock; }
646 void loadShaderAttribNames();
648 class re_MaterialTextureMap
651 re_MaterialTextureMap()
652 : myMap(nullptr), myMapIndex(-1),
653 myArrayMapIndex(-1), myTexCoords(0), myComponent(0),
654 myExplicitMap(false), myOwnMap(false) {}
655 ~re_MaterialTextureMap()
672 re_MaterialTextureMap *fetchMapInfo(RE_TexMapType
t,
676 bool preload_only =
false,
679 RE_TexMapType map_target,
680 re_MaterialTextureMap &map,
682 bool promote_1chan_to_rgb =
false);
684 bool bindTextureMap(
RE_Render *
r, re_MaterialTextureMap &map,
685 const char *udim_stride_name,
687 const char *component_name =
nullptr);
688 void bindUVTransform(RE_TexMapType
type,
690 void bindComponentAndUDIM(re_MaterialTextureMap &map,
691 const char *udim_area_name,
692 const char *component_name =
nullptr);
693 void bindTextureMaps(
RE_Render *
r,
int layer);
697 void updateHairMaterialForShader(
RE_Render *
r,
701 void updateGameMaterialForShader(
RE_Render *
r,
710 re_MaterialTextureMap &map,
713 const char *texture_name);
717 const re_MaterialTextureMap &map)
const;
728 float myDiffRoughness;
730 RE_MaterialType myMaterialType;
731 AlphaMode myAlphaMode;
740 re_MaterialTextureMap mySpecMap;
741 re_MaterialTextureMap myOpacityMap;
742 re_MaterialTextureMap myBumpMap;
743 re_MaterialTextureMap myRoughMap;
744 re_MaterialTextureMap myEmissionMap;
745 re_MaterialTextureMap myNormalMap;
746 re_MaterialTextureMap myDisplaceMap;
747 re_MaterialTextureMap myOcclusionMap;
748 re_MaterialTextureMap myMetallicMap;
749 re_MaterialTextureMap myCoatRoughMap;
750 re_MaterialTextureMap myCoatIntMap;
751 re_MaterialTextureMap myReflectAmountMap;
752 re_MaterialTextureMap myGameBlendMap;
753 re_MaterialTextureMap myEnvMap;
754 re_MaterialTextureMap myHairDiffMap;
755 re_MaterialTextureMap myHairSpecMap;
756 re_MaterialTextureMap myHairDiffRamp;
757 re_MaterialTextureMap myHairSpecRamp;
758 re_MaterialTextureMap myHairAlphaRamp;
775 unsigned myDoLighting:1,
777 myLimitTextureSize:1,
780 myTrivialTextureAlpha:1,
783 myTextureLoadPending:1,
784 myCustomShaderDirty:1,
790 myNeedsTangentSpace:1;
791 int myTextureAnisotropy;
792 int myNumDiffuseLayers;
795 int myMaxTextureW, myMaxTextureH;
796 float myTextureScale;
797 int myTextureMemLimitMB;
799 bool myShaderAlphaFlag;
801 bool myUsePackedColor;
809 bool myExplicitReflection;
822 re_NormalMapType myNormalMapType;
830 float myDisplaceScale;
831 float myDisplaceOffset;
832 float myDisplaceQuality;
833 re_Displace myDisplaceSpace;
837 bool myOpacityMapInvert;
841 bool myEmissionMatCap;
852 int myMaterialOverride;
853 bool myMatBlockDirty;
854 bool myMatBlockHasEnvMapTexture;
855 bool myMatBlockHasReflectMapTexture;
856 bool myMatBlockHasDiffuseTexture;
860 int myTextureCacheSerial;
863 class re_HairCompParms
866 re_HairCompParms() : intensity(0.5), shift(0.0),
angle(1.0),
867 root_col(1,1,1), tip_col(1,1,1),
868 use_ramp(false), use_map(false) {}
877 struct re_HairRandomParms
879 re_HairRandomParms() : randomize(false) {}
884 bool myHairMaterialEnabled;
885 re_HairCompParms myHairDiffuse;
886 re_HairCompParms myHairSpecular;
888 bool myHairUseAlphaRamp;
889 re_HairRandomParms myHairRandomDiffHue;
890 re_HairRandomParms myHairRandomDiffSat;
891 re_HairRandomParms myHairRandomDiffInt;
892 re_HairRandomParms myHairRandomSpecInt;
894 int myHairMatBlockIndex;
895 int myHairRandomTextureIndex;
896 int myHairDiffBaseMapIndex;
904 int myMatBlockDiffuseIndex;
905 int myMatBlockDiffuseArrayIndex;
907 int myMatBlockEnvMapIndex;
908 int myMatBlockReflectMapIndex;
910 int myHairMaterialOverride;
913 void *myLastHairShader;
914 int myLastHairShaderSerial;
916 int myHairDiffArrayIndex;
918 int myHairSpecArrayIndex;
919 int myHairDiffRampIndex;
920 int myHairSpecRampIndex;
921 int myHairAlphaRampIndex;
922 int myMatBlockHairIndex;
926 int myGameMaterialOverride;
930 re_GameLayer() : triplanar(false),
scale(1,1),
trans(0,0),
rot(0),
932 tpblend(1,1,1), tpoff(0,0,0), use_tint(false),
933 tint(1.0, 1.0, 1.0, 1.0), rough(1.0) {}
949 int myLastGameShaderSerial;
950 int myGameBlendIndex;
951 int myGameMatBlockIndex;
953 int myPrevSeamlessCubeMap;
968 re_UVTransform() :
transform(1.0), identity(true) {}
1005 if(cache_serial != myTextureCacheSerial)
1007 myTextureCacheSerial = cache_serial;
1008 myNeedsTexUpdate =
true;
1013 myNeedsTexUpdate =
true;
1033 return myShader[sht];
1034 if(myShaderRef[sht] != 0)
1043 return myShaderRef[sht];
1055 {
return myDefault; }
1059 {
return myFactory; }
1065 if(material_id == -1)
1066 return myDefault ? myDefault : myFactory;
1069 return entry->second;
1077 { (*this)[ material->getUniqueId() ] = material; }
1082 { myDefault = material;
if(add_list && material)
add(material); }
1087 { myFactory = material;
if(add_list && material)
add(material); }
void setDiffuse(UT_Color col)
bool mipMapTextures() const
void setTextured(bool has_tex)
bool hasOverrides() const
bool hasHairDiffuseMap() const
void setNeedsUVs(bool uvs)
float getDisplaceLOD() const
bool hasOpacityMap() const
const UT_StringHolder & getNodePath() const
void dirty(bool dirty=true)
bool isTimeDependent() const
SIM_API const UT_StringHolder angle
void setMatNetName(const UT_StringRef &mat_path)
GA_API const UT_StringHolder uv
GT_API const UT_StringHolder time
GLsizei const GLchar *const * path
const RE_UniformBlockHandle & hairBlock() const
GA_API const UT_StringHolder rot
bool isMatCapTextured() const
void setEmit(float r, float g, float b)
int getSpecularModel() const
constexpr SYS_FORCE_INLINE T & z() noexcept
bool areTexturesPending()
void setShaderAlpha(bool enabled)
bool hasShaderAlpha() const
const RE_MaterialPtr & getDefaultMaterial() const
bool hasTessellation() const
void setSpecular(UT_Color col)
bool hasCoatIntensityMap() const
const UT_Options & getOverrides() const
void setSpec(float r, float g, float b)
GLenum GLenum GLsizei const GLuint GLboolean enabled
bool hasRoughnessMap() const
fpreal getCurrentTime() const
int getTextureMemLimitMB() const
const UT_StringMap< UT_StringHolder > & vertexOverrides() const
void setAmb(float r, float g, float b)
int getAnisotropySamples() const
bool isShaderOwned(RE_ShaderTarget sht=RE_SHADER_TARGET_TRIANGLE) const
static RE_Shader * lookupProgram(int id)
GLenum GLuint GLint GLint layer
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
bool needsTangentSpace() const
bool isMatNetDirty() const
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
RE_MaterialType getMaterialType() const
GA_API const UT_StringHolder scale
bool hasHairSpecularRamp() const
float amb(unsigned idx) const
DEP_MicroNode & dependencies()
void setFactoryMaterial(const RE_MaterialPtr &material, bool add_list=true)
const RE_UniformBlockHandle & materialBlock() const
void intrusive_ptr_release(T *x)
bool hasDisplaceMap() const
int getCoatSpecuarModel() const
const RE_UniformBlockHandle & gameMatBlock() const
GA_API const UT_StringHolder trans
bool hasHairDiffuseRamp() const
bool hasReflectionAmountMap() const
void setMatXNodeVersion(int64 version)
bool hasNormalMap() const
void setReflectionMap(RE_Texture *map)
bool usePackedColor() const
bool limitTextureSize() const
GLint GLint GLsizei GLint GLenum format
void setTimeDependent(bool timedep, fpreal t=0.0)
RE_Shader * getShader(RE_ShaderTarget sht=RE_SHADER_TARGET_TRIANGLE) const
bool customShaderDirty() const
bool hasMetallicMap() const
bool hasDisplacement() const
GLfloat GLfloat GLfloat alpha
const UT_StringRef & getMatNetName() const
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
GA_API const UT_StringHolder transform
void setEmission(UT_Color col)
fpreal getCoatIntensity() const
bool hasOcclusionMap() const
void markDefaultShader(bool def)
bool hasSpecularMap() const
bool allowShaders() const
void enableHairParameters(bool e)
float diff(unsigned idx) const
GT_API const UT_StringHolder version
void setDefaultMaterial(const RE_MaterialPtr &material, bool add_list=true)
UT_Vector3T< fpreal32 > UT_Vector3F
float emit(unsigned idx) const
float coatRoughness() const
GLfloat GLfloat GLfloat GLfloat h
A map of string to various well defined value types.
AlphaMode getAlphaMode() const
float diffuseRoughness() const
bool hasCoatRoughnessMap() const
float spec(unsigned idx) const
float coatIntensity() const
void intrusive_ptr_add_ref(T *x)
void setDiff(float r, float g, float b)
void clearReflectionMap()
const RE_MaterialPtr & getFactoryMaterial() const
bool useGeometryColor() const
bool checkForCacheUpdate(int cache_serial, fpreal t)
void setVertexOverrides(const UT_StringMap< UT_StringHolder > &ovr)
UT_Vector3F metallicEdgeTint() const
bool hasHairAlphaRamp() const
void setDisplaceLOD(float lod)
bool hasEmissionMap() const
void preloadMapsOnly(bool preload)
RE_TextureCompress getTextureFormat() const
void setAmbient(UT_Color col)
void dirtyMatNet(bool dirty=true)
void setNeedsTangentSpace(bool b)
const UT_StringHolder & getMaterialName() const
MX_RENDER_API ShaderPtr createShader(const string &shaderName, GenContext &context, ElementPtr elem)
Create a shader for a given element.
fpreal getAlphaCutoff() const
GLubyte GLubyte GLubyte GLubyte w
Simple class for a mutli-integer cache tag.
void add(const RE_MaterialPtr &material)
int64 getMatXNodeVersion() const
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void getMaxTextureSize(int &w, int &h)
bool hasExplicitReflection() const
constexpr SYS_FORCE_INLINE T & y() noexcept
bool SYSisEqual(const UT_Vector2T< T > &a, const UT_Vector2T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
bool isDirty(fpreal time) const
fpreal getCoatRoughness() const
Base::const_iterator const_iterator
int getNumDiffuseLayers() const
bool hasHairSpecularMap() const
void setTransparent(bool alpha)
float getTextureScale() const
RE_MaterialTextureBinding
bool needsTextureUpdate() const
bool isDefaultShader() const
fpreal getSpecularTint() const
void allowShaders(bool yes)
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
int getShaderRefID(RE_ShaderTarget ptype=RE_SHADER_TARGET_TRIANGLE) const
bool hasCustomShader(RE_ShaderTarget ptype=RE_SHADER_TARGET_TRIANGLE) const
constexpr SYS_FORCE_INLINE T & x() noexcept