Skip to content

Material

Abstract base class for material types.

This class is not intended to be used directly. Use one of the concrete material types such as PhongMaterial, UnlitMaterial, ShaderMaterial, or derive your own material implementation from this class.

Types

Material::Blending enum

Enumerates blending modes used for compositing this material.

ValueDescription
NoneNo blending (default) fragments overwrite existing pixels.
NormalStandard alpha blending.
AdditiveAdds fragment color to the framebuffer color.
SubtractiveSubtracts fragment color from the framebuffer color.
MultiplyMultiplies fragment color by the framebuffer color.

Material::Depth enum

Enumerates depth comparison functions used for depth testing.

ValueDescription
LessPasses if the fragment depth is less than the stored depth.
EqualPasses if the fragment depth is equal to the stored depth.
LessEqualPasses if the fragment depth is less than or equal to the stored depth.
GreaterPasses if the fragment depth is greater than the stored depth.
GreaterEqualPasses if the fragment depth is greater than or equal to the stored depth.
AlwaysAlways passes regardless of depth value.
NeverNever passes regardless of depth value.

Material::Side enum

Enumerates which side of each polygon is rendered.

ValueDescription
FrontRenders front faces only (default).
BackRenders back faces only.
TwoSidedRenders both front and back faces.

Material::Type enum

Enumerates all supported material types.

ValueDescription
DepthMaterialRenders depth only; used internally for shadow map passes.
PBRMaterialImplements physically-based rendering with the metallic workflow.
PhongMaterialImplements the Blinn–Phong lighting model.
ShaderMaterialUses a custom shader program for rendering.
SpriteMaterialSpecialized material for 2D sprites and billboards.
UnlitMaterialRenders without lighting; color appears as-is.
LengthSentinel value representing the number of material types.

Properties

alpha_test float

Alpha threshold below which fragments are discarded.

Fragments whose final alpha (opacity combined with texture alpha) falls below this value are not rendered. Use for cutout surfaces such as foliage. Unlike transparent, discarded fragments write no depth and require no sorting. A value of 0 disables the test.

cpp
float alpha_test {0.0f};

blending Blending

Blending mode used when rendering this material.

cpp
Blending blending {Blending::Normal};

depth Depth

Depth function used for depth testing.

cpp
Depth depth {Depth::LessEqual};

depth_test bool

Enables depth testing.

cpp
bool depth_test {true};

flat_shaded bool

Enables flat shading.

cpp
bool flat_shaded {false};

fog bool

Enables scene fog for this material.

cpp
bool fog {true};

opacity float

Value in the range indicating how transparent the material is.

Blends the material with the framebuffer when transparency is enabled, and contributes to the alpha value tested against alpha_test. Has no effect when both are disabled.

cpp
float opacity {1.0f};

polygon_offset_factor float

Polygon offset factor used to mitigate z-fighting.

cpp
float polygon_offset_factor {0.0f};

polygon_offset_units float

Polygon offset units used to mitigate z-fighting.

cpp
float polygon_offset_units {0.0f};

side Side

Side of each polygon rendered by this material.

cpp
Side side {Side::Front};

transparent bool

Enables transparency for this material.

cpp
bool transparent {false};

visible bool

Controls whether this material is visible when rendering.

cpp
bool visible {true};

wireframe bool

Enables wireframe rendering.

cpp
bool wireframe {false};

Functions

GetType() Type pure virtual

Identifies the concrete Material::Type of this material.

cpp
virtual Type Material::GetType() const=0;

Material::TypeToString() std::string

Converts a material type value to a string.

Primarily intended for debugging and logging.

cpp
static std::string Material::TypeToString(Type type);
ParameterDescription
typeMaterial type enum value.

Released under the MIT License.