17 #ifndef GZ_RENDERING_BASE_BASEMATERIAL_HH_
18 #define GZ_RENDERING_BASE_BASEMATERIAL_HH_
23 #include "gz/common/Console.hh"
33 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
52 public:
virtual void SetAmbient(
const double _r,
const double _g,
53 const double _b,
const double _a = 1.0)
override;
56 public:
virtual void SetAmbient(
const math::Color &_color)
override;
59 public:
virtual void SetDiffuse(
const double _r,
const double _g,
60 const double _b,
const double _a = 1.0)
override;
63 public:
virtual void SetDiffuse(
const math::Color &_color)
override;
66 public:
virtual void SetSpecular(
const double _r,
const double _g,
67 const double _b,
const double _a = 1.0)
override;
70 public:
virtual void SetSpecular(
const math::Color &_color)
override;
73 public:
virtual void SetEmissive(
const double _r,
const double _g,
74 const double _b,
const double _a = 1.0)
override;
77 public:
virtual void SetEmissive(
const math::Color &_color)
override;
80 public:
virtual void SetTransparency(
const double _transparency)
override;
83 public:
virtual void SetAlphaFromTexture(
bool _enabled,
84 double _alpha = 0.5,
bool _twoSided =
true)
override;
87 public:
bool TextureAlphaEnabled()
const override;
90 public:
double AlphaThreshold()
const override;
93 public:
bool TwoSidedEnabled()
const override;
96 public:
virtual void SetShininess(
const double _shininess)
override;
99 public:
virtual void SetReflectivity(
const double _reflectivity)
override;
102 public:
virtual void SetCastShadows(
const bool _castShadows)
override;
105 public:
virtual void SetReceiveShadows(
const bool _receiveShadows)
109 public:
virtual void SetReflectionEnabled(
const bool _enabled)
override;
112 public:
virtual void SetLightingEnabled(
const bool _enabled)
override;
115 public:
virtual void SetDepthCheckEnabled(
bool _enabled)
override;
118 public:
virtual void SetDepthWriteEnabled(
bool _enabled)
override;
121 public:
virtual math::Color Ambient()
const override;
124 public:
virtual math::Color Diffuse()
const override;
127 public:
virtual math::Color Specular()
const override;
130 public:
virtual math::Color Emissive()
const override;
133 public:
virtual double Transparency()
const override;
136 public:
virtual double Reflectivity()
const override;
139 public:
virtual double Shininess()
const override;
142 public:
virtual bool CastShadows()
const override;
145 public:
virtual bool ReceiveShadows()
const override;
148 public:
virtual bool LightingEnabled()
const override;
151 public:
virtual bool DepthCheckEnabled()
const override;
154 public:
virtual bool DepthWriteEnabled()
const override;
157 public:
virtual bool ReflectionEnabled()
const override;
160 public:
virtual bool HasTexture()
const override;
163 public:
virtual std::string Texture()
const override;
166 public:
virtual void SetTexture(
const std::string &_texture,
174 public:
virtual void ClearTexture()
override;
177 public:
virtual bool HasNormalMap()
const override;
180 public:
virtual std::string NormalMap()
const override;
187 public:
virtual void SetNormalMap(
const std::string &_normalMap,
191 public:
virtual void ClearNormalMap()
override;
194 public:
virtual bool HasRoughnessMap()
const override;
197 public:
virtual std::string RoughnessMap()
const override;
204 public:
virtual void SetRoughnessMap(
const std::string &_roughnessMap,
208 public:
virtual void ClearRoughnessMap()
override;
211 public:
virtual bool HasMetalnessMap()
const override;
214 public:
virtual std::string MetalnessMap()
const override;
221 public:
virtual void SetMetalnessMap(
const std::string &_metalnessMap,
225 public:
virtual void ClearMetalnessMap()
override;
228 public:
virtual bool HasEnvironmentMap()
const override;
231 public:
virtual std::string EnvironmentMap()
const override;
238 public:
virtual void SetEnvironmentMap(
const std::string &_environmentMap,
242 public:
virtual void ClearEnvironmentMap()
override;
245 public:
virtual bool HasEmissiveMap()
const override;
248 public:
virtual std::string EmissiveMap()
const override;
255 public:
virtual void SetEmissiveMap(
const std::string &_emissiveMap,
259 public:
virtual void ClearEmissiveMap()
override;
262 public:
virtual bool HasLightMap()
const override;
265 public:
virtual std::string LightMap()
const override;
268 public:
virtual unsigned int LightMapTexCoordSet()
const override;
271 public:
virtual void SetLightMap(
const std::string &_lightMap,
273 unsigned int _uvSet = 0u)
override;
280 public:
virtual void ClearLightMap()
override;
283 public:
virtual void SetRenderOrder(
const float _renderOrder)
override;
286 public:
virtual float RenderOrder()
const override;
289 public:
virtual void SetRoughness(
const float _roughness)
override;
292 public:
virtual float Roughness()
const override;
295 public:
virtual void SetMetalness(
const float _metalness)
override;
298 public:
virtual float Metalness()
const override;
317 public:
virtual void SetDepthMaterial(
const double far,
318 const double near)
override;
322 public:
virtual std::string VertexShader()
const override;
330 public:
virtual void SetVertexShader(
const std::string &_path)
override;
334 public:
virtual std::string FragmentShader()
const override;
342 public:
virtual void SetFragmentShader(
const std::string &_path)
override;
351 public:
virtual void PreRender()
override;
353 protected:
virtual void Reset();
368 protected:
double transparency = 0.0;
371 protected:
bool textureAlphaEnabled =
false;
374 protected:
double alphaThreshold = 0.5;
377 protected:
bool twoSidedEnabled =
false;
380 protected:
double renderOrder = 0.0;
383 protected:
double shininess = 0.0;
386 protected:
double reflectivity = 0.0;
389 protected:
bool lightingEnabled =
false;
392 protected:
bool depthCheckEnabled =
true;
395 protected:
bool depthWriteEnabled =
true;
398 protected:
bool reflectionEnabled =
false;
401 protected:
bool receiveShadows =
true;
404 protected:
bool castShadows =
true;
422 const double _b,
const double _a)
431 this->ambient = _color;
437 const double _b,
const double _a)
446 this->diffuse = _color;
452 const double _b,
const double _a)
461 this->specular = _color;
467 const double _b,
const double _a)
476 this->emissive = _color;
483 this->shininess = _shininess;
490 this->transparency = _transparency;
498 this->textureAlphaEnabled = _enabled;
499 this->alphaThreshold = _alpha;
500 this->twoSidedEnabled = _twoSided;
507 return this->textureAlphaEnabled;
514 return this->alphaThreshold;
521 return this->twoSidedEnabled;
528 this->reflectivity = _reflectivity;
535 this->reflectionEnabled = _enabled;
542 this->lightingEnabled = _enabled;
549 this->depthCheckEnabled = _enabled;
556 this->depthWriteEnabled = _enabled;
563 this->castShadows = _castShadows;
570 this->receiveShadows = _receive;
577 this->renderOrder = _renderorder;
584 return this->ambient;
591 return this->diffuse;
598 return this->specular;
605 return this->emissive;
612 return this->shininess;
619 return this->transparency;
626 return this->renderOrder;
633 return this->reflectivity;
640 return this->castShadows;
647 return this->receiveShadows;
654 return this->lightingEnabled;
661 return this->depthCheckEnabled;
668 return this->depthWriteEnabled;
675 return this->reflectionEnabled;
1023 auto baseShared = this->shared_from_this();
1026 std::dynamic_pointer_cast<const BaseMaterial<T>>(baseShared);
1028 MaterialPtr material = T::Scene()->CreateMaterial(_name);
1029 material->CopyFrom(thisShared);
1037 this->SetLightingEnabled(_material->LightingEnabled());
1038 this->SetAmbient(_material->Ambient());
1039 this->SetDiffuse(_material->Diffuse());
1040 this->SetSpecular(_material->Specular());
1041 this->SetEmissive(_material->Emissive());
1042 this->SetRenderOrder(_material->RenderOrder());
1043 this->SetShininess(_material->Shininess());
1044 this->SetAlphaFromTexture(_material->TextureAlphaEnabled(),
1045 _material->AlphaThreshold(), _material->TwoSidedEnabled());
1047 this->SetTransparency(_material->Transparency());
1049 this->SetDepthCheckEnabled(_material->DepthCheckEnabled());
1050 this->SetDepthWriteEnabled(_material->DepthWriteEnabled());
1051 this->SetReflectivity(_material->Reflectivity());
1052 this->SetCastShadows(_material->CastShadows());
1053 this->SetReceiveShadows(_material->ReceiveShadows());
1054 this->SetReflectionEnabled(_material->ReflectionEnabled());
1055 this->SetTexture(_material->Texture(), _material->TextureData());
1056 this->SetNormalMap(_material->NormalMap(), _material->NormalMapData());
1057 this->SetRoughnessMap(_material->RoughnessMap(),
1058 _material->RoughnessMapData());
1059 this->SetMetalnessMap(_material->MetalnessMap(),
1060 _material->MetalnessMapData());
1061 this->SetRoughness(_material->Roughness());
1062 this->SetMetalness(_material->Metalness());
1063 this->SetEnvironmentMap(_material->EnvironmentMap(),
1064 _material->EnvironmentMapData());
1065 this->SetEmissiveMap(_material->EmissiveMap(),
1066 _material->EmissiveMapData());
1067 this->SetLightMap(_material->LightMap(), _material->LightMapData(),
1068 _material->LightMapTexCoordSet());
1069 this->SetShaderType(_material->ShaderType());
1070 this->SetVertexShader(_material->VertexShader());
1071 this->SetFragmentShader(_material->FragmentShader());
1078 this->SetLightingEnabled(_material.
Lighting());
1079 this->SetAmbient(_material.
Ambient());
1080 this->SetDiffuse(_material.
Diffuse());
1081 this->SetSpecular(_material.
Specular());
1082 this->SetEmissive(_material.
Emissive());
1083 this->SetShininess(_material.
Shininess());
1089 this->SetReflectivity(0);
1092 this->SetCastShadows(
true);
1094 this->SetReceiveShadows(
true);
1096 this->SetReflectionEnabled(
true);
1098 this->ClearNormalMap();
1108 this->SetRoughness(pbrMat->
Roughness());
1109 this->SetMetalness(pbrMat->
Metalness());
1136 this->SetLightingEnabled(
true);
1137 this->SetDepthCheckEnabled(
true);
1138 this->SetDepthWriteEnabled(
true);
1139 this->SetAmbient(0.3, 0.3, 0.3);
1140 this->SetDiffuse(1.0, 1.0, 1.0);
1141 this->SetSpecular(0.2, 0.2, 0.2);
1142 this->SetEmissive(0, 0, 0);
1143 this->SetRenderOrder(0);
1144 this->SetShininess(1.5);
1145 this->SetTransparency(0);
1146 this->SetReflectivity(0);
1147 this->SetCastShadows(
true);
1148 this->SetReceiveShadows(
true);
1149 this->SetReflectionEnabled(
true);
1150 this->ClearTexture();
1151 this->ClearNormalMap();
1152 this->ClearRoughnessMap();
1153 this->ClearMetalnessMap();
1154 this->ClearEmissiveMap();
1155 this->ClearLightMap();