Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Rendering::Material Class Reference

Shader configuration with parameters and textures for surface appearance. More...

#include <Material.hpp>

Inheritance diagram for Infinity::Types::Rendering::Material:
[legend]
Collaboration diagram for Infinity::Types::Rendering::Material:
[legend]

Public Member Functions

 Material ()
 Default constructor.
 
virtual ~Material ()
 Destructor.
 
std::unique_ptr< Core::Baseclone () const override
 
void setInt (const std::string &key, int value)
 Sets an integer parameter.
 
void setFloat (const std::string &key, float value)
 Sets a float parameter.
 
void setVector2 (const std::string &key, const Infinity::Types::Math::Vector2 &value)
 Sets a 2D vector parameter.
 
void setVector3 (const std::string &key, const Infinity::Types::Math::Vector3 &value)
 Sets a 3D vector parameter.
 
void setVector4 (const std::string &key, const Infinity::Types::Math::Vector4 &value)
 Sets a 4D vector parameter.
 
void setColor (const std::string &key, const Infinity::Types::Math::Vector4ub &value)
 Sets a color parameter (8-bit RGBA).
 
void setTexture (const std::string &key, std::shared_ptr< const Containers::ArrayBase > texture)
 Sets a texture from a generic array base.
 
void setTexture2DR (const std::string &key, const Containers::Array2D< uint8_t > &texture)
 Sets a single-channel 8-bit texture (R format).
 
void setTexture2DRG (const std::string &key, const Containers::Array2D< Math::Vector2ub > &texture)
 Sets a two-channel 8-bit texture (RG format).
 
void setTexture2DRGB (const std::string &key, const Containers::Array2D< Math::Vector3ub > &texture)
 Sets a three-channel 8-bit texture (RGB format).
 
void setTexture2DRGBA (const std::string &key, const Containers::Array2D< Math::Vector4ub > &texture)
 Sets a four-channel 8-bit texture (RGBA format).
 
void setTexture2DR_SFloat32 (const std::string &key, const Containers::Array2D< float > &texture)
 Sets a single-channel 32-bit float texture (R format, HDR).
 
void setTexture2DRG_SFloat32 (const std::string &key, const Containers::Array2D< Math::Vector2 > &texture)
 Sets a two-channel 32-bit float texture (RG format, HDR).
 
void setTexture2DRGB_SFloat32 (const std::string &key, const Containers::Array2D< Math::Vector3 > &texture)
 Sets a three-channel 32-bit float texture (RGB format, HDR).
 
void setTexture2DRGBA_SFloat32 (const std::string &key, const Containers::Array2D< Math::Vector4 > &texture)
 Sets a four-channel 32-bit float texture (RGBA format, HDR).
 
int getInt (const std::string &key) const
 Gets an integer parameter.
 
float getFloat (const std::string &key) const
 Gets a float parameter.
 
Math::Vector2 getVector2 (const std::string &key) const
 Gets a 2D vector parameter.
 
Math::Vector3 getVector3 (const std::string &key) const
 Gets a 3D vector parameter.
 
Math::Vector4 getVector4 (const std::string &key) const
 Gets a 4D vector parameter.
 
Math::Vector4ub getColor (const std::string &key) const
 Gets a color parameter as 8-bit RGBA.
 
Math::Vector4ub getColorRGBA (const std::string &key) const
 Gets a color parameter as 8-bit RGBA.
 
Math::Vector4 getColorRGBAFloat (const std::string &key) const
 Gets a color parameter as normalized float RGBA.
 
bool hasParam (const std::string &key) const
 Checks if a parameter exists.
 
bool hasTexture (const std::string &key) const
 Checks if a texture parameter exists.
 
const Containers::ArrayBasegetTexture (const std::string &key) const
 Gets a texture as generic ArrayBase reference.
 
const Containers::Array2D< uint8_t > & getTexture2DR (const std::string &key) const
 Gets a single-channel 8-bit texture.
 
const Containers::Array2D< Math::Vector2ub > & getTexture2DRG (const std::string &key) const
 Gets a two-channel 8-bit texture.
 
