20 if (!m_materialBuffer) {
26 m_materialBuffer->SetSlot(1);
40 if (m_specularTexture)
42 if (m_roughnessTexture)
44 if (m_metallicTexture)
48 if (m_emissiveTexture)
51 if (m_materialBuffer) {
53 m_materialBuffer->Update(&data,
sizeof(data));
54 m_materialBuffer->Update();
67 data.
HasAOMap = m_aoTexture.IsValid() ? 1u : 0u;
71 Math::Vector4D diffNorm = m_diffuseColor.
normalize();
77 Math::Vector4D specNorm = m_specularColor.
normalize();
83 Math::Vector4D emitNorm = m_emissiveColor.
normalize();
124 if (m_materialBuffer) {
126 m_materialBuffer->Update(&data,
sizeof(data));
127 m_materialBuffer->Update();
143 return m_shader.IsValid() ? m_shader.operator->() :
nullptr;
147 m_diffuseTexture = texture;
151 AdoptTexture(m_diffuseTexture, texture);
160 return m_diffuseTexture.get();
164 return m_diffuseTexture.IsValid();
168 m_normalTexture = texture;
172 AdoptTexture(m_normalTexture, texture);
181 return m_normalTexture.get();
185 return m_normalTexture.IsValid();
189 m_specularTexture = texture;
193 AdoptTexture(m_specularTexture, texture);
202 return m_specularTexture.get();
206 return m_specularTexture.IsValid();
210 m_roughnessTexture = texture;
214 AdoptTexture(m_roughnessTexture, texture);
223 return m_roughnessTexture.get();
227 return m_roughnessTexture.IsValid();
231 m_metallicTexture = texture;
235 AdoptTexture(m_metallicTexture, texture);
244 return m_metallicTexture.get();
248 return m_metallicTexture.IsValid();
252 m_aoTexture = texture;
256 AdoptTexture(m_aoTexture, texture);
267 return m_aoTexture.IsValid();
271 m_emissiveTexture = texture;
275 AdoptTexture(m_emissiveTexture, texture);
284 return m_emissiveTexture.get();
288 return m_emissiveTexture.IsValid();
292 m_diffuseColor = color;
302 static_cast<uint8_t
>(r * 255.0f),
303 static_cast<uint8_t
>(g * 255.0f),
304 static_cast<uint8_t
>(b * 255.0f),
305 static_cast<uint8_t
>(a * 255.0f));
311 m_specularColor = color;
320 return m_specularColor;
324 m_emissiveColor = color;
333 static_cast<uint8_t
>(r * 255.0f),
334 static_cast<uint8_t
>(g * 255.0f),
335 static_cast<uint8_t
>(b * 255.0f), 255);
339 return m_emissiveColor;
343 m_shininess = shininess;
349 m_metallic = metallic;
355 m_roughness = roughness;
365 m_normalIntensity = intensity;
371 m_emissiveIntensity = intensity;
375 return m_emissiveIntensity;
383 m_alphaCutoff = cutoff;
394 m_tilingX = tiling.
GetX();
395 m_tilingY = tiling.
GetY();
408 m_offsetX = offset.
GetX();
409 m_offsetY = offset.
GetY();
425 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
void SetRoughnessTexture(const RefPtr< Texture > &texture)
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
Texture * GetNormalTexture() const
void SetAOTexture(const RefPtr< Texture > &texture)
void SetOpacity(float opacity)
Texture * GetDiffuseTexture() const
void SetMetallic(float metallic)
void SetShininess(float shininess)
void SetEmissiveTexture(const RefPtr< Texture > &texture)
bool HasEmissiveTexture() const
void SetOffset(float x, float y)
bool HasAOTexture() const
void SetDiffuseTexture(const RefPtr< Texture > &texture)
void SetNormalTexture(const RefPtr< 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.
bool HasRoughnessTexture() const
void BindTexturesAndCB()
Binds textures and uploads the material CB for the deferred geometry pass, skipping the shader bind.
bool HasSpecularTexture() const
void SetSpecularTexture(const RefPtr< Texture > &texture)
Texture * GetSpecularTexture() const
Math::Vector2D GetTiling() const
Math::Color GetDiffuseColor() const
void SetMetallicTexture(const RefPtr< Texture > &texture)
void SetTwoSided(bool twoSided)
MaterialRenderMode GetRenderMode() const
bool HasDiffuseTexture() const
void SetNormalIntensity(float intensity)
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].
constexpr float GetY() const
constexpr float GetX() const
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.