SleakEngine 0.1.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
Texture * GetAOTexture () const
Math::Color GetDiffuseColor () const
Texture * GetDiffuseTexture () const
Math::Color GetEmissiveColor () const
float GetEmissiveIntensity () const
Texture * GetEmissiveTexture () const
float GetMetallic () const
Texture * GetMetallicTexture () const
float GetNormalIntensity () const
Texture * GetNormalTexture () const
Math::Vector2D GetOffset () const
float GetOpacity () const
MaterialRenderMode GetRenderMode () const
float GetRoughness () const
Texture * GetRoughnessTexture () const
RenderEngine::Shader * GetShader () const
float GetShininess () const
Math::Color GetSpecularColor () const
Texture * GetSpecularTexture () 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 RefPtr< Texture > &texture)
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 RefPtr< Texture > &texture)
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 RefPtr< Texture > &texture)
void SetEmissiveTexture (const std::string &path)
void SetEmissiveTexture (Texture *texture)
void SetMetallic (float metallic)
void SetMetallicTexture (const RefPtr< Texture > &texture)
void SetMetallicTexture (const std::string &path)
void SetMetallicTexture (Texture *texture)
void SetNormalIntensity (float intensity)
void SetNormalTexture (const RefPtr< Texture > &texture)
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 RefPtr< Texture > &texture)
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 RefPtr< Texture > &texture)
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
std::string GetDebugName () const
 Name plus unique ID, for logs where names can repeat.
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. Textures are held by RefPtr too. Each texture setter takes a RefPtr<Texture> to share one texture between materials, a raw Texture* the material adopts (do not hand the same raw pointer to two materials), or 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 90 of file Material.hpp.

Constructor & Destructor Documentation

◆ Material()

Sleak::Material::Material ( )

Definition at line 14 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 31 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 114 of file Material.cpp.

◆ GetAlphaCutoff()

float Sleak::Material::GetAlphaCutoff ( ) const

Definition at line 386 of file Material.cpp.

◆ GetAO()

float Sleak::Material::GetAO ( ) const

Definition at line 362 of file Material.cpp.

◆ GetAOTexture()

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

Definition at line 264 of file Material.cpp.

◆ GetDiffuseColor()

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

Definition at line 308 of file Material.cpp.

◆ GetDiffuseTexture()

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

Definition at line 159 of file Material.cpp.

◆ GetEmissiveColor()

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

Definition at line 338 of file Material.cpp.

◆ GetEmissiveIntensity()

float Sleak::Material::GetEmissiveIntensity ( ) const

Definition at line 374 of file Material.cpp.

◆ GetEmissiveTexture()

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

Definition at line 283 of file Material.cpp.

◆ GetMetallic()

float Sleak::Material::GetMetallic ( ) const

Definition at line 352 of file Material.cpp.

◆ GetMetallicTexture()

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

Definition at line 243 of file Material.cpp.

◆ GetNormalIntensity()

float Sleak::Material::GetNormalIntensity ( ) const

Definition at line 368 of file Material.cpp.

◆ GetNormalTexture()

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

Definition at line 180 of file Material.cpp.

◆ GetOffset()

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

Definition at line 412 of file Material.cpp.

◆ GetOpacity()

float Sleak::Material::GetOpacity ( ) const

Definition at line 380 of file Material.cpp.

◆ GetRenderMode()

MaterialRenderMode Sleak::Material::GetRenderMode ( ) const

Definition at line 420 of file Material.cpp.

◆ GetRoughness()

float Sleak::Material::GetRoughness ( ) const

Definition at line 358 of file Material.cpp.

◆ GetRoughnessTexture()

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

Definition at line 222 of file Material.cpp.

◆ GetShader()

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

Definition at line 142 of file Material.cpp.

◆ GetShininess()

float Sleak::Material::GetShininess ( ) const

Definition at line 346 of file Material.cpp.

◆ GetSpecularColor()

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

Definition at line 319 of file Material.cpp.

◆ GetSpecularTexture()

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

Definition at line 201 of file Material.cpp.

◆ GetTiling()

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

Definition at line 398 of file Material.cpp.

◆ HasAOTexture()

bool Sleak::Material::HasAOTexture ( ) const

Definition at line 266 of file Material.cpp.

◆ HasDiffuseTexture()

bool Sleak::Material::HasDiffuseTexture ( ) const

Definition at line 163 of file Material.cpp.

◆ HasEmissiveTexture()

bool Sleak::Material::HasEmissiveTexture ( ) const

Definition at line 287 of file Material.cpp.

◆ HasMetallicTexture()

bool Sleak::Material::HasMetallicTexture ( ) const

Definition at line 247 of file Material.cpp.

◆ HasNormalTexture()

bool Sleak::Material::HasNormalTexture ( ) const

Definition at line 184 of file Material.cpp.

◆ HasRoughnessTexture()

bool Sleak::Material::HasRoughnessTexture ( ) const

Definition at line 226 of file Material.cpp.

