23#ifndef VCL_SPACE_CORE_MATERIAL_H
24#define VCL_SPACE_CORE_MATERIAL_H
28#include "texture_descriptor.h"
30#include <vclib/base.h>
74 inline static const std::
76 TEXTURE_TYPE_NAMES = {
78 "metallicRoughnessTex",
84 inline static const uint N_TEXTURE_TYPE =
90 Color mBaseColor = Color::White;
92 float mMetallic = 0.0f;
94 float mRoughness = 1.0f;
97 Color mEmissiveColor = Color::Black;
101 float mAlphaCutoff = 0.5f;
103 float mNormalScale = 1.0f;
105 float mOcclusionStrength = 1.0f;
107 std::array<TextureDescriptor, N_TEXTURE_TYPE> mTextureDescriptors;
109 bool mDoubleSided =
false;
135 const std::string&
name()
const {
return mName; }
141 std::string&
name() {
return mName; }
263 return mTextureDescriptors[toUnderlying(
BASE_COLOR)];
274 return mTextureDescriptors[toUnderlying(
BASE_COLOR)];
285 assert(type < N_TEXTURE_TYPE);
286 return mTextureDescriptors[type];
308 assert(type < N_TEXTURE_TYPE);
309 return mTextureDescriptors[type];
329 vcl::serialize(
os, mName);
330 mBaseColor.serialize(
os);
331 vcl::serialize(
os, mMetallic, mRoughness);
332 mEmissiveColor.serialize(
os);
333 vcl::serialize(
os, mAlphaMode, mAlphaCutoff);
334 vcl::serialize(
os, mNormalScale);
335 vcl::serialize(
os, mOcclusionStrength);
336 vcl::serialize(
os, mTextureDescriptors);
337 vcl::serialize(
os, mDoubleSided);
346 vcl::deserialize(is, mName);
347 mBaseColor.deserialize(is);
348 vcl::deserialize(is, mMetallic, mRoughness);
349 mEmissiveColor.deserialize(is);
350 vcl::deserialize(is, mAlphaMode, mAlphaCutoff);
351 vcl::deserialize(is, mNormalScale);
352 vcl::deserialize(is, mOcclusionStrength);
353 vcl::deserialize(is, mTextureDescriptors);
354 vcl::deserialize(is, mDoubleSided);
383 default:
return Image::ColorSpace::LINEAR;
402 std::remove_cvref_t<T>,
A class representing a box in N-dimensional space.
Definition box.h:46
The Color class represents a 32 bit color.
Definition color.h:48
Represents a Physically-Based Rendering (PBR) material.
Definition material.h:45
bool operator==(const Material &other) const =default
Defaulted equality comparison operator.
TextureDescriptor & textureDescriptor(TextureType type)
Gets a mutable reference to the texture descriptor for a given texture type.
Definition material.h:318
void deserialize(std::istream &is)
Deserializes the material's data from an input stream.
Definition material.h:344
float & roughness()
Gets a mutable reference to the roughness factor of the material.
Definition material.h:178
std::string & name()
Gets a mutable reference to the name of the material.
Definition material.h:141
const TextureDescriptor & baseColorTextureDescriptor() const
Gets the texture descriptor for the base color texture.
Definition material.h:260
TextureType
Defines the types of textures used in the PBR material model.
Definition material.h:62
@ NORMAL
The tangent-space normal map. Stored in linear color space.
@ COUNT
Utility value to get the number of texture types.
@ BASE_COLOR
The base color (albedo) texture. Stored in sRGB color space.
@ EMISSIVE
The emissive color texture. Stored in sRGB color space.
const TextureDescriptor & textureDescriptor(uint type) const
Gets the texture descriptor for a given texture type index.
Definition material.h:283
const std::string & name() const
Gets the name of the material.
Definition material.h:135
bool & doubleSided()
Gets a mutable reference to the double-sided property.
Definition material.h:230
const TextureDescriptor & textureDescriptor(TextureType type) const
Gets the texture descriptor for a given texture type.
Definition material.h:294
float & alphaCutoff()
Gets a mutable reference to the alpha cutoff value.
Definition material.h:216
Color & emissiveColor()
Gets a mutable reference to the emissive color of the material.
Definition material.h:191
const Color & emissiveColor() const
Gets the emissive color of the material. This is the color emitted by the material,...
Definition material.h:185
void serialize(std::ostream &os) const
Serializes the material's data to an output stream.
Definition material.h:327
AlphaMode & alphaMode()
Gets a mutable reference to the alpha rendering mode.
Definition material.h:203
static Image::ColorSpace textureTypeToColorSpace(TextureType type)
Determines the appropriate color space for a given texture type.
Definition material.h:375
Material()
Default constructor.
Definition material.h:129
float metallic() const
Gets the metallic factor of the material.
Definition material.h:160
Color & baseColor()
Gets a mutable reference to the base color of the material.
Definition material.h:154
float & metallic()
Gets a mutable reference to the metallic factor of the material.
Definition material.h:166
float occlusionStrength() const
Gets the strength of the ambient occlusion effect.
Definition material.h:248
float alphaCutoff() const
Gets the alpha cutoff value. This value is used only when the alpha mode is ALPHA_MASK.
Definition material.h:210
float & occlusionStrength()
Gets a mutable reference to the occlusion strength.
Definition material.h:254
AlphaMode
Defines the alpha rendering mode of the material.
Definition material.h:50
float normalScale() const
Gets the scalar multiplier for the normal map.
Definition material.h:236
TextureDescriptor & baseColorTextureDescriptor()
Gets a mutable reference to the texture descriptor for the base color texture.
Definition material.h:271
TextureDescriptor & textureDescriptor(uint type)
Gets a mutable reference to the texture descriptor for a given texture type index.
Definition material.h:306
float & normalScale()
Gets a mutable reference to the normal scale.
Definition material.h:242
AlphaMode alphaMode() const
Gets the alpha rendering mode.
Definition material.h:197
const Color & baseColor() const
Gets the base color of the material. This is used as a tint if a base color texture is present.
Definition material.h:148
float roughness() const
Gets the roughness factor of the material.
Definition material.h:172
bool doubleSided() const
Checks if the material is double-sided. If true, both front and back faces of polygons with this mate...
Definition material.h:224
Describes the properties of a texture, such as its source path and rendering parameters.
Definition texture_descriptor.h:42
A concept representing a Material.
Definition material.h:401