Class Material
Material descriptor for PBR rendering.More...
#include <Material.h>
Public Types
| Type | Name |
|---|---|
| enum | MatDataType Data type discriminator for material parameters. |
| enum | MatParaType Material parameter types. |
| typedef std::tuple< MatDataType, float, glm::vec3, TextureLib::TextureRes > | MatParamData Parameter data: (type, float, vec3, texture) |
| typedef std::shared_ptr< Material > | MaterialRes Shared pointer to Material (for resource sharing) |
Public Attributes
| Type | Name |
|---|---|
| bool | is_mat_changed = { true }Flag indicating material parameters have changed. |
| bool | is_mat_struct_changed = { true }Flag indicating material structure (data types) has changed. |
| std::string | mat_name = { "Default" }Material name (for debugging and serialization) |
| std::unordered_map< MatParaType, MatParamData > | mat_params Map of material parameters to their data. |
Public Static Attributes
| Type | Name |
|---|---|
| std::vector< std::string > | mat_uniform_name = /* multi line expression */Uniform names for each MatParaType (indexed array) |
Public Functions
| Type | Name |
|---|---|
| void | BindMatTexture () const Binds all material textures to their respective texture units. |
| void | InitParamData () Initializes all material parameters to default values. |
| Material () Default constructor (creates default PBR material). |
|
| void | ParseConfig (const std::string & _config) Parses material configuration from a string. |
| void | SetMatParam (MatParaType _tar, MatDataType _type) Sets the data type for a material parameter. |
| void | SetMatParam (MatParaType _tar, float _var) Sets a material parameter to a float value. |
| void | SetMatParam (MatParaType _tar, glm::vec3 _col) Sets a material parameter to a color value. |
| void | SetMatParam (MatParaType _tar, TextureLib::TextureRes _tex) Sets a material parameter to a texture. |
| ~Material () Destructor. |
Public Static Functions
| Type | Name |
|---|---|
| MaterialRes | LoadMaterial (std::string _path="") Loads a material from a configuration file. |
Detailed Description
Material encapsulates all surface appearance parameters for physically-based rendering. Supports hybrid mode where each parameter can be a constant, color, or texture map.
Material Parameters: * MAT_ALBEDO: Base color / diffuse albedo * MAT_METAL: Metallic factor (0 = dielectric, 1 = conductor) * MAT_ROUGH: Roughness (0 = smooth/mirror, 1 = rough/matte) * MAT_SPEC: Specular reflectance (non-metallic materials) * MAT_EMIS_COL: Emissive color * MAT_EMIS_STR: Emissive strength multiplier * MAT_ALPHA: Opacity/transparency * MAT_NORMAL: Normal map (tangent space) * MAT_BUMP: Bump/height map
Usage:
auto mat = Material::LoadMaterial("materials/gold.mat");
mat->SetMatParam(Material::MAT_ALBEDO, glm::vec3(1.0f, 0.766f, 0.336f));
mat->SetMatParam(Material::MAT_METAL, 1.0f);
mat->SetMatParam(Material::MAT_ROUGH, 0.3f);
mat->BindMatTexture(); // Bind before rendering
Note:
Thread-safety: Not thread-safe. Material state should not be modified during rendering.
Public Types Documentation
enum MatDataType
Data type discriminator for material parameters.
enum Material::MatDataType {
MPARA_FLT,
MPARA_COL,
MPARA_TEX,
MPARA_CODE
};
Specifies how a parameter is stored and should be interpreted by shaders.
enum MatParaType
Material parameter types.
enum Material::MatParaType {
MAT_NONE = -1,
MAT_ALBEDO,
MAT_METAL,
MAT_ROUGH,
MAT_SPEC,
MAT_EMIS_COL,
MAT_EMIS_STR,
MAT_ALPHA,
MAT_NORMAL,
MAT_BUMP,
MAT_END
};
Each parameter can have different data types depending on the material setup. Constants provide uniform values, while textures provide per-pixel variation.
typedef MatParamData
Parameter data: (type, float, vec3, texture)
using Material::MatParamData = std::tuple<MatDataType, float, glm::vec3, TextureLib::TextureRes>;
typedef MaterialRes
Shared pointer to Material (for resource sharing)
using Material::MaterialRes = std::shared_ptr<Material>;
Public Attributes Documentation
variable is_mat_changed
Flag indicating material parameters have changed.
bool Material::is_mat_changed;
variable is_mat_struct_changed
Flag indicating material structure (data types) has changed.
bool Material::is_mat_struct_changed;
variable mat_name
Material name (for debugging and serialization)
std::string Material::mat_name;
variable mat_params
Map of material parameters to their data.
std::unordered_map<MatParaType, MatParamData> Material::mat_params;
Public Static Attributes Documentation
variable mat_uniform_name
Uniform names for each MatParaType (indexed array)
std::vector< std::string > Material::mat_uniform_name;
Public Functions Documentation
function BindMatTexture
Binds all material textures to their respective texture units.
void Material::BindMatTexture () const
Iterates through mat_params and binds all MPARA_TEX type parameters to OpenGL texture units. Should be called before rendering with this material.
Texture Unit Assignment: * Typically uses units 0-9 for material textures * Specific slot assignment depends on shader uniform locations
Note:
Must be called within an active OpenGL context
Note:
Corresponding shader must have matching sampler2D uniforms
function InitParamData
Initializes all material parameters to default values.
void Material::InitParamData ()
Sets up default PBR parameters: * Albedo: white (1, 1, 1) * Metallic: 0.0 * Roughness: 0.5 * Specular: gray (0.04, 0.04, 0.04) * Emissive: black, strength 0 * Alpha: 1.0 (opaque)
function Material
Default constructor (creates default PBR material).
Material::Material ()
function ParseConfig
Parses material configuration from a string.
void Material::ParseConfig (
const std::string & _config
)
Parameters:
_configMaterial configuration string (JSON or custom format)
Note:
Updates mat_params based on parsed config
function SetMatParam [1/4]
Sets the data type for a material parameter.
void Material::SetMatParam (
MatParaType _tar,
MatDataType _type
)
Parameters:
_tarParameter type (MAT_ALBEDO, MAT_ROUGH, etc.)_typeData type (MPARA_FLT, MPARA_COL, MPARA_TEX)
Note:
Marks material as changed for GPU update
function SetMatParam [2/4]
Sets a material parameter to a float value.
void Material::SetMatParam (
MatParaType _tar,
float _var
)
Parameters:
_tarParameter type_varFloat value
Note:
Automatically sets data type to MPARA_FLT
function SetMatParam [3/4]
Sets a material parameter to a color value.
void Material::SetMatParam (
MatParaType _tar,
glm::vec3 _col
)
Parameters:
_tarParameter type_colColor value (vec3, RGB in [0,1])
Note:
Automatically sets data type to MPARA_COL
function SetMatParam [4/4]
Sets a material parameter to a texture.
void Material::SetMatParam (
MatParaType _tar,
TextureLib::TextureRes _tex
)
Parameters:
_tarParameter type_texTexture resource (shared pointer)
Note:
Automatically sets data type to MPARA_TEX
function ~Material
Destructor.
Material::~Material ()
Public Static Functions Documentation
function LoadMaterial
Loads a material from a configuration file.
static MaterialRes Material::LoadMaterial (
std::string _path=""
)
Parameters:
_pathPath to material file (JSON or custom format)
Returns:
Shared pointer to loaded Material, or default material on failure
Note:
If path is empty, returns default material
The documentation for this class was generated from the following file src/render/Material.h