◆ HasSpecularTexture()

bool Sleak::Material::HasSpecularTexture ( ) const

Definition at line 205 of file Material.cpp.

◆ Initialize()

void Sleak::Material::Initialize ( )

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

Definition at line 19 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 108 of file Material.cpp.

◆ IsTwoSided()

bool Sleak::Material::IsTwoSided ( ) const

Definition at line 428 of file Material.cpp.

◆ SetAlphaCutoff()

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

Definition at line 382 of file Material.cpp.

◆ SetAO()

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

Definition at line 360 of file Material.cpp.

◆ SetAOTexture() [1/3]

void Sleak::Material::SetAOTexture ( const RefPtr< Texture > & texture)

Definition at line 251 of file Material.cpp.

◆ SetAOTexture() [2/3]

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

Definition at line 259 of file Material.cpp.

◆ SetAOTexture() [3/3]

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

Definition at line 255 of file Material.cpp.

◆ SetDiffuseColor() [1/3]

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

Definition at line 300 of file Material.cpp.

◆ SetDiffuseColor() [2/3]

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

Definition at line 291 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 295 of file Material.cpp.

◆ SetDiffuseTexture() [1/3]

void Sleak::Material::SetDiffuseTexture ( const RefPtr< Texture > & texture)

Definition at line 146 of file Material.cpp.

◆ SetDiffuseTexture() [2/3]

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

Definition at line 154 of file Material.cpp.

◆ SetDiffuseTexture() [3/3]

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

Definition at line 150 of file Material.cpp.

◆ SetEmissiveColor() [1/3]

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

Definition at line 331 of file Material.cpp.

◆ SetEmissiveColor() [2/3]

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

Definition at line 323 of file Material.cpp.

◆ SetEmissiveColor() [3/3]

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

Definition at line 327 of file Material.cpp.

◆ SetEmissiveIntensity()

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

Definition at line 370 of file Material.cpp.

◆ SetEmissiveTexture() [1/3]

void Sleak::Material::SetEmissiveTexture ( const RefPtr< Texture > & texture)

Definition at line 270 of file Material.cpp.

◆ SetEmissiveTexture() [2/3]

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

Definition at line 278 of file Material.cpp.

◆ SetEmissiveTexture() [3/3]

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

Definition at line 274 of file Material.cpp.

◆ SetMetallic()

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

Definition at line 348 of file Material.cpp.

◆ SetMetallicTexture() [1/3]

void Sleak::Material::SetMetallicTexture ( const RefPtr< Texture > & texture)

Definition at line 230 of file Material.cpp.

◆ SetMetallicTexture() [2/3]

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

Definition at line 238 of file Material.cpp.

◆ SetMetallicTexture() [3/3]

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

Definition at line 234 of file Material.cpp.

◆ SetNormalIntensity()

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

Definition at line 364 of file Material.cpp.

◆ SetNormalTexture() [1/3]

void Sleak::Material::SetNormalTexture ( const RefPtr< Texture > & texture)

Definition at line 167 of file Material.cpp.

◆ SetNormalTexture() [2/3]

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

Definition at line 175 of file Material.cpp.

◆ SetNormalTexture() [3/3]

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

Definition at line 171 of file Material.cpp.

◆ SetOffset() [1/2]

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

Definition at line 402 of file Material.cpp.

◆ SetOffset() [2/2]

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

Definition at line 407 of file Material.cpp.

◆ SetOpacity()

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

Definition at line 378 of file Material.cpp.

◆ SetRenderMode()

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

Definition at line 416 of file Material.cpp.

◆ SetRoughness()

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

Definition at line 354 of file Material.cpp.

◆ SetRoughnessTexture() [1/3]

void Sleak::Material::SetRoughnessTexture ( const RefPtr< Texture > & texture)

Definition at line 209 of file Material.cpp.

◆ SetRoughnessTexture() [2/3]

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

Definition at line 217 of file Material.cpp.

◆ SetRoughnessTexture() [3/3]

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

Definition at line 213 of file Material.cpp.

◆ SetShader() [1/2]

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

Definition at line 135 of file Material.cpp.

◆ SetShader() [2/2]

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

Definition at line 131 of file Material.cpp.

◆ SetShininess()

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

Definition at line 342 of file Material.cpp.

◆ SetSpecularColor() [1/2]

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

Definition at line 310 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 314 of file Material.cpp.

◆ SetSpecularTexture() [1/3]

void Sleak::Material::SetSpecularTexture ( const RefPtr< Texture > & texture)

Definition at line 188 of file Material.cpp.

◆ SetSpecularTexture() [2/3]

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

Definition at line 196 of file Material.cpp.

◆ SetSpecularTexture() [3/3]

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

Definition at line 192 of file Material.cpp.

◆ SetTiling() [1/2]

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

Definition at line 388 of file Material.cpp.

◆ SetTiling() [2/2]

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

Definition at line 393 of file Material.cpp.

◆ SetTwoSided()

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

Definition at line 424 of file Material.cpp.