14 if (!m_materialBuffer) {
20 m_materialBuffer->SetSlot(1);
34 if (m_specularTexture)
36 if (m_roughnessTexture)
38 if (m_metallicTexture)
42 if (m_emissiveTexture)
45 if (m_materialBuffer) {
47 m_materialBuffer->Update(&data,
sizeof(data));
48 m_materialBuffer->Update();
61 data.
HasAOMap = m_aoTexture.IsValid() ? 1u : 0u;
65 Math::Vector4D diffNorm = m_diffuseColor.
normalize();
71 Math::Vector4D specNorm = m_specularColor.
normalize();
77 Math::Vector4D emitNorm = m_emissiveColor.
normalize();
118 if (m_materialBuffer) {
120 m_materialBuffer->Update(&data,
sizeof(data));
121 m_materialBuffer->Update();
137 return m_shader.IsValid() ? m_shader.operator->() :
nullptr;
150 return m_diffuseTexture.IsValid() ? m_diffuseTexture.operator->()
155 return m_diffuseTexture.IsValid();
168 return m_normalTexture.IsValid() ? m_normalTexture.operator->()
173 return m_normalTexture.IsValid();
186 return m_specularTexture.IsValid() ? m_specularTexture.operator->()
191 return m_specularTexture.IsValid();
204 return m_roughnessTexture.IsValid()
205 ? m_roughnessTexture.operator->()
210 return m_roughnessTexture.IsValid();
223 return m_metallicTexture.IsValid()
224 ? m_metallicTexture.operator->()
229 return m_metallicTexture.IsValid();
242 return m_aoTexture.IsValid() ? m_aoTexture.operator->() :
nullptr;
246 return m_aoTexture.IsValid();
259 return m_emissiveTexture.IsValid()
260 ? m_emissiveTexture.operator->()
265 return m_emissiveTexture.IsValid();
269 m_diffuseColor = color;
279 static_cast<uint8_t
>(r * 255.0f),
280 static_cast<uint8_t
>(g * 255.0f),
281 static_cast<uint8_t
>(b * 255.0f),
282 static_cast<uint8_t
>(a * 255.0f));
288 m_specularColor = color;
297 return m_specularColor;
301 m_emissiveColor = color;
310 static_cast<uint8_t
>(r * 255.0f),
311 static_cast<uint8_t
>(g * 255.0f),
312 static_cast<uint8_t
>(b * 255.0f), 255);
316 return m_emissiveColor;
320 m_shininess = shininess;
326 m_metallic = metallic;
332 m_roughness = roughness;
342 m_normalIntensity = intensity;
348 m_emissiveIntensity = intensity;
352 return m_emissiveIntensity;
360 m_alphaCutoff = cutoff;
371 m_tilingX = tiling.
GetX();
372 m_tilingY = tiling.
GetY();
385 m_offsetX = offset.
GetX();
386 m_offsetY = offset.
GetY();
402 m_twoSided = twoSided;
#define TEXTURE_SLOT_DIFFUSE
#define TEXTURE_SLOT_METALLIC
#define TEXTURE_SLOT_NORMAL
#define TEXTURE_SLOT_SPECULAR
#define TEXTURE_SLOT_EMISSIVE
#define TEXTURE_SLOT_ROUGHNESS
float GetAlphaCutoff() const
Math::Color GetEmissiveColor() const
Texture * GetRoughnessTexture() const
void SetShader(RenderEngine::Shader *shader)
Texture * GetMetallicTexture() const
bool HasNormalTexture() const
Math::Color GetSpecularColor() const
RenderEngine::Shader * GetShader() const
void SetMetallicTexture(Texture *texture)
Texture * GetNormalTexture() const
void SetNormalTexture(Texture *texture)
void SetOpacity(float opacity)
Texture * GetDiffuseTexture() const
void SetMetallic(float metallic)
void SetShininess(float shininess)
bool HasEmissiveTexture() const
void SetOffset(float x, float y)
bool HasAOTexture() const
void SetAOTexture(Texture *texture)
void SetDiffuseTexture(Texture *texture)
void SetSpecularColor(Math::Color color)
float GetShininess() const
Texture * GetEmissiveTexture() const
void SetRenderMode(MaterialRenderMode mode)
void SetAlphaCutoff(float cutoff)
void Initialize()
Lazily allocates the material's constant buffer on first use.
void SetSpecularTexture(Texture *texture)
bool HasRoughnessTexture() const
void BindTexturesAndCB()
Binds textures and uploads the material CB for the deferred geometry pass, skipping the shader bind.
bool HasSpecularTexture() const
Texture * GetSpecularTexture() const
void SetRoughnessTexture(Texture *texture)
Math::Vector2D GetTiling() const
Math::Color GetDiffuseColor() const
void SetTwoSided(bool twoSided)
MaterialRenderMode GetRenderMode() const
bool HasDiffuseTexture() const
void SetNormalIntensity(float intensity)
void SetEmissiveTexture(Texture *texture)
Math::Vector2D GetOffset() const
void SetEmissiveColor(Math::Color color)
void SetDiffuseColor(Math::Color color)
void SetRoughness(float roughness)
bool IsForwardRendered() const
True when this material must skip the GBuffer and render in the forward transparent pass.
Texture * GetAOTexture() const
float GetNormalIntensity() const
float GetRoughness() const
void SetTiling(float x, float y)
float GetMetallic() const
void SetEmissiveIntensity(float intensity)
void Bind()
Binds shader, all set textures, and uploads the packed material CB for a forward draw.
float GetEmissiveIntensity() const
bool HasMetallicTexture() const
Vector4D normalize() const noexcept
Converts to a Vector4D with each channel in [0,1].
Object(const std::string &name="Object")
static Shader * CreateShader(const std::string &ShaderPath)
Compiles a shader via the currently registered backend factory.
static Sleak::Texture * CreateTexture(const std::string &TexturePath)
Loads a texture via the currently registered backend factory.
static BufferBase * CreateBuffer(BufferType Type, uint32_t Size, void *Data)
Creates a buffer via the currently registered backend factory.
Backend-agnostic compiled shader program.
Root namespace for everything the engine exposes.
Packed PBR material parameters uploaded to the material constant buffer.