Kemena3D
Loading...
Searching...
No Matches
kemena::kMaterial Class Reference

Groups a shader program with textures and surface parameters. More...

#include <kmaterial.h>

Public Member Functions

 kMaterial ()
 Constructs a material with default surface parameters and no shader.
virtual ~kMaterial ()
 Destroys the material.
void setShader (kShader *newShader)
 Assigns a compiled shader to this material.
kShadergetShader ()
 Returns the assigned shader.
void addTexture (kTexture *texture)
 Appends a texture to the material's texture list.
std::vector< kTexture * > getTextures ()
 Returns all textures attached to this material.
kTexturegetTexture (int index)
 Returns a texture by index.
void setTransparent (kTransparentType type)
 Sets the transparency blending mode.
kTransparentType getTransparent ()
 Returns the transparency blending mode.
void setUvTiling (kVec2 newTiling)
 Sets the UV tiling factor applied to all texture coordinates.
kVec2 getUvTiling ()
 Returns the UV tiling factor.
void setAmbientColor (kVec3 color)
 Sets the ambient colour.
void setDiffuseColor (kVec3 color)
 Sets the diffuse colour.
void setSpecularColor (kVec3 color)
 Sets the specular colour.
void setShininess (float value)
 Sets the Phong shininess exponent.
void setMetallic (float value)
 Sets the PBR metallic factor.
void setRoughness (float value)
 Sets the PBR roughness factor.
kVec3 getAmbientColor ()
 Returns the ambient colour.
kVec3 getDiffuseColor ()
 Returns the diffuse colour.
kVec3 getSpecularColor ()
 Returns the specular colour.
float getShininess ()
 Returns the Phong shininess exponent.
float getMetallic ()
 Returns the PBR metallic factor.
float getRoughness ()
 Returns the PBR roughness factor.
void setSingleSided (bool newSingleSided, bool newCullBack=true)
 Configures face culling for this material.
bool getSingleSided ()
 Returns whether face culling is enabled.
bool getCullBack ()
 Returns which face is culled when single-sided rendering is on.

Detailed Description

Groups a shader program with textures and surface parameters.

A material is assigned to a kObject (and optionally its children) via kObject::setMaterial(). The renderer queries the material for the shader to bind, the texture list to upload, and the surface colour/PBR values to pass as uniforms.

Constructor & Destructor Documentation

◆ kMaterial()

kemena::kMaterial::kMaterial ( )

Constructs a material with default surface parameters and no shader.

◆ ~kMaterial()

virtual kemena::kMaterial::~kMaterial ( )
virtual

Destroys the material.

Does not free the shader or textures; ownership of those resources remains with the caller.

Member Function Documentation

◆ addTexture()

void kemena::kMaterial::addTexture ( kTexture * texture)

Appends a texture to the material's texture list.

Parameters
textureTexture to add; ownership is not transferred.

◆ getAmbientColor()

kVec3 kemena::kMaterial::getAmbientColor ( )

Returns the ambient colour.

Returns
RGB ambient colour.

◆ getCullBack()

bool kemena::kMaterial::getCullBack ( )

Returns which face is culled when single-sided rendering is on.

Returns
true if back faces are culled; false if front faces are culled.

◆ getDiffuseColor()

kVec3 kemena::kMaterial::getDiffuseColor ( )

Returns the diffuse colour.

Returns
RGB diffuse colour.

◆ getMetallic()

float kemena::kMaterial::getMetallic ( )

Returns the PBR metallic factor.

Returns
Metallic value.

◆ getRoughness()

float kemena::kMaterial::getRoughness ( )

Returns the PBR roughness factor.

Returns
Roughness value.

◆ getShader()

kShader * kemena::kMaterial::getShader ( )

Returns the assigned shader.

Returns
Pointer to the shader, or nullptr if none is set.

◆ getShininess()

float kemena::kMaterial::getShininess ( )

Returns the Phong shininess exponent.

Returns
Shininess value.

◆ getSingleSided()

bool kemena::kMaterial::getSingleSided ( )

Returns whether face culling is enabled.

Returns
true if single-sided rendering is active.

◆ getSpecularColor()

kVec3 kemena::kMaterial::getSpecularColor ( )

Returns the specular colour.

Returns
RGB specular colour.

◆ getTexture()

kTexture * kemena::kMaterial::getTexture ( int index)

Returns a texture by index.

Parameters
indexZero-based index into the texture list.
Returns
Pointer to the texture, or nullptr if index is out of range.

◆ getTextures()

std::vector< kTexture * > kemena::kMaterial::getTextures ( )

Returns all textures attached to this material.

Returns
Copy of the internal texture vector.

◆ getTransparent()

kTransparentType kemena::kMaterial::getTransparent ( )

Returns the transparency blending mode.

Returns
Current transparency type.

◆ getUvTiling()

kVec2 kemena::kMaterial::getUvTiling ( )

Returns the UV tiling factor.

Returns
UV tiling (U, V).

◆ setAmbientColor()

void kemena::kMaterial::setAmbientColor ( kVec3 color)

Sets the ambient colour.

Parameters
colorRGB ambient colour (0..1 per channel).

◆ setDiffuseColor()

void kemena::kMaterial::setDiffuseColor ( kVec3 color)

Sets the diffuse colour.

Parameters
colorRGB diffuse colour.

◆ setMetallic()

void kemena::kMaterial::setMetallic ( float value)

Sets the PBR metallic factor.

Parameters
valueMetallic value in the range [0, 1].

◆ setRoughness()

void kemena::kMaterial::setRoughness ( float value)

Sets the PBR roughness factor.

Parameters
valueRoughness value in the range [0, 1].

◆ setShader()

void kemena::kMaterial::setShader ( kShader * newShader)

Assigns a compiled shader to this material.

Parameters
newShaderPointer to the shader program; must outlive the material.

◆ setShininess()

void kemena::kMaterial::setShininess ( float value)

Sets the Phong shininess exponent.

Parameters
valueShininess exponent (higher = tighter highlights).

◆ setSingleSided()

void kemena::kMaterial::setSingleSided ( bool newSingleSided,
bool newCullBack = true )

Configures face culling for this material.

Parameters
newSingleSidedtrue to enable face culling.
newCullBacktrue to cull back faces; false to cull front faces.

◆ setSpecularColor()

void kemena::kMaterial::setSpecularColor ( kVec3 color)

Sets the specular colour.

Parameters
colorRGB specular colour.

◆ setTransparent()

void kemena::kMaterial::setTransparent ( kTransparentType type)

Sets the transparency blending mode.

Parameters
typeTransparency type (none, alpha blend, etc.).

◆ setUvTiling()

void kemena::kMaterial::setUvTiling ( kVec2 newTiling)

Sets the UV tiling factor applied to all texture coordinates.

Parameters
newTilingTiling multiplier (U, V).

The documentation for this class was generated from the following file: