SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Material Class Reference

#include <Material.hpp>

Inheritance diagram for Sleak::Material:

Public Member Functions

 Material ()
 ~Material () override
void Bind ()
 Binds shader, all set textures, and uploads the packed material CB for a forward draw.
void BindTexturesAndCB ()
 Binds textures and uploads the material CB for the deferred geometry pass, skipping the shader bind.
float GetAlphaCutoff () const
float GetAO () const
TextureGetAOTexture () const
Math::Color GetDiffuseColor () const
TextureGetDiffuseTexture () const
Math::Color GetEmissiveColor () const
float GetEmissiveIntensity () const
TextureGetEmissiveTexture () const
float GetMetallic () const
TextureGetMetallicTexture () const
float GetNormalIntensity () const
TextureGetNormalTexture () const
Math::Vector2D GetOffset () const
float GetOpacity () const
MaterialRenderMode GetRenderMode () const
float GetRoughness () const
TextureGetRoughnessTexture () const
RenderEngine::ShaderGetShader () const
float GetShininess () const
Math::Color GetSpecularColor () const
TextureGetSpecularTexture () const
Math::Vector2D GetTiling () const
bool HasAOTexture () const
bool HasDiffuseTexture () const
bool HasEmissiveTexture () const
bool HasMetallicTexture () const
bool HasNormalTexture () const
bool HasRoughnessTexture () const
bool HasSpecularTexture () const
void Initialize ()
 Lazily allocates the material's constant buffer on first use.
bool IsForwardRendered () const
 True when this material must skip the GBuffer and render in the forward transparent pass.
bool IsTwoSided () const
void SetAlphaCutoff (float cutoff)
void SetAO (float ao)
void SetAOTexture (const std::string &path)
void SetAOTexture (Texture *texture)
void SetDiffuseColor (float r, float g, float b, float a=1.0f)
void SetDiffuseColor (Math::Color color)
void SetDiffuseColor (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
void SetDiffuseTexture (const std::string &path)
void SetDiffuseTexture (Texture *texture)
void SetEmissiveColor (float r, float g, float b)
void SetEmissiveColor (Math::Color color)
void SetEmissiveColor (uint8_t r, uint8_t g, uint8_t b)
void SetEmissiveIntensity (float intensity)
void SetEmissiveTexture (const std::string &path)
void SetEmissiveTexture (Texture *texture)
void SetMetallic (float metallic)
void SetMetallicTexture (const std::string &path)
void SetMetallicTexture (Texture *texture)
void SetNormalIntensity (float intensity)
void SetNormalTexture (const std::string &path)
void SetNormalTexture (Texture *texture)
void SetOffset (float x, float y)
void SetOffset (Math::Vector2D offset)
void SetOpacity (float opacity)
void SetRenderMode (MaterialRenderMode mode)
void SetRoughness (float roughness)
void SetRoughnessTexture (const std::string &path)
void SetRoughnessTexture (Texture *texture)
void SetShader (const std::string &shaderPath)
void SetShader (RenderEngine::Shader *shader)
void SetShininess (float shininess)
void SetSpecularColor (Math::Color color)
void SetSpecularColor (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
void SetSpecularTexture (const std::string &path)
void SetSpecularTexture (Texture *texture)
void SetTiling (float x, float y)
void SetTiling (Math::Vector2D tiling)
void SetTwoSided (bool twoSided)
Public Member Functions inherited from Sleak::Object
 Object (const std::string &name="Object")
virtual ~Object ()=default
const std::string & GetName () const
uint64_t GetUniqueID () const
void SetName (const std::string &value)

Detailed Description

PBR-ish surface properties, textures, and GPU buffer for a drawable; shared across any mesh that references it.

A Material describes how a surface responds to light: a base color, metallic, roughness, ambient occlusion, emissive, and opacity, plus up to seven texture maps that override those scalars per texel. It owns its own GPU constant buffer and rebuilds it when properties change.

Materials are meant to be shared. Wrap one in a RefPtr and hand the same RefPtr to every MaterialComponent that should use it; changing a property updates every object drawn with it. Each texture setter comes in two forms, one taking an owned Texture* and one taking a file path the material loads for you.

SetRenderMode() decides how transparency is handled: MaterialRenderMode::Opaque and ::Cutout render in the normal (deferred, where the backend supports it) path, while ::Transparent forces the material into a forward pass. IsForwardRendered() reports which side a material falls on.

auto* mat = new Sleak::Material();
mat->SetShader("assets/shaders/default_shader.hlsl");
mat->SetDiffuseColor((uint8_t)230, (uint8_t)230, (uint8_t)230);
mat->SetMetallic(0.0f);
mat->SetRoughness(0.35f);
mat->SetAO(1.0f);
// Texture maps, loaded by path
mat->SetDiffuseTexture("assets/textures/crate_albedo.png");
mat->SetNormalTexture("assets/textures/crate_normal.png");
mat->SetTiling(2.0f, 2.0f);
// Share one material across many objects
crate->AddComponent<Sleak::MaterialComponent>(shared);
barrel->AddComponent<Sleak::MaterialComponent>(shared);
// Alpha-blended glass
auto* glass = new Sleak::Material();
glass->SetOpacity(0.35f);
glass->SetTwoSided(true);
See also
MaterialComponent, Texture, MaterialRenderMode, MeshBatch, RefPtr

Definition at line 87 of file Material.hpp.

Constructor & Destructor Documentation

◆ Material()

Sleak::Material::Material ( )

Definition at line 8 of file Material.cpp.

◆ ~Material()

Sleak::Material::~Material ( )
overridedefault

Member Function Documentation

◆ Bind()

void Sleak::Material::Bind ( )

Binds shader, all set textures, and uploads the packed material CB for a forward draw.

Definition at line 25 of file Material.cpp.

◆ BindTexturesAndCB()

void Sleak::Material::BindTexturesAndCB ( )

Binds textures and uploads the material CB for the deferred geometry pass, skipping the shader bind.

Bind only textures and material CB (skips shader bind). Used by the deferred geometry pass which overrides the shader.

Definition at line 108 of file Material.cpp.

◆ GetAlphaCutoff()

float Sleak::Material::GetAlphaCutoff ( ) const

Definition at line 363 of file Material.cpp.

◆ GetAO()

float Sleak::Material::GetAO ( ) const

Definition at line 339 of file Material.cpp.

◆ GetAOTexture()

Texture * Sleak::Material::GetAOTexture ( ) const

Definition at line 241 of file Material.cpp.

◆ GetDiffuseColor()

Math::Color Sleak::Material::GetDiffuseColor ( ) const

Definition at line 285 of file Material.cpp.

◆ GetDiffuseTexture()

Texture * Sleak::Material::GetDiffuseTexture ( ) const

Definition at line 149 of file Material.cpp.

◆ GetEmissiveColor()

Math::Color Sleak::Material::GetEmissiveColor ( ) const

Definition at line 315 of file Material.cpp.

◆ GetEmissiveIntensity()

float Sleak::Material::GetEmissiveIntensity ( ) const

Definition at line 351 of file Material.cpp.

◆ GetEmissiveTexture()

Texture * Sleak::Material::GetEmissiveTexture ( ) const

Definition at line 258 of file Material.cpp.

◆ GetMetallic()

float Sleak::Material::GetMetallic ( ) const

Definition at line 329 of file Material.cpp.

◆ GetMetallicTexture()

Texture * Sleak::Material::GetMetallicTexture ( ) const

Definition at line 222 of file Material.cpp.

◆ GetNormalIntensity()

float Sleak::Material::GetNormalIntensity ( ) const

Definition at line 345 of file Material.cpp.

◆ GetNormalTexture()

Texture * Sleak::Material::GetNormalTexture ( ) const

Definition at line 167 of file Material.cpp.

◆ GetOffset()

Math::Vector2D Sleak::Material::GetOffset ( ) const

Definition at line 389 of file Material.cpp.

◆ GetOpacity()

float Sleak::Material::GetOpacity ( ) const

Definition at line 357 of file Material.cpp.

◆ GetRenderMode()

MaterialRenderMode Sleak::Material::GetRenderMode ( ) const

Definition at line 397 of file Material.cpp.

◆ GetRoughness()

float Sleak::Material::GetRoughness ( ) const

Definition at line 335 of file Material.cpp.

◆ GetRoughnessTexture()

Texture * Sleak::Material::GetRoughnessTexture ( ) const

Definition at line 203 of file Material.cpp.

◆ GetShader()

RenderEngine::Shader * Sleak::Material::GetShader ( ) const

Definition at line 136 of file Material.cpp.

◆ GetShininess()

float Sleak::Material::GetShininess ( ) const

Definition at line 323 of file Material.cpp.

◆ GetSpecularColor()

Math::Color Sleak::Material::GetSpecularColor ( ) const

Definition at line 296 of file Material.cpp.

◆ GetSpecularTexture()

Texture * Sleak::Material::GetSpecularTexture ( ) const

Definition at line 185 of file Material.cpp.

◆ GetTiling()

Math::Vector2D Sleak::Material::GetTiling ( ) const

Definition at line 375 of file Material.cpp.

◆ HasAOTexture()

bool Sleak::Material::HasAOTexture ( ) const

Definition at line 245 of file Material.cpp.

◆ HasDiffuseTexture()

bool Sleak::Material::HasDiffuseTexture ( ) const

Definition at line 154 of file Material.cpp.

◆ HasEmissiveTexture()

bool Sleak::Material::HasEmissiveTexture ( ) const

Definition at line 264 of file Material.cpp.

◆ HasMetallicTexture()

bool Sleak::Material::HasMetallicTexture ( ) const

Definition at line 228 of file Material.cpp.

◆ HasNormalTexture()

bool Sleak::Material::HasNormalTexture ( ) const

Definition at line 172 of file Material.cpp.

◆ HasRoughnessTexture()

bool Sleak::Material::HasRoughnessTexture ( ) const

Definition at line 209 of file Material.cpp.

◆ HasSpecularTexture()

bool Sleak::Material::HasSpecularTexture ( ) const

Definition at line 190 of file Material.cpp.

◆ Initialize()

void Sleak::Material::Initialize ( )

Lazily allocates the material's constant buffer on first use.

Definition at line 13 of file Material.cpp.

◆ IsForwardRendered()

bool Sleak::Material::IsForwardRendered ( ) const

True when this material must skip the GBuffer and render in the forward transparent pass.

True if this material must be rendered in a forward pass (transparent, alpha-blended). Opaque and cutout materials return false.

Definition at line 102 of file Material.cpp.

◆ IsTwoSided()

bool Sleak::Material::IsTwoSided ( ) const

Definition at line 405 of file Material.cpp.

◆ SetAlphaCutoff()

void Sleak::Material::SetAlphaCutoff ( float cutoff)

Definition at line 359 of file Material.cpp.

◆ SetAO()

void Sleak::Material::SetAO ( float ao)

Definition at line 337 of file Material.cpp.

◆ SetAOTexture() [1/2]

void Sleak::Material::SetAOTexture ( const std::string & path)

Definition at line 236 of file Material.cpp.

◆ SetAOTexture() [2/2]

void Sleak::Material::SetAOTexture ( Texture * texture)

Definition at line 232 of file Material.cpp.

◆ SetDiffuseColor() [1/3]

void Sleak::Material::SetDiffuseColor ( float r,
float g,
float b,
float a = 1.0f )

Definition at line 277 of file Material.cpp.

◆ SetDiffuseColor() [2/3]

void Sleak::Material::SetDiffuseColor ( Math::Color color)

Definition at line 268 of file Material.cpp.

◆ SetDiffuseColor() [3/3]

void Sleak::Material::SetDiffuseColor ( uint8_t r,
uint8_t g,
uint8_t b,
uint8_t a = 255 )

Definition at line 272 of file Material.cpp.

◆ SetDiffuseTexture() [1/2]

void Sleak::Material::SetDiffuseTexture ( const std::string & path)

Definition at line 144 of file Material.cpp.

◆ SetDiffuseTexture() [2/2]

void Sleak::Material::SetDiffuseTexture ( Texture * texture)

Definition at line 140 of file Material.cpp.

◆ SetEmissiveColor() [1/3]

void Sleak::Material::SetEmissiveColor ( float r,
float g,
float b )

Definition at line 308 of file Material.cpp.

◆ SetEmissiveColor() [2/3]

void Sleak::Material::SetEmissiveColor ( Math::Color color)

Definition at line 300 of file Material.cpp.

◆ SetEmissiveColor() [3/3]

void Sleak::Material::SetEmissiveColor ( uint8_t r,
uint8_t g,
uint8_t b )

Definition at line 304 of file Material.cpp.

◆ SetEmissiveIntensity()

void Sleak::Material::SetEmissiveIntensity ( float intensity)

Definition at line 347 of file Material.cpp.

◆ SetEmissiveTexture() [1/2]

void Sleak::Material::SetEmissiveTexture ( const std::string & path)

Definition at line 253 of file Material.cpp.

◆ SetEmissiveTexture() [2/2]

void Sleak::Material::SetEmissiveTexture ( Texture * texture)

Definition at line 249 of file Material.cpp.

◆ SetMetallic()

void Sleak::Material::SetMetallic ( float metallic)

Definition at line 325 of file Material.cpp.

◆ SetMetallicTexture() [1/2]

void Sleak::Material::SetMetallicTexture ( const std::string & path)

Definition at line 217 of file Material.cpp.

◆ SetMetallicTexture() [2/2]

void Sleak::Material::SetMetallicTexture ( Texture * texture)

Definition at line 213 of file Material.cpp.

◆ SetNormalIntensity()

void Sleak::Material::SetNormalIntensity ( float intensity)

Definition at line 341 of file Material.cpp.

◆ SetNormalTexture() [1/2]

void Sleak::Material::SetNormalTexture ( const std::string & path)

Definition at line 162 of file Material.cpp.

◆ SetNormalTexture() [2/2]

void Sleak::Material::SetNormalTexture ( Texture * texture)

Definition at line 158 of file Material.cpp.

◆ SetOffset() [1/2]

void Sleak::Material::SetOffset ( float x,
float y )

Definition at line 379 of file Material.cpp.

◆ SetOffset() [2/2]

void Sleak::Material::SetOffset ( Math::Vector2D offset)

Definition at line 384 of file Material.cpp.

◆ SetOpacity()

void Sleak::Material::SetOpacity ( float opacity)

Definition at line 355 of file Material.cpp.

◆ SetRenderMode()

void Sleak::Material::SetRenderMode ( MaterialRenderMode mode)

Definition at line 393 of file Material.cpp.

◆ SetRoughness()

void Sleak::Material::SetRoughness ( float roughness)

Definition at line 331 of file Material.cpp.

◆ SetRoughnessTexture() [1/2]

void Sleak::Material::SetRoughnessTexture ( const std::string & path)

Definition at line 198 of file Material.cpp.

◆ SetRoughnessTexture() [2/2]

void Sleak::Material::SetRoughnessTexture ( Texture * texture)

Definition at line 194 of file Material.cpp.

◆ SetShader() [1/2]

void Sleak::Material::SetShader ( const std::string & shaderPath)

Definition at line 129 of file Material.cpp.

◆ SetShader() [2/2]

void Sleak::Material::SetShader ( RenderEngine::Shader * shader)

Definition at line 125 of file Material.cpp.

◆ SetShininess()

void Sleak::Material::SetShininess ( float shininess)

Definition at line 319 of file Material.cpp.

◆ SetSpecularColor() [1/2]

void Sleak::Material::SetSpecularColor ( Math::Color color)

Definition at line 287 of file Material.cpp.

◆ SetSpecularColor() [2/2]

void Sleak::Material::SetSpecularColor ( uint8_t r,
uint8_t g,
uint8_t b,
uint8_t a = 255 )

Definition at line 291 of file Material.cpp.

◆ SetSpecularTexture() [1/2]

void Sleak::Material::SetSpecularTexture ( const std::string & path)

Definition at line 180 of file Material.cpp.

◆ SetSpecularTexture() [2/2]

void Sleak::Material::SetSpecularTexture ( Texture * texture)

Definition at line 176 of file Material.cpp.

◆ SetTiling() [1/2]

void Sleak::Material::SetTiling ( float x,
float y )

Definition at line 365 of file Material.cpp.

◆ SetTiling() [2/2]

void Sleak::Material::SetTiling ( Math::Vector2D tiling)

Definition at line 370 of file Material.cpp.

◆ SetTwoSided()

void Sleak::Material::SetTwoSided ( bool twoSided)

Definition at line 401 of file Material.cpp.