const Containers::Array2D< Math::Vector3ub > & getTexture2DRGB (const std::string &key) const
 Gets a three-channel 8-bit texture.
 
const Containers::Array2D< Math::Vector4ub > & getTexture2DRGBA (const std::string &key) const
 Gets a four-channel 8-bit texture.
 
const Containers::Array2D< float > & getTexture2DR_SFloat32 (const std::string &key) const
 Gets a single-channel 32-bit float texture.
 
const Containers::Array2D< Math::Vector2 > & getTexture2DRG_SFloat32 (const std::string &key) const
 Gets a two-channel 32-bit float texture.
 
const Containers::Array2D< Math::Vector3 > & getTexture2DRGB_SFloat32 (const std::string &key) const
 Gets a three-channel 32-bit float texture.
 
const Containers::Array2D< Math::Vector4 > & getTexture2DRGBA_SFloat32 (const std::string &key) const
 Gets a four-channel 32-bit float texture.
 
const Infinity::Types::TypeIDtypeId () const override
 Gets the TypeID for Material.
 
- Public Member Functions inherited from Infinity::Types::Core::Data
 Data ()
 
 Data (const Data &other)
 
 Data (Data &&other)
 
Dataoperator= (const Data &other)
 
Dataoperator= (Data &&other)
 
virtual ~Data ()
 Virtual destructor.
 
bool hasProperty (const std::string &key) const
 
template<typename T >
void setProperty (const std::string &key, T &&value)
 Sets a typed property value.
 
template<typename T >
void setProperty (const std::string &key, const T &value)
 Sets a typed property value.
 
void setProperty (const std::string &key, PropertyValue &&value)
 Sets a typed property value.
 
const PropertyValuegetProperty (const std::string &key) const
 Gets a property value without type checking.
 
template<typename T >
const T & getProperty (const std::string &key) const
 Gets a typed property value.
 
void removeProperty (const std::string &key)
 
- Public Member Functions inherited from Infinity::Types::Core::Base
virtual ~Base ()
 Virtual destructor.
 
virtual std::istream & legibleDataRead (std::istream &in) override
 Deserializes the object from a single-line text representation.
 
virtual std::ostream & legibleDataWrite (std::ostream &out) const override
 Serializes the object to a single-line text representation.
 

Public Attributes

std::string name
 Human-readable material name.
 
std::string shaderName
 Name of the shader to use for rendering.
 
Containers::ImmutableMap params
 Parameter storage for shader uniforms and textures.
 
- Public Attributes inherited from Infinity::Types::Core::Data
std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

Shader configuration with parameters and textures for surface appearance.

Material defines the visual properties of rendered surfaces by specifying a shader and its associated parameters (uniforms and textures). It provides a type-safe interface for configuring shader inputs, supporting both scalar parameters (floats, vectors, colors) and texture data in various formats.

The material system enables:

  • Shader-based rendering with customizable parameters
  • Multiple texture channels (albedo, normal, roughness, metallic, etc.)
  • Procedurally generated texture assignment
  • Material variations for the same shader
  • Support for both 8-bit and 32-bit float texture formats
  • Parameter sharing via ImmutableMap

Materials reference shaders by name and store parameters in an ImmutableMap, allowing heterogeneous parameter types while maintaining type safety through the setter/getter methods.

Common use cases:

  • Assigning materials to procedurally generated meshes
  • Terrain material configuration with splatmaps
  • Dynamic material parameter modification
  • Texture-based surface properties
  • PBR (Physically Based Rendering) workflows
  • Custom shader parameter binding
Note
The shaderName must reference a shader known to the rendering system.
Texture formats support both LDR (8-bit) and HDR (32-bit float) data.
Parameters are stored by name and must match shader uniform names.
Use setTexture variants for different channel counts (R, RG, RGB, RGBA).

Example usage:

