3 #include <Engine/RaEngine.hpp>
8 #include <Core/Utils/Color.hpp>
9 #include <Engine/Data/Material.hpp>
10 #include <Engine/Data/Texture.hpp>
35 enum class TextureSemantic { TEX_DIFFUSE, TEX_SPECULAR, TEX_NORMAL, TEX_SHININESS, TEX_ALPHA };
38 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
51 void updateGL()
override;
52 void updateFromParameters()
override;
53 bool isTransparent()
const override;
60 inline void addTexture(
const TextureSemantic& semantic,
Texture* texture );
67 inline Texture* getTexture(
const TextureSemantic& semantic )
const;
74 static void registerMaterial();
80 static void unregisterMaterial();
86 inline nlohmann::json getParametersMetadata()
const override;
88 inline void setColoredByVertexAttrib(
bool state )
override;
90 inline bool isColoredByVertexAttrib()
const override;
96 Scalar m_alpha { 1.0 };
97 bool m_perVertexColor {
false };
98 bool m_renderAsSplat {
false };
106 inline TextureParameters& addTexture(
const TextureSemantic& semantic,
107 const TextureParameters& texture );
110 std::map<TextureSemantic, Texture*> m_textures;
111 std::map<TextureSemantic, TextureParameters> m_pendingTextures;
112 static nlohmann::json s_parametersMetadata;
120 inline TextureParameters& addTexture(
const TextureSemantic& semantic,
121 const std::string& texture );
126 void updateRenderingParameters();
143 m_textures[semantic] = texture;
146 m_pendingTextures.erase( semantic );
151 const std::string& texture ) {
152 CORE_ASSERT( !texture.empty(),
"Invalid texture name" );
156 data.
wrapS = GL_REPEAT;
157 data.
wrapT = GL_REPEAT;
158 if ( semantic != TextureSemantic::TEX_NORMAL ) { data.
minFilter = GL_LINEAR_MIPMAP_LINEAR; }
167 m_pendingTextures[semantic] = texture;
170 return m_pendingTextures[semantic];
176 auto it = m_textures.find( semantic );
177 if ( it != m_textures.end() ) { tex = it->second; }
183 return s_parametersMetadata;
187 bool oldState = m_perVertexColor;
188 m_perVertexColor = state;
189 if ( oldState != m_perVertexColor ) {
needUpdate(); }
193 return m_perVertexColor;
represent material data loaded by a file loader. Material data must be identified by a unique name....
bool isColoredByVertexAttrib() const override
Indicates if the material takes the VERTEX_COLOR attribute into account.
void addTexture(const TextureSemantic &semantic, Texture *texture)
TextureSemantic
Semantic of the texture : define which BSDF parameter is controled by the texture.
Texture * getTexture(const TextureSemantic &semantic) const
void setColoredByVertexAttrib(bool state) override
Makes the Material take its base color from the VERTEX_COLOR attribute of the rendered geometry.
nlohmann::json getParametersMetadata() const override
GLenum wrapT
OpenGL wrap mode in the t direction.
GLenum wrapS
OpenGL wrap mode in the s direction.
GLenum minFilter
OpenGL minification filter ( GL_LINEAR or GL_NEAREST or GL_XXX_MIPMAP_YYY )
std::string name
Name of the texture.