4#include "Foundation/StringView.h"
37 void setupInstance(
Material * material);
103 uint16_t
getMaterialFlags()
const {
return (material->materialFlags & instanceFlags) | instanceFlags; }
106 void setBackdrop() { setMaterialFlag(MaterialFlags::Backdrop); options.depthWriteEnabled =
false; }
109 void unsetBackdrop() { unsetMaterialFlag(MaterialFlags::Backdrop); options.depthWriteEnabled &=
true; }
116 bool isBackdrop()
const {
return instanceFlags & MaterialFlags::Backdrop ? true :
false; }
124 void setTransparent();
137 bool hasTransparency()
const;
149 void setProperty(
const StringView & key,
const void * value,
const size_t sizeInBytes);
150 void setProperty(
VariableKey key,
const void * value,
const size_t sizeInBytes);
152 bool getProperty(
const StringView & key,
void * value,
const size_t sizeInBytes)
const;
153 bool getProperty(
VariableKey key,
void * value,
const size_t sizeInBytes)
const;
184 auto & materialProperty = material->constantBuffers.variables[key];
185 if (!materialProperty.isPerInstance)
187 material->setProperty(key, value);
190 if (materialProperty.flags != MaterialPropertyFlags::None) {
191 enforcePropertyFlags(materialProperty, materialProperty.flags, &value);
194 buffers[materialProperty.buffer].setValue(materialProperty.descriptor.offset, value);
215 getProperty(key, &t,
sizeof(T));
227 setProperty(key, value);
238 setProperty(key, value);
249 setProperty(key, value);
260 setProperty(key, value);
271 setProperty(key, value);
282 setProperty(key, value);
285 void setIntProperty(
const VariableKey key,
int value)
287 setProperty(key, value);
290 void setUIntProperty(
const VariableKey key, uint32_t value)
292 setProperty(key, value);
303 setProperty(key, value);
336 return getProperty<glm::vec2>(key);
348 return getProperty<glm::vec3>(key);
360 return getProperty<glm::vec4>(key);
372 return getProperty<glm::mat4>(key);
384 return getProperty<bool>(key);
396 return getProperty<float>(key);
408 if (key != NoProperty) {
409 return textureVariables[key];
414 size_t getPermutationIndex(
const StringView & key)
const;
420 void setVariant(
size_t index,
int value);
421 void setVariant(
size_t index,
bool value);
422 void setVariant(
size_t index,
const StringView & value);
425 void setVariant(
const StringView & key,
const char* value) { setVariant(key,
StringView(value)); }
426 void setVariant(
const StringView & key,
bool value);
427 void setVariant(
const StringView & key,
int value);
429 std::string getVariant(
const StringView & key)
const;
438 std::vector<MaterialPropertyBufferInstance>
buffers;
444 uint16_t instanceFlags = MaterialFlags::None;
456 size_t permutationIndex = 0;
459 size_t variantGeneration = 0;
462 uint16_t buffersGeneration = 1;
Provides a weakly referenced view over the contents of a string.
uint16_t VariableKey
Used to lookup material properties.
Contains all Cogs related functionality.
void setChanged(Cogs::Core::Context *context, Cogs::ComponentModel::Component *component, Reflection::FieldId fieldId)
Must be Called after changing a Component field. Mark field changed. Request engine update.
EMaterialFlags
Material flags.
Material instances represent a specialized Material combined with state for all its buffers and prope...
std::vector< TextureValue > textureVariables
Texture property values for this instance.
uint16_t getMaterialFlags() const
Gets flags of the instance, combined from material flags and overrides from instance.
bool isDefaultMaterial() const
Gets if this material instance is created from the default material.
void setBackdrop()
Set the material instance to act as backdrop when rendering.
MaterialInstance(MaterialInstance &&other) noexcept=default
Move construct MaterialInstance from other.
glm::vec4 getVec4Property(const VariableKey key) const
Get the value of the property with the given key.
void setFloatProperty(const VariableKey key, float value)
Set the float property with the given key to value.
bool isBackdrop() const
Get if geometry rendered with this material instance is to be treated as backdrops.
void setInt4Property(const VariableKey key, glm::ivec4 value)
Set the ivec4 property with the given key to value.
T getProperty(const VariableKey key) const
Get the property value of the property with the given key in the given collection.
void unsetBackdrop()
Set the material instance to act as regular geometry, not backdrop, when rendering.
bool getBoolProperty(const VariableKey key) const
Get the value of the property with the given key.
TextureValue getTextureProperty(const VariableKey key) const
Get the value of the property with the given key.
std::vector< MaterialPropertyBufferInstance > buffers
Buffer instances matching the buffers and layout of the parent material.
void setVec3Property(const VariableKey key, glm::vec3 value)
Set the vec3 property with the given key to value.
std::vector< std::string > variantStrings
String storage for string variants.
float getFloatProperty(const VariableKey key) const
Get the value of the property with the given key.
glm::vec3 getVec3Property(const VariableKey key) const
Get the value of the property with the given key.
void setProperty(const VariableKey key, T value)
Set the property value of the property with the given key.
void setMaterialFlag(MaterialFlags::EMaterialFlags flag)
Set the given material flag.
MaterialInstanceHandle masterInstance
Master material instance overriding properties in this instance if override is enabled.
void unsetMaterialFlag(MaterialFlags::EMaterialFlags flag)
Unset the given material flag.
void setVec2Property(const VariableKey key, glm::vec2 value)
Set the vec2 property with the given key to value.
MaterialOptions options
Material rendering options used by this instance.
void setVec4Property(const VariableKey key, glm::vec4 value)
Set the vec4 property with the given key to value.
void setMaterialFlag(MaterialFlags::EMaterialFlags flag, bool status)
Set the given material flag to the given state.
void setBoolProperty(const VariableKey key, bool value)
Set the bool property with the given key to value.
MaterialInstance & operator=(MaterialInstance &&other) noexcept=default
Move assign MaterialInstance from other.
glm::vec2 getVec2Property(const VariableKey key) const
Get the value of the property with the given key.
ShaderVariantSelectors variantSelectors
Variant selectors.
MaterialInstance()=default
void setMat4Property(const VariableKey key, glm::mat4 value)
Set the mat4 property with the given key to value.
glm::mat4 getMat4Property(const VariableKey key) const
Get the value of the property with the given key.
Defines options for rendering using a material instance.
Material resources define the how of geometry rendering (the what is defined by Mesh and Texture reso...
Base class for engine resources.
AddressMode
Addressing modes to use when sampling textures.
FilterMode
Filter modes to specify how texture data is treated when sampled.