// Create a basic PBR material
mat.name = "TerrainMaterial";
mat.shaderName = "pbr_standard";
// Set scalar parameters
mat.setFloat("roughness", 0.8f);
mat.setFloat("metallic", 0.0f);
mat.setVector3("tint", Vector3{0.8f, 0.7f, 0.6f});
// Set color parameters
mat.setColor("baseColor", Vector4ub{200, 180, 160, 255});
// Assign procedurally generated textures
Array2D<Vector4ub> albedoMap = generateAlbedoTexture(512, 512);
mat.setTexture2DRGBA("albedoMap", albedoMap);
Array2D<Vector3ub> normalMap = generateNormalMap(512, 512);
mat.setTexture2DRGB("normalMap", normalMap);
Array2D<uint8_t> roughnessMap = generateRoughnessMap(512, 512);
mat.setTexture2DR("roughnessMap", roughnessMap);
// Terrain material with multiple layers
Material terrainMat;
terrainMat.shaderName = "terrain_multitexture";
terrainMat.setTexture2DRGBA("grassAlbedo", grassTexture);
terrainMat.setTexture2DRGBA("rockAlbedo", rockTexture);
terrainMat.setTexture2DRGBA("snowAlbedo", snowTexture);
terrainMat.setTexture2DR("splatmap", splatmapData);
terrainMat.setFloat("textureScale", 10.0f);
// HDR textures for emissive materials
Array2D<Vector3> emissiveMap = generateEmissiveHDR(256, 256);
mat.setTexture2DRGB_SFloat32("emissiveMap", emissiveMap);
mat.setFloat("emissiveStrength", 5.0f);
// Check parameter existence before access
if (mat.hasParam("roughness")) {
float r = mat.getFloat("roughness");
}
// Use with ProceduralSystem
system->setIn("surface_material", std::move(mat));
Shader configuration with parameters and textures for surface appearance.
Definition Material.hpp:96
void setFloat(const std::string &key, float value)
Sets a float parameter.
void setTexture2DRGB_SFloat32(const std::string &key, const Containers::Array2D< Math::Vector3 > &texture)
Sets a three-channel 32-bit float texture (RGB format, HDR).
void setColor(const std::string &key, const Infinity::Types::Math::Vector4ub &value)
Sets a color parameter (8-bit RGBA).
std::string shaderName
Name of the shader to use for rendering.
Definition Material.hpp:119
void setTexture2DRGBA(const std::string &key, const Containers::Array2D< Math::Vector4ub > &texture)
Sets a four-channel 8-bit texture (RGBA format).
std::string name
Human-readable material name.
Definition Material.hpp:104
bool hasParam(const std::string &key) const
Checks if a parameter exists.
void setTexture2DRGB(const std::string &key, const Containers::Array2D< Math::Vector3ub > &texture)
Sets a three-channel 8-bit texture (RGB format).
void setVector3(const std::string &key, const Infinity::Types::Math::Vector3 &value)
Sets a 3D vector parameter.
float getFloat(const std::string &key) const
Gets a float parameter.
void setTexture2DR(const std::string &key, const Containers::Array2D< uint8_t > &texture)
Sets a single-channel 8-bit texture (R format).

Constructor & Destructor Documentation

◆ Material()

Infinity::Types::Rendering::Material::Material ( )

Default constructor.

Creates an empty material with no shader or parameters.

◆ ~Material()

virtual Infinity::Types::Rendering::Material::~Material ( )
virtual

Destructor.

Member Function Documentation

◆ clone()

std::unique_ptr< Core::Base > Infinity::Types::Rendering::Material::clone ( ) const
overridevirtual

Reimplemented from Infinity::Types::Core::Data.

◆ getColor()

Math::Vector4ub Infinity::Types::Rendering::Material::getColor ( const std::string &  key) const

Gets a color parameter as 8-bit RGBA.

Parameters
keyParameter name.
Returns
Color as Vector4ub (0-255 per channel).
Exceptions
std::out_of_rangeif key doesn't exist.

◆ getColorRGBA()

Math::Vector4ub Infinity::Types::Rendering::Material::getColorRGBA ( const std::string &  key) const

Gets a color parameter as 8-bit RGBA.

Alias for getColor().

