![]() |
Skylicht Engine
|
The object class describes material information such as which shader it's associated with, which texture it uses, and what its color parameters are. More...
#include <Material/CMaterial.h>
Classes | |
| struct | SUniformTexture |
| Structure for a uniform texture parameter in the material. More... | |
| struct | SUniformValue |
| Structure for a uniform value parameter in the material. More... | |
| struct | SExtraParams |
| Structure for storing extra parameters, used when switching shaders. More... | |
Public Member Functions | |
| CMaterial (const char *name, const char *shaderPath) | |
| Constructs a material with the given name and shader path. | |
| virtual | ~CMaterial () |
| Destructor. Releases textures, deletes all parameters and cleans up resources. | |
| CShader * | getShader () |
| Get the shader associated with this material. | |
| void | rename (const char *name) |
| Rename the material. | |
| const char * | getName () |
| Get the name of the material. | |
| const char * | getPackage () |
| Get the package name of the material. | |
| void | setPackage (const char *package) |
| Set the package name for the material. | |
| const char * | getShaderPath () |
| Get the shader path of the material. | |
| const char * | getMaterialPath () |
| Get the material file path. | |
| void | setMaterialPath (const char *path) |
| Set the material file path. | |
| bool | isDeferred () |
| Returns true if the material is used for deferred rendering. | |
| void | setManualInitTexture (bool b) |
| Set manual initialization flag for textures. | |
| CMaterial * | clone () |
| Create a deep clone of this material. | |
| void | copyTo (CMaterial *mat) |
| Copy all parameters and resources to another material. | |
| void | copyParamsTo (CMaterial *mat) |
| Copy only uniform parameters to another material. | |
| void | deleteAllParams () |
| Delete all uniform parameters and textures. | |
| void | deleteExtraParams () |
| Delete all extra parameters (used for shader switching). | |
| void | setUniform (const char *name, float f) |
| Set a float value for a named uniform. | |
| void | setUniform2 (const char *name, float *f) |
| Set a vec2 value for a named uniform. | |
| void | setUniform3 (const char *name, float *f) |
| Set a vec3 value for a named uniform. | |
| void | setUniform4 (const char *name, float *f) |
| Set a vec4 value for a named uniform. | |
| void | setUniform4 (const char *name, const SColor &color) |
| Set a vec4 value for a named uniform from an SColor. | |
| const char * | getUniformTextureName (int slot) |
| Get the name of a uniform texture by slot index. | |
| void | setUniformTexture (const char *name, const char *path, bool loadTexture=true) |
| Set a uniform texture by name and path, optionally loading the texture. | |
| 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 | setUniformTexture (const char *name, ITexture *texture) |
| Set a uniform texture by name, using an ITexture pointer. | |
| void | setUniformTextureWrapU (const char *name, int wrapU) |
| Set the wrapping mode in U direction for a uniform texture. | |
| void | setUniformTextureWrapV (const char *name, int wrapV) |
| Set the wrapping mode in V direction for a uniform texture. | |
| SExtraParams * | newExtra (const char *shaderPath) |
| Create a new extra parameter block for a specific shader path. | |
| void | setExtraUniformTexture (SExtraParams *e, const char *name, const char *path) |
| Set the path for an extra uniform texture. | |
| void | setExtraUniform (SExtraParams *e, const char *name, float *f, int floatSize) |
| Set a value for an extra uniform. | |
| void | setExtraUniformTextureWrapU (SExtraParams *e, const char *name, int wrapU) |
| Set wrapping mode U for extra uniform texture. | |
| void | setExtraUniformTextureWrapV (SExtraParams *e, const char *name, int wrapV) |
| Set wrapping mode V for extra uniform texture. | |
| std::vector< SUniformValue * > & | getUniformParams () |
| Get a reference to the uniform value parameters vector. | |
| std::vector< SUniformTexture * > & | getUniformTexture () |
| Get a reference to the uniform texture parameters vector. | |
| std::vector< SExtraParams * > & | getExtraParams () |
| Get a reference to the extra parameters vector. | |
| void | setBackfaceCulling (bool b) |
| Enable or disable backface culling for the material. | |
| bool | isBackfaceCulling () |
| Returns whether backface culling is enabled. | |
| void | setFrontfaceCulling (bool b) |
| Enable or disable frontface culling for the material. | |
| bool | isFrontfaceCulling () |
| Returns whether frontface culling is enabled. | |
| void | setZWrite (bool b) |
| Enable or disable Z-buffer writing for the material. | |
| bool | isZWrite () |
| Returns whether Z-buffer writing is enabled. | |
| void | setZTest (video::E_COMPARISON_FUNC f) |
| Set the Z-buffer comparison function. | |
| video::E_COMPARISON_FUNC | getZTest () |
| Get the Z-buffer comparison function. | |
| SUniformValue * | getUniform (const char *name) |
| Get a uniform value by name (creates if not found). | |
| SUniformTexture * | getUniformTexture (const char *name) |
| Get a uniform texture by name (creates if not found). | |
| SUniformValue * | getExtraUniform (SExtraParams *e, const char *name) |
| Get an extra uniform value by name (creates if not found). | |
| SUniformTexture * | getExtraUniformTexture (SExtraParams *e, const char *name) |
| Get an extra uniform texture by name (creates if not found). | |
| CShaderParams & | getShaderParams () |
| Get the shader parameter set for this material. | |
| bool | haveUniform (const char *name) |
| Returns true if the uniform with the given name exists. | |
| void | initMaterial () |
| Initializes the material by loading the shader and setting up all parameters. | |
| void | setTexture (ITexture **textures, int num) |
| Set textures for all slots using an array. | |
| void | setTexture (int slot, ITexture *texture) |
| Set the texture for a specific slot. | |
| ITexture * | getTexture (int slot) |
| Get the texture assigned to a slot. | |
| void | setProperty (const std::string &name, const std::string &value) |
| Set a material property by name. | |
| std::string | getProperty (const std::string &name) |
| Get a material property value by name. | |
| void | loadDefaultTexture () |
| Load default textures specified by the shader. | |
| void | loadUniformTexture () |
| Load all uniform textures assigned to this material. | |
| void | unloadDefaultTexture () |
| Unload all default textures. | |
| void | unloadUniformTexture () |
| Unload all uniform textures. | |
| void | unloadUniformTexture (const char *name) |
| Unload a specific uniform texture by name. | |
| void | setOverrideResource (ITexture *texture, CShader::EResourceType type) |
| Override a resource texture for this material. | |
| void | changeShader (CShader *shader) |
| Change the shader for this material. | |
| void | changeShader (const char *path) |
| Change the shader for this material using a path. | |
| bool | autoDetectLoadTexture () |
| Automatically detect and load textures based on shader and uniform settings. | |
| void | applyMaterial () |
| Apply material properties and textures internally (no arguments). | |
| void | applyMaterial (SMaterial &mat) |
| Update textures for the passed SMaterial. | |
| void | updateTexture (SMaterial &mat) |
| Replace a texture resource with a new texture in all relevant slots and uniforms. | |
| void | replaceTexture (ITexture *oldTexture, ITexture *newTexture) |
| Replace a texture resource with a new texture in all relevant slots and uniforms. | |
| void | updateShaderParams () |
| Update internal shader parameter values based on uniforms. | |
| Public Member Functions inherited from irr::IReferenceCounted | |
| IReferenceCounted () | |
| Constructor. | |
| virtual | ~IReferenceCounted () |
| Destructor. | |
| void | grab () const |
| Grabs the object. Increments the reference counter by one. | |
| bool | drop () const |
| Drops the object. Decrements the reference counter by one. | |
| s32 | getReferenceCount () const |
| Get the reference count. | |
| const c8 * | getDebugName () const |
| Returns the debug name of the object. | |
Protected Member Functions | |
| void | bindUniformParam () |
| Bind uniform parameter slots to shader uniforms. | |
| void | updateSetTextureSlot () |
| Update and assign texture slots for all uniforms. | |
| void | initDefaultValue () |
| Initialize default values for material uniforms based on shader defaults. | |
| void | setDefaultValue (SUniformValue *v, SUniform *u) |
| Set default value for a uniform value using shader information. | |
| SUniformValue * | newUniform (const char *name, int floatSize) |
| Create a new uniform value with given name and float size. | |
| SUniformTexture * | newUniformTexture (const char *name) |
| Create a new uniform texture with given name. | |
| SUniformTexture * | newExtraUniformTexture (SExtraParams *e, const char *name) |
| Create a new extra uniform texture for a specific extra parameter block. | |
| SUniformValue * | newExtraUniform (SExtraParams *e, const char *name, int floatSize) |
| Create a new extra uniform value for a specific extra parameter block. | |
| void | addShaderUI (CShader::SUniformUI *ui) |
| Add a shader UI control (from shader XML) to the material's uniforms. | |
| SExtraParams * | getExtraParams (const char *shaderPath) |
| Get extra parameter block by shader path. | |
| void | saveExtraParams () |
| Save extra parameters for the current shader path. | |
| void | reloadExtraParams (const char *shaderPath) |
| Reload extra parameters for the given shader path. | |
| SUniformTexture * | findExtraTexture (const char *name) |
| Find an extra texture by name among all extra parameter blocks. | |
| SUniformValue * | findExtraParam (const char *name, int floatSize) |
| Find an extra uniform value by name and float size among all extra parameter blocks. | |
| Protected Member Functions inherited from irr::IReferenceCounted | |
| void | setDebugName (const c8 *newName) |
| Sets the debug name of the object. | |
The object class describes material information such as which shader it's associated with, which texture it uses, and what its color parameters are.
Skylicht-Editor
You can create materials in two ways
Method 1: Select the model file (.fbx, .dae) and click the "Export Material" button
Method 2: Create it manually by choosing the menu Asset/Create/Material.
Adjusting materials:
The Material Property window allows you to add multiple materials within a .mat file. It also includes functions like delete/rename.
Next, drag the shader .xml file into the Shader Field to select the material's shader.
From there, you can then drag texture files into the various uniform textures, or adjust the parameters defined within the shader .xml.
Materials are essential for the CRenderMesh component to display the model's appearance on the Skylicht-Engine
You use CMaterialManager to support loading .mat material files.
| Skylicht::CMaterial::CMaterial | ( | const char * | name, |
| const char * | shaderPath ) |
Constructs a material with the given name and shader path.
| name | Name of the material. |
| shaderPath | Path to the shader file. |
|
protected |
| void Skylicht::CMaterial::applyMaterial | ( | SMaterial & | mat | ) |
| bool Skylicht::CMaterial::autoDetectLoadTexture | ( | ) |
Automatically detect and load textures based on shader and uniform settings.
| void Skylicht::CMaterial::changeShader | ( | const char * | path | ) |
Change the shader for this material using a path.
| path | Path to new shader file. |
| void Skylicht::CMaterial::changeShader | ( | CShader * | shader | ) |
Change the shader for this material.
| shader | Pointer to new shader. |
| CMaterial * Skylicht::CMaterial::clone | ( | ) |
Create a deep clone of this material.
| void Skylicht::CMaterial::copyParamsTo | ( | CMaterial * | mat | ) |
Copy only uniform parameters to another material.
| mat | Target material to copy parameters to. |
| void Skylicht::CMaterial::copyTo | ( | CMaterial * | mat | ) |
Copy all parameters and resources to another material.
| mat | Target material to copy parameters to. |
|
protected |
Find an extra uniform value by name and float size among all extra parameter blocks.
| name | Uniform name. |
| floatSize | Number of floats. |
|
protected |
Find an extra texture by name among all extra parameter blocks.
| name | Uniform texture name. |
|
inline |
Get a reference to the extra parameters vector.
|
protected |
Get extra parameter block by shader path.
| shaderPath | Shader path string. |
| SUniformValue * Skylicht::CMaterial::getExtraUniform | ( | SExtraParams * | e, |
| const char * | name ) |
Get an extra uniform value by name (creates if not found).
| e | Pointer to extra parameter block. |
| name | Uniform name. |
| SUniformTexture * Skylicht::CMaterial::getExtraUniformTexture | ( | SExtraParams * | e, |
| const char * | name ) |
Get an extra uniform texture by name (creates if not found).
| e | Pointer to extra parameter block. |
| name | Uniform texture name. |
|
inline |
Get the material file path.
|
inline |
Get the name of the material.
|
inline |
| std::string Skylicht::CMaterial::getProperty | ( | const std::string & | name | ) |
Get a material property value by name.
| name | Property name. |
|
inline |
Get the shader associated with this material.
|
inline |
Get the shader parameter set for this material.
|
inline |
Get the shader path of the material.
| ITexture * Skylicht::CMaterial::getTexture | ( | int | slot | ) |
Get the texture assigned to a slot.
| slot | Slot index. |
| SUniformValue * Skylicht::CMaterial::getUniform | ( | const char * | name | ) |
Get a uniform value by name (creates if not found).
| name | Name of the uniform. |
|
inline |
Get a reference to the uniform value parameters vector.
|
inline |
Get a reference to the uniform texture parameters vector.
| SUniformTexture * Skylicht::CMaterial::getUniformTexture | ( | const char * | name | ) |
Get a uniform texture by name (creates if not found).
| name | Name of the uniform texture. |
| const char * Skylicht::CMaterial::getUniformTextureName | ( | int | slot | ) |
Get the name of a uniform texture by slot index.
| slot | Texture slot index. |
|
inline |
Get the Z-buffer comparison function.
| bool Skylicht::CMaterial::haveUniform | ( | const char * | name | ) |
Returns true if the uniform with the given name exists.
| name | Uniform name. |
|
inline |
Returns whether backface culling is enabled.
|
inline |
Returns true if the material is used for deferred rendering.
|
inline |
Returns whether frontface culling is enabled.
|
inline |
Returns whether Z-buffer writing is enabled.
| SExtraParams * Skylicht::CMaterial::newExtra | ( | const char * | shaderPath | ) |
Create a new extra parameter block for a specific shader path.
| shaderPath | Shader path string. |
|
protected |
Create a new extra uniform value for a specific extra parameter block.
| e | Pointer to extra parameter block. |
| name | Name of the uniform. |
| floatSize | Number of floats. |
|
protected |
Create a new extra uniform texture for a specific extra parameter block.
| e | Pointer to extra parameter block. |
| name | Name of the uniform texture. |
|
protected |
Create a new uniform value with given name and float size.
| name | Name of the uniform. |
| floatSize | Number of floats. |
|
protected |
Create a new uniform texture with given name.
| name | Name of the uniform texture. |
|
protected |
Reload extra parameters for the given shader path.
| shaderPath | Shader path string. |
|
inline |
Rename the material.
| name | New name for the material. |
Replace a texture resource with a new texture in all relevant slots and uniforms.
| oldTexture | Pointer to old texture. |
| newTexture | Pointer to new texture. |
|
inline |
Enable or disable backface culling for the material.
| b | True to enable, false to disable. |
|
protected |
Set default value for a uniform value using shader information.
| v | Pointer to SUniformValue. |
| u | Pointer to SUniform. |
| void Skylicht::CMaterial::setExtraUniform | ( | SExtraParams * | e, |
| const char * | name, | ||
| float * | f, | ||
| int | floatSize ) |
Set a value for an extra uniform.
| e | Pointer to extra parameter block. |
| name | Uniform name. |
| f | Pointer to value array. |
| floatSize | Number of floats. |
| void Skylicht::CMaterial::setExtraUniformTexture | ( | SExtraParams * | e, |
| const char * | name, | ||
| const char * | path ) |
Set the path for an extra uniform texture.
| e | Pointer to extra parameter block. |
| name | Uniform texture name. |
| path | Path to texture. |
| void Skylicht::CMaterial::setExtraUniformTextureWrapU | ( | SExtraParams * | e, |
| const char * | name, | ||
| int | wrapU ) |
Set wrapping mode U for extra uniform texture.
| e | Pointer to extra parameter block. |
| name | Uniform texture name. |
| wrapU | Wrapping mode value. |
| void Skylicht::CMaterial::setExtraUniformTextureWrapV | ( | SExtraParams * | e, |
| const char * | name, | ||
| int | wrapV ) |
Set wrapping mode V for extra uniform texture.
| e | Pointer to extra parameter block. |
| name | Uniform texture name. |
| wrapV | Wrapping mode value. |
|
inline |
Enable or disable frontface culling for the material.
| b | True to enable, false to disable. |
|
inline |
Set manual initialization flag for textures.
| b | True to enable manual initialization. |
|
inline |
Set the material file path.
| path | New material file path string. |
|
inline |
Override a resource texture for this material.
| texture | Pointer to texture. |
| type | Resource type (see CShader::EResourceType). |
|
inline |
Set the package name for the material.
| package | Package name string. |
| void Skylicht::CMaterial::setProperty | ( | const std::string & | name, |
| const std::string & | value ) |
Set a material property by name.
| name | Property name. |
| value | Property value. |
| void Skylicht::CMaterial::setTexture | ( | int | slot, |
| ITexture * | texture ) |
Set the texture for a specific slot.
| slot | Slot index. |
| texture | Pointer to texture. |
| void Skylicht::CMaterial::setTexture | ( | ITexture ** | textures, |
| int | num ) |
Set textures for all slots using an array.
| textures | Array of texture pointers. |
| num | Number of textures. |
| void Skylicht::CMaterial::setUniform | ( | const char * | name, |
| float | f ) |
Set a float value for a named uniform.
| name | Name of the uniform. |
| f | Value to set. |
| void Skylicht::CMaterial::setUniform2 | ( | const char * | name, |
| float * | f ) |
Set a vec2 value for a named uniform.
| name | Name of the uniform. |
| f | Pointer to array of 2 floats. |
| void Skylicht::CMaterial::setUniform3 | ( | const char * | name, |
| float * | f ) |
Set a vec3 value for a named uniform.
| name | Name of the uniform. |
| f | Pointer to array of 3 floats. |
| void Skylicht::CMaterial::setUniform4 | ( | const char * | name, |
| const SColor & | color ) |
Set a vec4 value for a named uniform from an SColor.
| name | Name of the uniform. |
| color | Color value to set. |
| void Skylicht::CMaterial::setUniform4 | ( | const char * | name, |
| float * | f ) |
Set a vec4 value for a named uniform.
| name | Name of the uniform. |
| f | Pointer to array of 4 floats. |
| void Skylicht::CMaterial::setUniformTexture | ( | const char * | name, |
| const char * | path, | ||
| bool | loadTexture = true ) |
Set a uniform texture by name and path, optionally loading the texture.
| name | Uniform texture name. |
| path | Path to texture file. |
| loadTexture | True to load the texture. |
| void Skylicht::CMaterial::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.
| name | Uniform texture name. |
| path | Path to texture file. |
| folder | List of folders to search for the texture. |
| loadTexture | True to load the texture. |
| void Skylicht::CMaterial::setUniformTexture | ( | const char * | name, |
| ITexture * | texture ) |
Set a uniform texture by name, using an ITexture pointer.
| name | Uniform texture name. |
| texture | Pointer to texture. |
| void Skylicht::CMaterial::setUniformTextureWrapU | ( | const char * | name, |
| int | wrapU ) |
Set the wrapping mode in U direction for a uniform texture.
| name | Uniform texture name. |
| wrapU | Wrapping mode value. |
| void Skylicht::CMaterial::setUniformTextureWrapV | ( | const char * | name, |
| int | wrapV ) |
Set the wrapping mode in V direction for a uniform texture.
| name | Uniform texture name. |
| wrapV | Wrapping mode value. |
|
inline |
Set the Z-buffer comparison function.
| f | Comparison function value. |
|
inline |
Enable or disable Z-buffer writing for the material.
| b | True to enable, false to disable. |
| void Skylicht::CMaterial::unloadUniformTexture | ( | const char * | name | ) |
Unload a specific uniform texture by name.
| name | Uniform texture name. |
| void Skylicht::CMaterial::updateTexture | ( | SMaterial & | mat | ) |
Replace a texture resource with a new texture in all relevant slots and uniforms.
| oldTexture | Pointer to old texture. |
| newTexture | Pointer to new texture. |