#include <materialinstance.h>
To draw an object with a Material, you must use a MaterialInstance. MaterialInstance contains the runtime data for drawing a Material. MaterialInstance is intended to be used as a property in Components. It must be initialized based on a MaterialInstanceResource object to fill its runtime data. init() must be called from the ComponentInstance's init() function. Before drawing, make sure to call update() to update the uniforms and samplers. A descriptorset will be returned that can be used to issue the Vulkan draw call.
Multiple MaterialInstances can share a single Material and a single MaterialInstance can override Material properties on a per-instance basis. This means that you can set uniform or texture data on Material level, which means that, as long as the property isn't overridden, you will set it for all MaterialInstances in one go. If you set a property on MaterialInstance level, you will set it only for that MaterialInstance.
It is also possible to set uniform or texture state on a single MaterialInstance multiple times per frame. When multiple draws are performed with the frame, the state at the point of draw will be used.
Note that there is no implicit synchronization of access to shader resources bound to storage and regular uniforms between render passes. Therefore, it is currently not recommended to write to storage buffers inside vertex and/or fragment shaders over consecutive render passes within a single frame.
Performance note: changing the Depth mode or Blend mode frequently on a single MaterialInstance is not recommended, as it requires a rebuild of the entire GPU pipeline. If changing it per frame is required, consider using multiple MaterialInstance objects and switch between them instead.
EBlendMode getBlendMode | ( | ) | const |
EDepthMode getDepthMode | ( | ) | const |
Material& getMaterial | ( | ) |
const Material& getMaterial | ( | ) | const |
bool init | ( | RenderService & | renderService, |
MaterialInstanceResource & | resource, | ||
utility::ErrorState & | errorState | ||
) |
Initializes all runtime structures for MaterialInstance.
void setBlendMode | ( | EBlendMode | blendMode | ) |
Sets the blend mode that is used when rendering an object with this material. Note that frequently changing the blend mode on the same MaterialInstance requires a rebuild of the underlying GPU pipeline. When frequent changes are required, it is recommended to use multiple MaterialInstance objects instead.
blendMode | the new blend mode |
void setDepthMode | ( | EDepthMode | depthMode | ) |
Sets the depth mode that is used when rendering an object with this material. Note that frequently changing the depth mode on the same MaterialInstance requires a rebuild of the underlying GPU pipeline. When frequent changes are required, it is recommended to use multiple MaterialInstance objects instead.
depthMode | the new depth mode |