Parameters
keyParameter name.
Returns
Color as Vector4ub (0-255 per channel).
Exceptions
std::out_of_rangeif key doesn't exist.

◆ getColorRGBAFloat()

Math::Vector4 Infinity::Types::Rendering::Material::getColorRGBAFloat ( const std::string &  key) const

Gets a color parameter as normalized float RGBA.

Converts 8-bit color to float range [0, 1].

Parameters
keyParameter name.
Returns
Color as Vector4 (0.0-1.0 per channel).
Exceptions
std::out_of_rangeif key doesn't exist.

◆ getFloat()

float Infinity::Types::Rendering::Material::getFloat ( const std::string &  key) const

Gets a float parameter.

Parameters
keyParameter name.
Returns
Float value.
Exceptions
std::out_of_rangeif key doesn't exist.

◆ getInt()

int Infinity::Types::Rendering::Material::getInt ( const std::string &  key) const

Gets an integer parameter.

Parameters
keyParameter name.
Returns
Integer value.
Exceptions
std::out_of_rangeif key doesn't exist.

◆ getTexture()

const Containers::ArrayBase & Infinity::Types::Rendering::Material::getTexture ( const std::string &  key) const

Gets a texture as generic ArrayBase reference.

Parameters
keyTexture parameter name.
Returns
Const reference to texture data.
Exceptions
std::out_of_rangeif key doesn't exist.

◆ getTexture2DR()

const Containers::Array2D< uint8_t > & Infinity::Types::Rendering::Material::getTexture2DR ( const std::string &  key) const

Gets a single-channel 8-bit texture.

Parameters
keyTexture parameter name.
Returns
Const reference to R format texture.
Exceptions
std::out_of_rangeif key doesn't exist.
std::bad_castif texture is not the expected type.

◆ getTexture2DR_SFloat32()

const Containers::Array2D< float > & Infinity::Types::Rendering::Material::getTexture2DR_SFloat32 ( const std::string &  key) const

Gets a single-channel 32-bit float texture.

Parameters
keyTexture parameter name.
Returns
Const reference to R float format texture.
Exceptions
std::out_of_rangeif key doesn't exist.
std::bad_castif texture is not the expected type.

◆ getTexture2DRG()

const Containers::Array2D< Math::Vector2ub > & Infinity::Types::Rendering::Material::getTexture2DRG ( const std::string &  key) const

Gets a two-channel 8-bit texture.

Parameters
keyTexture parameter name.
Returns
Const reference to RG format texture.
Exceptions
std::out_of_rangeif key doesn't exist.
std::bad_castif texture is not the expected type.

◆ getTexture2DRG_SFloat32()

const Containers::Array2D< Math::Vector2 > & Infinity::Types::Rendering::Material::getTexture2DRG_SFloat32 ( const std::string &  key) const

Gets a two-channel 32-bit float texture.

Parameters
keyTexture parameter name.
Returns
Const reference to RG float format texture.
Exceptions
std::out_of_rangeif key doesn't exist.
std::bad_castif texture is not the expected type.

◆ getTexture2DRGB()

const Containers::Array2D< Math::Vector3ub > & Infinity::Types::Rendering::Material::getTexture2DRGB ( const std::string &  key) const

Gets a three-channel 8-bit texture.

Parameters
keyTexture parameter name.
Returns
Const reference to RGB format texture.
Exceptions
std::out_of_rangeif key doesn't exist.
std::bad_castif texture is not the expected type.

◆ getTexture2DRGB_SFloat32()

const Containers::Array2D< Math::Vector3 > & Infinity::Types::Rendering::Material::getTexture2DRGB_SFloat32 ( const std::string &  key) const

Gets a three-channel 32-bit float texture.

Parameters
keyTexture parameter name.
Returns
Const reference to RGB float format texture.
Exceptions
std::out_of_rangeif key doesn't exist.
std::bad_castif texture is not the expected type.

◆ getTexture2DRGBA()

const Containers::Array2D< Math::Vector4ub > & Infinity::Types::Rendering::Material::getTexture2DRGBA ( const std::string &  key) const

