Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Material

Add this in your code:

#include <engine/graphics/material.h>

Description

Handles the visual appearance of rendered objects, including shaders and textures.
The Material class allows you to configure how an object should look when drawn on screen.

Inspector settings


NameTypeDescription
ShaderShaderSet the material shader. Standard to use lighting, Unlit to disable lighting.
Rendering modeEnumSet the rendering mode of the material.
TextureTextureSet the material texture.
ColorColorSet the color of the material.
OffsetVector2Set the texture offset.
TilingVector2Set the texture tiling.
Use lightingCheckBoxCheck this if you are using Standard shader, uncheck this if you are using Unlit shader.

Public methods


SetAttribute

Set a value to an attribute in the shader when this material is used.

To use only when you are using custom shaders.

Parameters:

  • attribute: Attribute name
  • value: New attribute value
void SetAttribute(const char* attribute, const Vector2& value)
void SetAttribute(const char* attribute, const Vector3& value)
void SetAttribute(const char* attribute, const Vector4& value)
void SetAttribute(const char* attribute, const float value)
void SetAttribute(const char* attribute, const int value)

Code sample:

std::shared_ptr<Material> material; // Filled variable
material->SetAttribute("MyAttribute", Vector3(1, 0.5f, 1));

SetShader

Set the material shader.

Parameters:

  • shader: Shader to use
void SetShader(const std::shared_ptr<Shader>& shader)

Code sample:

std::shared_ptr<Material> material; // Filled variable
std::shared_ptr<Shader> shader; // Filled variable
material->SetShader(shader);

SetTexture

Set the material texture.

Parameters:

  • texture: Texture to use
void SetTexture(const std::shared_ptr<Texture>& texture)

Code sample:

std::shared_ptr<Material> material; // Filled variable
std::shared_ptr<Texture> texture; // Filled variable
material->SetTexture(texture);

SetUseLighting

Set the if the material uses lighting. Disable this only on Unlit shaders.

Parameters:

  • useLighting: Does the material uses lighting?
void SetUseLighting(const bool useLighting)

Code sample:

std::shared_ptr<Material> material; // Filled variable
material->SetUseLighting(true);

SetOffset

Set the texture offset.

Parameters:

  • offset: Offset of the texture
void SetOffset(const Vector2& offset)

Code sample:

std::shared_ptr<Material> material; // Filled variable
material->SetOffset(Vector2(0.5f, 0.5f));

SetTiling

Set the texture tiling.

Parameters:

  • tiling: Tiling of the texture
void SetTiling(const Vector2& tiling)

Code sample:

std::shared_ptr<Material> material; // Filled variable
material->SetTiling(Vector2(2.0f, 2.0f));

GetShader

Get the shader of the material.

 const std::shared_ptr<Shader>& GetShader() const

Code sample:

std::shared_ptr<Material> material; // Filled variable
std::shared_ptr<Shader> shader = material->GetShader();

GetTexture

Get the texture of the material.

const std::shared_ptr<Texture>& GetTexture() const

Code sample:

std::shared_ptr<Material> material; // Filled variable
std::shared_ptr<Texture> texture = material->GetTexture();

GetUseLighting

Get if the material uses lighting.

bool GetUseLighting() const

Code sample:

std::shared_ptr<Material> material; // Filled variable
bool isUsingLighting = material->GetUseLighting();

GetRenderingMode

Get the rendering mode of the material.

MaterialRenderingMode GetRenderingMode() const

Code sample:

std::shared_ptr<Material> material; // Filled variable
MaterialRenderingMode mode = material->GetRenderingMode();

GetOffset

Get the texture offset of the material.

const Vector2& GetOffset() const

Code sample:

std::shared_ptr<Material> material; // Filled variable
const Vector2& offset = material->GetOffset();

GetTiling

Get the texture tiling of the material.

const Vector2& GetTiling() const

Code sample:

std::shared_ptr<Material> material; // Filled variable
const Vector2& tiling = material->GetTiling();

GetColor

Get the color of the material.

const Color& GetColor() const

Code sample:

std::shared_ptr<Material> material; // Filled variable
const Color& color = material->GetColor();

SetColor

Set the color of the material.

Parameters:

  • color: Color of the material
void SetColor(const Color& color)

Code sample:

std::shared_ptr<Material> material; // Filled variable
material->SetColor(Color::CreateFromRGBAFloat(1, 0.5f, 0.5f, 1));

SetAlphaCutoff

Set the alpha cutoff of the material.

Parameters:

  • alphaCutoff: New alpha cutoff value [0.0f;1.0f]
void SetAlphaCutoff(float alphaCutoff)

Code sample:

std::shared_ptr<Material> material; // Filled variable
material->SetAlphaCutoff(0.5f);

GetAlphaCutoff

Get the alpha cutoff of the material.

float GetAlphaCutoff() const

Code sample:

std::shared_ptr<Material> material; // Filled variable
float alphaCutoff = material->GetAlphaCutoff();