Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::Material Class Reference

Represents a Physically-Based Rendering (PBR) material. More...

#include <vclib/space/core/material.h>

Public Types

enum class  AlphaMode { ALPHA_OPAQUE , ALPHA_MASK , ALPHA_BLEND }
 Defines the alpha rendering mode of the material. More...
 
enum class  TextureType {
  BASE_COLOR , METALLIC_ROUGHNESS , NORMAL , OCCLUSION ,
  EMISSIVE , COUNT
}
 Defines the types of textures used in the PBR material model. More...
 

Public Member Functions

floatalphaCutoff ()
 Gets a mutable reference to the alpha cutoff value.
 
float alphaCutoff () const
 Gets the alpha cutoff value. This value is used only when the alpha mode is ALPHA_MASK.
 
AlphaModealphaMode ()
 Gets a mutable reference to the alpha rendering mode.
 
AlphaMode alphaMode () const
 Gets the alpha rendering mode.
 
ColorbaseColor ()
 Gets a mutable reference to the base color of the material.
 
const ColorbaseColor () const
 Gets the base color of the material. This is used as a tint if a base color texture is present.
 
TextureDescriptorbaseColorTextureDescriptor ()
 Gets a mutable reference to the texture descriptor for the base color texture.
 
const TextureDescriptorbaseColorTextureDescriptor () const
 Gets the texture descriptor for the base color texture.
 
void deserialize (std::istream &is)
 Deserializes the material's data from an input stream.
 
booldoubleSided ()
 Gets a mutable reference to the double-sided property.
 
bool doubleSided () const
 Checks if the material is double-sided. If true, both front and back faces of polygons with this material should be rendered.
 
ColoremissiveColor ()
 Gets a mutable reference to the emissive color of the material.
 
const ColoremissiveColor () const
 Gets the emissive color of the material. This is the color emitted by the material, independent of lighting.
 
 Material ()
 Default constructor.
 
floatmetallic ()
 Gets a mutable reference to the metallic factor of the material.
 
float metallic () const
 Gets the metallic factor of the material.
 
std::string & name ()
 Gets a mutable reference to the name of the material.
 
const std::string & name () const
 Gets the name of the material.
 
floatnormalScale ()
 Gets a mutable reference to the normal scale.
 
float normalScale () const
 Gets the scalar multiplier for the normal map.
 
floatocclusionStrength ()
 Gets a mutable reference to the occlusion strength.
 
float occlusionStrength () const
 Gets the strength of the ambient occlusion effect.
 
bool operator== (const Material &other) const =default
 Defaulted equality comparison operator.
 
floatroughness ()
 Gets a mutable reference to the roughness factor of the material.
 
float roughness () const
 Gets the roughness factor of the material.
 
void serialize (std::ostream &os) const
 Serializes the material's data to an output stream.
 
TextureDescriptortextureDescriptor (TextureType type)
 Gets a mutable reference to the texture descriptor for a given texture type.
 
const TextureDescriptortextureDescriptor (TextureType type) const
 Gets the texture descriptor for a given texture type.
 
TextureDescriptortextureDescriptor (uint type)
 Gets a mutable reference to the texture descriptor for a given texture type index.
 
const TextureDescriptortextureDescriptor (uint type) const
 Gets the texture descriptor for a given texture type index.
 

Static Public Member Functions

static Image::ColorSpace textureTypeToColorSpace (TextureType type)
 Determines the appropriate color space for a given texture type.
 

Static Public Attributes

static const std::array< std::string, toUnderlying(TextureType::COUNT)> TEXTURE_TYPE_NAMES
 

Private Attributes

float mAlphaCutoff = 0.5f
 
AlphaMode mAlphaMode = AlphaMode::ALPHA_OPAQUE
 
Color mBaseColor = Color::White
 
bool mDoubleSided = false
 
Color mEmissiveColor = Color::Black
 
float mMetallic = 0.0f
 
std::string mName
 
float mNormalScale = 1.0f
 
float mOcclusionStrength = 1.0f
 
float mRoughness = 1.0f
 
std::array< TextureDescriptor, N_TEXTURE_TYPE > mTextureDescriptors
 

Static Private Attributes

static const uint N_TEXTURE_TYPE
 

Detailed Description

Represents a Physically-Based Rendering (PBR) material.

This class encapsulates all the properties required to describe a surface for rendering, following the PBR metallic-roughness workflow. It includes base color, metallic and roughness factors, emissive color, and textures. It also handles transparency modes and other rendering-related attributes.

