27#include "Shader/CShaderParams.h"
28#include "Shader/CShader.h"
30#include "GameObject/CGameObject.h"
174 bool ShaderDefaultValue;
187 ShaderDefaultValue =
false;
189 Type = NUM_SHADER_TYPE;
191 memset(FloatValue, 0, 4 *
sizeof(
float));
201 memcpy(c->FloatValue, FloatValue,
sizeof(
float) * 4);
203 c->FloatSize = FloatSize;
204 c->ShaderDefaultValue = ShaderDefaultValue;
206 c->ValueIndex = ValueIndex;
234 std::string m_package;
237 std::string m_materialName;
240 std::string m_shaderPath;
243 std::string m_materialPath;
246 std::vector<SUniformValue*> m_uniformParams;
249 std::vector<SUniformTexture*> m_uniformTextures;
252 std::vector<SExtraParams*> m_extras;
261 ITexture* m_overrideTextures[CShader::ResourceCount];
270 bool m_backfaceCulling;
273 bool m_frontfaceCulling;
285 bool m_manualInitMaterial;
318 m_materialName = name;
327 return m_materialName.c_str();
337 return m_package.c_str();
356 return m_shaderPath.c_str();
365 return m_materialPath.c_str();
374 m_materialPath = path;
392 m_manualInitMaterial = b;
479 void setUniformTexture(
const char* name,
const char* path, std::vector<std::string>& folder,
bool loadTexture =
true);
548 return m_uniformParams;
557 return m_uniformTextures;
575 m_backfaceCulling = b;
584 return m_backfaceCulling;
593 m_frontfaceCulling = b;
602 return m_frontfaceCulling;
620 return m_zWriteEnable;
677 return m_shaderParams;
718 void setProperty(
const std::string& name,
const std::string& value);
760 m_overrideTextures[type] = texture;
907 typedef std::vector<CMaterial*> ArrayMaterial;
void unloadUniformTexture()
Unload all uniform textures.
void setProperty(const std::string &name, const std::string &value)
Set a material property by name.
void setUniformTextureWrapV(const char *name, int wrapV)
Set the wrapping mode in V direction for a uniform texture.
SUniformValue * newUniform(const char *name, int floatSize)
Create a new uniform value with given name and float size.
void setExtraUniform(SExtraParams *e, const char *name, float *f, int floatSize)
Set a value for an extra uniform.
const char * getName()
Get the name of the material.
Definition CMaterial.h:325
void loadDefaultTexture()
Load default textures specified by the shader.
const char * getShaderPath()
Get the shader path of the material.
Definition CMaterial.h:354
void setZWrite(bool b)
Enable or disable Z-buffer writing for the material.
Definition CMaterial.h:609
void setUniform(const char *name, float f)
Set a float value for a named uniform.
CShaderParams & getShaderParams()
Get the shader parameter set for this material.
Definition CMaterial.h:675
bool haveUniform(const char *name)
Returns true if the uniform with the given name exists.
void bindUniformParam()
Bind uniform parameter slots to shader uniforms.
SUniformValue * getUniform(const char *name)
Get a uniform value by name (creates if not found).
void applyMaterial(SMaterial &mat)
Update textures for the passed SMaterial.
void unloadDefaultTexture()
Unload all default textures.
void setUniformTexture(const char *name, const char *path, std::vector< std::string > &folder, bool loadTexture=true)
Set a uniform texture by name and path, searching in specified folders.
void setUniform2(const char *name, float *f)
Set a vec2 value for a named uniform.
void updateShaderParams()
Update internal shader parameter values based on uniforms.
void updateSetTextureSlot()
Update and assign texture slots for all uniforms.
void setUniform3(const char *name, float *f)
Set a vec3 value for a named uniform.
SUniformTexture * newExtraUniformTexture(SExtraParams *e, const char *name)
Create a new extra uniform texture for a specific extra parameter block.
void setManualInitTexture(bool b)
Set manual initialization flag for textures.
Definition CMaterial.h:390
void setExtraUniformTextureWrapU(SExtraParams *e, const char *name, int wrapU)
Set wrapping mode U for extra uniform texture.
void updateTexture(SMaterial &mat)
Replace a texture resource with a new texture in all relevant slots and uniforms.
void setUniform4(const char *name, const SColor &color)
Set a vec4 value for a named uniform from an SColor.
const char * getMaterialPath()
Get the material file path.
Definition CMaterial.h:363
CMaterial(const char *name, const char *shaderPath)
Constructs a material with the given name and shader path.
void deleteAllParams()
Delete all uniform parameters and textures.
void copyParamsTo(CMaterial *mat)
Copy only uniform parameters to another material.
CShader * getShader()
Get the shader associated with this material.
Definition CMaterial.h:307
void copyTo(CMaterial *mat)
Copy all parameters and resources to another material.
void setTexture(ITexture **textures, int num)
Set textures for all slots using an array.
SUniformTexture * findExtraTexture(const char *name)
Find an extra texture by name among all extra parameter blocks.
void replaceTexture(ITexture *oldTexture, ITexture *newTexture)
Replace a texture resource with a new texture in all relevant slots and uniforms.
std::vector< SUniformValue * > & getUniformParams()
Get a reference to the uniform value parameters vector.
Definition CMaterial.h:546
void setDefaultValue(SUniformValue *v, SUniform *u)
Set default value for a uniform value using shader information.
void unloadUniformTexture(const char *name)
Unload a specific uniform texture by name.
bool isBackfaceCulling()
Returns whether backface culling is enabled.
Definition CMaterial.h:582
const char * getPackage()
Get the package name of the material.
Definition CMaterial.h:335
SUniformValue * findExtraParam(const char *name, int floatSize)
Find an extra uniform value by name and float size among all extra parameter blocks.
SUniformTexture * getUniformTexture(const char *name)
Get a uniform texture by name (creates if not found).
bool isFrontfaceCulling()
Returns whether frontface culling is enabled.
Definition CMaterial.h:600
void addShaderUI(CShader::SUniformUI *ui)
Add a shader UI control (from shader XML) to the material's uniforms.
SUniformValue * getExtraUniform(SExtraParams *e, const char *name)
Get an extra uniform value by name (creates if not found).
void reloadExtraParams(const char *shaderPath)
Reload extra parameters for the given shader path.
std::vector< SExtraParams * > & getExtraParams()
Get a reference to the extra parameters vector.
Definition CMaterial.h:564
void changeShader(CShader *shader)
Change the shader for this material.
CMaterial * clone()
Create a deep clone of this material.
const char * getUniformTextureName(int slot)
Get the name of a uniform texture by slot index.
SExtraParams * getExtraParams(const char *shaderPath)
Get extra parameter block by shader path.
void setZTest(video::E_COMPARISON_FUNC f)
Set the Z-buffer comparison function.
Definition CMaterial.h:627
void setFrontfaceCulling(bool b)
Enable or disable frontface culling for the material.
Definition CMaterial.h:591
void setUniformTexture(const char *name, ITexture *texture)
Set a uniform texture by name, using an ITexture pointer.
SUniformTexture * newUniformTexture(const char *name)
Create a new uniform texture with given name.
void applyMaterial()
Apply material properties and textures internally (no arguments).
void setOverrideResource(ITexture *texture, CShader::EResourceType type)
Override a resource texture for this material.
Definition CMaterial.h:758
bool isZWrite()
Returns whether Z-buffer writing is enabled.
Definition CMaterial.h:618
void setPackage(const char *package)
Set the package name for the material.
Definition CMaterial.h:345
void setExtraUniformTextureWrapV(SExtraParams *e, const char *name, int wrapV)
Set wrapping mode V for extra uniform texture.
void setMaterialPath(const char *path)
Set the material file path.
Definition CMaterial.h:372
video::E_COMPARISON_FUNC getZTest()
Get the Z-buffer comparison function.
Definition CMaterial.h:636
bool isDeferred()
Returns true if the material is used for deferred rendering.
Definition CMaterial.h:381
void setTexture(int slot, ITexture *texture)
Set the texture for a specific slot.
std::vector< SUniformTexture * > & getUniformTexture()
Get a reference to the uniform texture parameters vector.
Definition CMaterial.h:555
void setBackfaceCulling(bool b)
Enable or disable backface culling for the material.
Definition CMaterial.h:573
void loadUniformTexture()
Load all uniform textures assigned to this material.
void deleteExtraParams()
Delete all extra parameters (used for shader switching).
void setUniform4(const char *name, float *f)
Set a vec4 value for a named uniform.
void initDefaultValue()
Initialize default values for material uniforms based on shader defaults.
void setExtraUniformTexture(SExtraParams *e, const char *name, const char *path)
Set the path for an extra uniform texture.
void setUniformTextureWrapU(const char *name, int wrapU)
Set the wrapping mode in U direction for a uniform texture.
bool autoDetectLoadTexture()
Automatically detect and load textures based on shader and uniform settings.
void rename(const char *name)
Rename the material.
Definition CMaterial.h:316
void initMaterial()
Initializes the material by loading the shader and setting up all parameters.
ITexture * getTexture(int slot)
Get the texture assigned to a slot.
void changeShader(const char *path)
Change the shader for this material using a path.
SExtraParams * newExtra(const char *shaderPath)
Create a new extra parameter block for a specific shader path.
virtual ~CMaterial()
Destructor. Releases textures, deletes all parameters and cleans up resources.
void saveExtraParams()
Save extra parameters for the current shader path.
std::string getProperty(const std::string &name)
Get a material property value by name.
void setUniformTexture(const char *name, const char *path, bool loadTexture=true)
Set a uniform texture by name and path, optionally loading the texture.
SUniformValue * newExtraUniform(SExtraParams *e, const char *name, int floatSize)
Create a new extra uniform value for a specific extra parameter block.
SUniformTexture * getExtraUniformTexture(SExtraParams *e, const char *name)
Get an extra uniform texture by name (creates if not found).
Represents a programmable shader, including uniforms, UI, resources, instancing and platform-specific...
Definition CShader.h:198
EResourceType
Enum for resource types used in shaders.
Definition CShader.h:220
Definition CShaderParams.h:32
IReferenceCounted()
Constructor.
Definition IReferenceCounted.h:50
Interface of a Video Driver dependent Texture.
Definition ITexture.h:119
Class representing a 32 bit ARGB color.
Definition SColor.h:285
Struct for holding parameters for a material renderer.
Definition SMaterial.h:255
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
EUniformType
Enum for all supported uniform types in shaders. See documentation page: Shader information structure...
Definition CShader.h:39
const u32 MATERIAL_MAX_TEXTURES
Maximum number of texture an SMaterial can have.
Definition SMaterial.h:251
E_COMPARISON_FUNC
Comparison function, e.g. for depth buffer test.
Definition SMaterial.h:63
Structure for a uniform texture parameter in the material.
Definition CMaterial.h:93
bool Bilinear
Bilinear filtering enabled.
Definition CMaterial.h:121
std::string Path
Path to the texture file.
Definition CMaterial.h:98
SUniformTexture * clone()
Creates a deep copy of the uniform texture.
Definition CMaterial.h:141
bool Trilinear
Trilinear filtering enabled.
Definition CMaterial.h:118
int TextureSlot
Texture slot index in the shader.
Definition CMaterial.h:104
int WrapV
Wrapping mode in V direction.
Definition CMaterial.h:112
int Anisotropic
Anisotropic filtering level.
Definition CMaterial.h:115
ITexture * Texture
Pointer to loaded texture resource.
Definition CMaterial.h:101
int WrapU
Wrapping mode in U direction.
Definition CMaterial.h:108
SUniformTexture()
Default constructor initializing default values.
Definition CMaterial.h:126
std::string Name
Name of the uniform texture.
Definition CMaterial.h:95