Gets a four-channel 8-bit texture.

Parameters
keyTexture parameter name.
Returns
Const reference to RGBA format texture.
Exceptions
std::out_of_rangeif key doesn't exist.
std::bad_castif texture is not the expected type.

◆ getTexture2DRGBA_SFloat32()

const Containers::Array2D< Math::Vector4 > & Infinity::Types::Rendering::Material::getTexture2DRGBA_SFloat32 ( const std::string &  key) const

Gets a four-channel 32-bit float texture.

Parameters
keyTexture parameter name.
Returns
Const reference to RGBA float format texture.
Exceptions
std::out_of_rangeif key doesn't exist.
std::bad_castif texture is not the expected type.

◆ getVector2()

Math::Vector2 Infinity::Types::Rendering::Material::getVector2 ( const std::string &  key) const

Gets a 2D vector parameter.

Parameters
keyParameter name.
Returns
Vector2 value.
Exceptions
std::out_of_rangeif key doesn't exist.

◆ getVector3()

Math::Vector3 Infinity::Types::Rendering::Material::getVector3 ( const std::string &  key) const

Gets a 3D vector parameter.

Parameters
keyParameter name.
Returns
Vector3 value.
Exceptions
std::out_of_rangeif key doesn't exist.

◆ getVector4()

Math::Vector4 Infinity::Types::Rendering::Material::getVector4 ( const std::string &  key) const

Gets a 4D vector parameter.

Parameters
keyParameter name.
Returns
Vector4 value.
Exceptions
std::out_of_rangeif key doesn't exist.

◆ hasParam()

bool Infinity::Types::Rendering::Material::hasParam ( const std::string &  key) const

Checks if a parameter exists.

Parameters
keyParameter name to check.
Returns
True if parameter exists, false otherwise.

◆ hasTexture()

bool Infinity::Types::Rendering::Material::hasTexture ( const std::string &  key) const

Checks if a texture parameter exists.

Parameters
keyTexture parameter name to check.
Returns
True if texture exists, false otherwise.

◆ setColor()

void Infinity::Types::Rendering::Material::setColor ( const std::string &  key,
const Infinity::Types::Math::Vector4ub value 
)

Sets a color parameter (8-bit RGBA).

Parameters
keyParameter name (must match shader uniform name).
valueColor as 8-bit RGBA (0-255 per channel).

◆ setFloat()

void Infinity::Types::Rendering::Material::setFloat ( const std::string &  key,
float  value 
)

Sets a float parameter.

Parameters
keyParameter name (must match shader uniform name).
valueFloat value.

◆ setInt()

void Infinity::Types::Rendering::Material::setInt ( const std::string &  key,
int  value 
)

Sets an integer parameter.

Parameters
keyParameter name (must match shader uniform name).
valueInteger value.

◆ setTexture()

void Infinity::Types::Rendering::Material::setTexture ( const std::string &  key,
std::shared_ptr< const Containers::ArrayBase texture 
)

Sets a texture from a generic array base.

Parameters
keyTexture parameter name (must match shader sampler name).
textureShared pointer to texture data (any ArrayBase-derived type).

◆ setTexture2DR()

void Infinity::Types::Rendering::Material::setTexture2DR ( const std::string &  key,
const Containers::Array2D< uint8_t > &  texture 
)

Sets a single-channel 8-bit texture (R format).

Parameters
keyTexture parameter name.
textureSingle-channel texture (e.g., grayscale, roughness, metallic).

◆ setTexture2DR_SFloat32()

void Infinity::Types::Rendering::Material::setTexture2DR_SFloat32 ( const std::string &  key,
const Containers::Array2D< float > &  texture 
)

Sets a single-channel 32-bit float texture (R format, HDR).

Parameters
keyTexture parameter name.
textureSingle-channel HDR texture (e.g., heightmaps, HDR roughness).

◆ setTexture2DRG()

void Infinity::Types::Rendering::Material::setTexture2DRG ( const std::string &  key,
const Containers::Array2D< Math::Vector2ub > &  texture 
)

Sets a two-channel 8-bit texture (RG format).

Parameters
keyTexture parameter name.
textureTwo-channel texture (e.g., normal map RG encoding).

◆ setTexture2DRG_SFloat32()

void Infinity::Types::Rendering::Material::setTexture2DRG_SFloat32 ( const std::string &  key,
const Containers::Array2D< Math::Vector2 > &  texture 
)

Sets a two-channel 32-bit float texture (RG format, HDR).

Parameters
keyTexture parameter name.
textureTwo-channel HDR texture (e.g., flow maps, vector fields).

◆ setTexture2DRGB()

void Infinity::Types::Rendering::Material::setTexture2DRGB ( const std::string &  key,
const Containers::Array2D< Math::Vector3ub > &  texture 
)

Sets a three-channel 8-bit texture (RGB format).

Parameters
keyTexture parameter name.
textureThree-channel texture (e.g., albedo without alpha, normal map).

◆ setTexture2DRGB_SFloat32()

void Infinity::Types::Rendering::Material::setTexture2DRGB_SFloat32 ( const std::string &  key,
const Containers::Array2D< Math::Vector3 > &  texture 
)

Sets a three-channel 32-bit float texture (RGB format, HDR).

Parameters
keyTexture parameter name.
textureThree-channel HDR texture (e.g., emissive maps, HDR albedo).

◆ setTexture2DRGBA()

void Infinity::Types::Rendering::Material::setTexture2DRGBA ( const std::string &  key,
const Containers::Array2D< Math::Vector4ub > &  texture 
)

Sets a four-channel 8-bit texture (RGBA format).

Parameters
keyTexture parameter name.
textureFour-channel texture with alpha (e.g., albedo with transparency).

◆ setTexture2DRGBA_SFloat32()

void Infinity::Types::Rendering::Material::setTexture2DRGBA_SFloat32 ( const std::string &  key,
const Containers::Array2D< Math::Vector4 > &  texture 
)

Sets a four-channel 32-bit float texture (RGBA format, HDR).

Parameters
keyTexture parameter name.
textureFour-channel HDR texture with alpha.

◆ setVector2()

void Infinity::Types::Rendering::Material::setVector2 ( const std::string &  key,
const Infinity::Types::Math::Vector2 value 
)

Sets a 2D vector parameter.

Parameters
keyParameter name (must match shader uniform name).
valueVector2 value.

◆ setVector3()

void Infinity::Types::Rendering::Material::setVector3 ( const std::string &  key,
const Infinity::Types::Math::Vector3 value 
)

Sets a 3D vector parameter.

Parameters
keyParameter name (must match shader uniform name).
valueVector3 value.

◆ setVector4()

void Infinity::Types::Rendering::Material::setVector4 ( const std::string &  key,
const Infinity::Types::Math::Vector4 value 
)

Sets a 4D vector parameter.

Parameters
keyParameter name (must match shader uniform name).
valueVector4 value.

◆ typeId()

const Infinity::Types::TypeID & Infinity::Types::Rendering::Material::typeId ( ) const
overridevirtual

Gets the TypeID for Material.

Returns
TypeID identifying this Material type.

Reimplemented from Infinity::Types::Core::Data.

Member Data Documentation

◆ name

std::string Infinity::Types::Rendering::Material::name

Human-readable material name.

Descriptive name for the material, used for identification and debugging. Does not affect rendering behavior.

◆ params

Containers::ImmutableMap Infinity::Types::Rendering::Material::params

Parameter storage for shader uniforms and textures.

Heterogeneous map storing all material parameters. Access through the type-safe setter/getter methods rather than directly.

◆ shaderName

std::string Infinity::Types::Rendering::Material::shaderName

Name of the shader to use for rendering.

References a shader program by name. The shader must be available in the rendering system's shader registry. Parameters set on this material should match the shader's uniform names.

Common shader names:

  • "pbr_standard": Standard physically-based rendering
  • "unlit": Simple unlit/emissive rendering
  • "terrain_multitexture": Terrain with splatmap blending
  • Custom shader names as defined in your project