Member Enumeration Documentation

◆ AlphaMode

Defines the alpha rendering mode of the material.

Enumerator
ALPHA_OPAQUE 

The material is fully opaque. Alpha values are ignored.

ALPHA_MASK 

The material is rendered as either fully opaque or fully transparent, based on the alphaCutoff value.

ALPHA_BLEND 

The material is rendered with alpha blending, allowing for smooth transparency.

◆ TextureType

Defines the types of textures used in the PBR material model.

Enumerator
BASE_COLOR 

The base color (albedo) texture. Stored in sRGB color space.

METALLIC_ROUGHNESS 

Metallic (B channel) and roughness (G channel) texture. Stored in linear color space.

NORMAL 

The tangent-space normal map. Stored in linear color space.

OCCLUSION 

The ambient occlusion map (R channel). Stored in linear color space.

EMISSIVE 

The emissive color texture. Stored in sRGB color space.

COUNT 

Utility value to get the number of texture types.

Constructor & Destructor Documentation

◆ Material()

vcl::Material::Material ( )
inline

Default constructor.

Creates a default material. The default material has:

  • Name: empty string
  • Base Color: White
  • Metallic: 0.0
  • Roughness: 1.0
  • Emissive Color: Black
  • Alpha Mode: ALPHA_OPAQUE
  • Alpha Cutoff: 0.5
  • Double Sided: false
  • Normal Scale: 1.0
  • Occlusion Strength: 1.0
  • No textures assigned.

Member Function Documentation

◆ alphaCutoff() [1/2]

float & vcl::Material::alphaCutoff ( )
inline

Gets a mutable reference to the alpha cutoff value.

Returns
A reference to the alpha cutoff value.

◆ alphaCutoff() [2/2]

float vcl::Material::alphaCutoff ( ) const
inline

Gets the alpha cutoff value. This value is used only when the alpha mode is ALPHA_MASK.

Returns
The alpha cutoff value, in the range [0.0, 1.0].

◆ alphaMode() [1/2]

AlphaMode & vcl::Material::alphaMode ( )
inline

Gets a mutable reference to the alpha rendering mode.

Returns
A reference to the alpha mode.

◆ alphaMode() [2/2]

AlphaMode vcl::Material::alphaMode ( ) const
inline

Gets the alpha rendering mode.

Returns
The current alpha mode (Opaque, Mask, or Blend).

◆ baseColor() [1/2]

Color & vcl::Material::baseColor ( )
inline

Gets a mutable reference to the base color of the material.

Returns
A reference to the base color.

◆ baseColor() [2/2]

const Color & vcl::Material::baseColor ( ) const
inline

Gets the base color of the material. This is used as a tint if a base color texture is present.

Returns
A const reference to the base color.

◆ baseColorTextureDescriptor() [1/2]

TextureDescriptor & vcl::Material::baseColorTextureDescriptor ( )
inline

Gets a mutable reference to the texture descriptor for the base color texture.

Returns
A reference to the base color texture descriptor.

◆ baseColorTextureDescriptor() [2/2]

const TextureDescriptor & vcl::Material::baseColorTextureDescriptor ( ) const
inline

Gets the texture descriptor for the base color texture.

Returns
A const reference to the base color texture descriptor.

◆ deserialize()

void vcl::Material::deserialize ( std::istream &  is)
inline

Deserializes the material's data from an input stream.

Parameters
[in/out]is: The input stream to read from.

◆ doubleSided() [1/2]

bool & vcl::Material::doubleSided ( )
inline

Gets a mutable reference to the double-sided property.

Returns
A reference to the double-sided flag.

◆ doubleSided() [2/2]

bool vcl::Material::doubleSided ( ) const
inline

Checks if the material is double-sided. If true, both front and back faces of polygons with this material should be rendered.

Returns
True if the material is double-sided, false otherwise.

◆ emissiveColor() [1/2]

Color & vcl::Material::emissiveColor ( )
inline

Gets a mutable reference to the emissive color of the material.

Returns
A reference to the emissive color.

◆ emissiveColor() [2/2]

const Color & vcl::Material::emissiveColor ( ) const
inline

Gets the emissive color of the material. This is the color emitted by the material, independent of lighting.

Returns
A const reference to the emissive color.

◆ metallic() [1/2]

float & vcl::Material::metallic ( )
inline

Gets a mutable reference to the metallic factor of the material.

Returns
A reference to the metallic factor.

◆ metallic() [2/2]

float vcl::Material::metallic ( ) const
inline

Gets the metallic factor of the material.

Returns
The metallic factor, in the range [0.0, 1.0].

◆ name() [1/2]

std::string & vcl::Material::name ( )
inline

Gets a mutable reference to the name of the material.

Returns
A reference to the material's name.

◆ name() [2/2]

const std::string & vcl::Material::name ( ) const
inline

Gets the name of the material.

Returns
A const reference to the material's name.

◆ normalScale() [1/2]

float & vcl::Material::normalScale ( )
inline

Gets a mutable reference to the normal scale.

Returns
A reference to the normal scale.

◆ normalScale() [2/2]

float vcl::Material::normalScale ( ) const
inline

Gets the scalar multiplier for the normal map.

Returns
The normal scale factor.

◆ occlusionStrength() [1/2]

float & vcl::Material::occlusionStrength ( )
inline

Gets a mutable reference to the occlusion strength.

Returns
A reference to the occlusion strength.

◆ occlusionStrength() [2/2]

float vcl::Material::occlusionStrength ( ) const
inline

Gets the strength of the ambient occlusion effect.

Returns
The occlusion strength, in the range [0.0, 1.0].

◆ operator==()

bool vcl::Material::operator== ( const Material other) const
default

Defaulted equality comparison operator.

Parameters
[in]otherThe material to compare against.
Returns
True if all members of this material are equal to the other, false otherwise.

◆ roughness() [1/2]

float & vcl::Material::roughness ( )
inline

Gets a mutable reference to the roughness factor of the material.

Returns
A reference to the roughness factor.

◆ roughness() [2/2]

float vcl::Material::roughness ( ) const
inline

Gets the roughness factor of the material.

Returns
The roughness factor, in the range [0.0, 1.0].

◆ serialize()

void vcl::Material::serialize ( std::ostream &  os) const
inline

Serializes the material's data to an output stream.

Parameters
[in/out]os: The output stream to write to.

◆ textureDescriptor() [1/4]

TextureDescriptor & vcl::Material::textureDescriptor ( TextureType  type)
inline

Gets a mutable reference to the texture descriptor for a given texture type.

Parameters
[in]typeThe TextureType enum value.
Returns
A reference to the corresponding texture descriptor.

◆ textureDescriptor() [2/4]

const TextureDescriptor & vcl::Material::textureDescriptor ( TextureType  type) const
inline

Gets the texture descriptor for a given texture type.

Parameters
[in]typeThe TextureType enum value.
Returns
A const reference to the corresponding texture descriptor.

◆ textureDescriptor() [3/4]

TextureDescriptor & vcl::Material::textureDescriptor ( uint  type)
inline

Gets a mutable reference to the texture descriptor for a given texture type index.

Parameters
[in]typeThe integer index of the texture type. Must be less than TextureType::COUNT.
Returns
A reference to the corresponding texture descriptor.

◆ textureDescriptor() [4/4]

const TextureDescriptor & vcl::Material::textureDescriptor ( uint  type) const
inline

Gets the texture descriptor for a given texture type index.

Parameters
[in]typeThe integer index of the texture type. Must be less than TextureType::COUNT.
Returns
A const reference to the corresponding texture descriptor.

◆ textureTypeToColorSpace()

static Image::ColorSpace vcl::Material::textureTypeToColorSpace ( TextureType  type)
inlinestatic

Determines the appropriate color space for a given texture type.

Base color and emissive textures contain color information and should be treated as sRGB. Other textures (metallic-roughness, normal, occlusion) contain data and should be treated as linear.

Parameters
[in]typeThe texture type.
Returns
Image::ColorSpace::SRGB or Image::ColorSpace::LINEAR.

Member Data Documentation

◆ N_TEXTURE_TYPE

const uint vcl::Material::N_TEXTURE_TYPE
inlinestaticprivate
Initial value:
=
static_cast<uint>(TextureType::COUNT)
@ COUNT
Utility value to get the number of texture types.

◆ TEXTURE_TYPE_NAMES

const std:: array<std::string, toUnderlying(TextureType::COUNT)> vcl::Material::TEXTURE_TYPE_NAMES
inlinestatic
Initial value:
= {
"baseColorTex",
"metallicRoughnessTex",
"normalTex",
"occlusionTex",
"emissiveTex"}

The documentation for this class was generated from the following file: