Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
nirt::video::SMaterial Class Reference

Struct for holding parameters for a material renderer. More...

#include <nirtcpp/core/engine/SMaterial.hpp>

Collaboration diagram for nirt::video::SMaterial:
Collaboration graph

Public Member Functions

 SMaterial ()
 Default constructor. Creates a solid, lit material with white colors.
 
core::matrix4getTextureMatrix (u32 i)
 Gets the texture transformation matrix for level i.
 
const core::matrix4getTextureMatrix (u32 i) const
 Gets the immutable texture transformation matrix for level i.
 
void setTextureMatrix (u32 i, const core::matrix4 &mat)
 Sets the i-th texture transformation matrix.
 
ITexturegetTexture (u32 i) const
 Gets the i-th texture.
 
void setTexture (u32 i, ITexture *tex)
 Sets the i-th texture.
 
void setFlag (E_MATERIAL_FLAG flag, bool value)
 Sets the Material flag to the given value.
 
bool getFlag (E_MATERIAL_FLAG flag) const
 Gets the Material flag.
 
bool operator!= (const SMaterial &b) const
 Inequality operator.
 
bool operator== (const SMaterial &b) const
 Equality operator.
 
bool isAlphaBlendOperation () const
 Check if material needs alpha blending.
 
bool isTransparent () const
 

Public Attributes

SMaterialLayer TextureLayer [MATERIAL_MAX_TEXTURES]
 Texture layer array.
 
E_MATERIAL_TYPE MaterialType
 Type of the material. Specifies how everything is blended together.
 
SColor AmbientColor
 How much ambient light (a global light) is reflected by this material.
 
SColor DiffuseColor
 How much diffuse light coming from a light source is reflected by this material.
 
SColor EmissiveColor
 Light emitted by this material. Default is to emit no light.
 
SColor SpecularColor
 How much specular light (highlights from a light) is reflected.
 
f32 Shininess
 Value affecting the size of specular highlights.
 
f32 MaterialTypeParam
 Free parameter, dependent on the material type.
 
f32 MaterialTypeParam2
 Second free parameter, dependent on the material type.
 
f32 Thickness
 Thickness of non-3dimensional elements such as lines and points.
 
u8 ZBuffer
 Is the ZBuffer enabled? Default: ECFN_LESSEQUAL.
 
u8 AntiAliasing
 Sets the antialiasing mode.
 
u8 ColorMask:4
 Defines the enabled color planes.
 
u8 ColorMaterial:3
 Defines the interpretation of vertex color in the lighting equation.
 
E_BLEND_OPERATION BlendOperation:8
 Store the blend operation of choice.
 
f32 BlendFactor
 Store the blend factors.
 
f32 PolygonOffsetDepthBias
 A constant z-buffer offset for a polygon/line/point.
 
f32 PolygonOffsetSlopeScale
 Variable Z-Buffer offset based on the slope of the polygon.
 
u8 PolygonOffsetFactor:3
 DEPRECATED. Will be removed after Nirtcpp 1.9. Please use PolygonOffsetDepthBias instead.
 
E_POLYGON_OFFSET PolygonOffsetDirection:2
 DEPRECATED. Will be removed after Nirtcpp 1.9.
 
bool Wireframe:1
 Draw as wireframe or filled triangles? Default: false.
 
bool PointCloud:1
 Draw as point cloud or filled triangles? Default: false.
 
bool GouraudShading:1
 Flat or Gouraud shading? Default: true.
 
bool Lighting:1
 Will this material be lighted? Default: true.
 
E_ZWRITE ZWriteEnable:3
 Is the zbuffer writable or is it read-only. Default: EZW_AUTO.
 
bool BackfaceCulling:1
 Is backface culling enabled? Default: true.
 
bool FrontfaceCulling:1
 Is frontface culling enabled? Default: false.
 
bool FogEnable:1
 Is fog enabled? Default: false.
 
bool NormalizeNormals:1
 Should normals be normalized?
 
bool UseMipMaps:1
 Shall mipmaps be used if available.
 

Detailed Description

Struct for holding parameters for a material renderer.

Member Function Documentation

◆ getFlag()

bool nirt::video::SMaterial::getFlag ( E_MATERIAL_FLAG  flag) const
inline

Gets the Material flag.

Parameters
flagThe flag to query.
Returns
The current value of the flag.

◆ getTexture()

ITexture * nirt::video::SMaterial::getTexture ( u32  i) const
inline

Gets the i-th texture.

Parameters
iThe desired level.
Returns
Texture for texture level i, if defined, else 0.

◆ getTextureMatrix() [1/2]

core::matrix4 & nirt::video::SMaterial::getTextureMatrix ( u32  i)
inline

Gets the texture transformation matrix for level i.

Parameters
iThe desired level. Must not be larger than MATERIAL_MAX_TEXTURES
Returns
Texture matrix for texture level i.

◆ getTextureMatrix() [2/2]

const core::matrix4 & nirt::video::SMaterial::getTextureMatrix ( u32  i) const
inline

Gets the immutable texture transformation matrix for level i.

Parameters
iThe desired level.
Returns
Texture matrix for texture level i, or identity matrix for levels larger than MATERIAL_MAX_TEXTURES.

◆ isTransparent()

bool nirt::video::SMaterial::isTransparent ( ) const
inline

Check for some fixed-function transparent types. Still used internally, but might be deprecated soon. You probably should not use this anymore, IVideoDriver::needsTransparentRenderPass is more useful in most situations as it asks the material renders directly what they do with the material.

◆ operator!=()

bool nirt::video::SMaterial::operator!= ( const SMaterial b) const
inline

Inequality operator.

Parameters
bMaterial to compare to.
Returns
True if the materials differ, else false.

◆ operator==()

bool nirt::video::SMaterial::operator== ( const SMaterial b) const
inline

Equality operator.

Parameters
bMaterial to compare to.
Returns
True if the materials are equal, else false.

◆ setFlag()

void nirt::video::SMaterial::setFlag ( E_MATERIAL_FLAG  flag,
bool  value 
)
inline

Sets the Material flag to the given value.

Parameters
flagThe flag to be set.
valueThe new value for the flag.

◆ setTexture()

void nirt::video::SMaterial::setTexture ( u32  i,
ITexture tex 
)
inline

Sets the i-th texture.

If i>=MATERIAL_MAX_TEXTURES this setting will be ignored.

Parameters
iThe desired level.
texTexture for texture level i.

◆ setTextureMatrix()

void nirt::video::SMaterial::setTextureMatrix ( u32  i,
const core::matrix4 mat 
)
inline

Sets the i-th texture transformation matrix.

Parameters
iThe desired level.
matTexture matrix for texture level i.

Member Data Documentation

◆ AmbientColor

SColor nirt::video::SMaterial::AmbientColor

How much ambient light (a global light) is reflected by this material.

The default is full white, meaning objects are completely globally illuminated. Reduce this if you want to see diffuse or specular light effects.

◆ AntiAliasing

u8 nirt::video::SMaterial::AntiAliasing

Sets the antialiasing mode.

Values are chosen from E_ANTI_ALIASING_MODE. Default is EAAM_SIMPLE, i.e. simple multi-sample anti-aliasing.

◆ BlendFactor

f32 nirt::video::SMaterial::BlendFactor

Store the blend factors.

textureBlendFunc/textureBlendFuncSeparate functions should be used to write properly blending factors to this parameter. Due to historical reasons this parameter is not used for material type EMT_ONETEXTURE_BLEND which uses MaterialTypeParam instead for the blend factor. It's generally used only for materials without any blending otherwise (like EMT_SOLID). It's main use is to allow having shader materials which can enable/disable blending after they have been created. When you set this you usually also have to set BlendOperation to a value != EBO_NONE (setting it to EBO_ADD is probably the most common one value).

◆ BlendOperation

E_BLEND_OPERATION nirt::video::SMaterial::BlendOperation

Store the blend operation of choice.

Values to be chosen from E_BLEND_OPERATION.

◆ ColorMask

u8 nirt::video::SMaterial::ColorMask

Defines the enabled color planes.

Values are defined as or'ed values of the E_COLOR_PLANE enum. Only enabled color planes will be rendered to the current render target. Typical use is to disable all colors when rendering only to depth or stencil buffer, or using Red and Green for Stereo rendering.

◆ ColorMaterial

u8 nirt::video::SMaterial::ColorMaterial

Defines the interpretation of vertex color in the lighting equation.

Values should be chosen from E_COLOR_MATERIAL. When lighting is enabled, vertex color can be used instead of the material values for light modulation. This allows to easily change e.g. the diffuse light behavior of each face. The default, ECM_DIFFUSE, will result in a very similar rendering as with lighting turned off, just with light shading.

◆ DiffuseColor

SColor nirt::video::SMaterial::DiffuseColor

How much diffuse light coming from a light source is reflected by this material.

The default is full white.

◆ MaterialTypeParam

f32 nirt::video::SMaterial::MaterialTypeParam

Free parameter, dependent on the material type.

Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID, EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND.

◆ MaterialTypeParam2

f32 nirt::video::SMaterial::MaterialTypeParam2

Second free parameter, dependent on the material type.

Mostly ignored.

◆ NormalizeNormals

bool nirt::video::SMaterial::NormalizeNormals

Should normals be normalized?

Always use this if the mesh lit and scaled. Default: false

◆ PolygonOffsetDepthBias

f32 nirt::video::SMaterial::PolygonOffsetDepthBias

A constant z-buffer offset for a polygon/line/point.

The range of the value is driver specific. On OpenGL you get units which are multiplied by the smallest value that is guaranteed to produce a resolvable offset. On D3D9 you can pass a range between -1 and 1. But you should likely divide it by the range of the depthbuffer. Like dividing by 65535.0 for a 16 bit depthbuffer. Thought it still might produce too large of a bias. Some article (https://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/) recommends multiplying by 2.0*4.8e-7 (and strangely on both 16 bit and 24 bit).

◆ PolygonOffsetDirection

E_POLYGON_OFFSET nirt::video::SMaterial::PolygonOffsetDirection

DEPRECATED. Will be removed after Nirtcpp 1.9.

Flag defining the direction the polygon offset is applied to. Can be to front or to back, specified by values from E_POLYGON_OFFSET.

◆ PolygonOffsetFactor

u8 nirt::video::SMaterial::PolygonOffsetFactor

DEPRECATED. Will be removed after Nirtcpp 1.9. Please use PolygonOffsetDepthBias instead.

Factor specifying how far the polygon offset should be made. Specifying 0 disables the polygon offset. The direction is specified separately. The factor can be from 0 to 7. Note: This probably never worked on Direct3D9 (was coded for D3D8 which had different value ranges)

◆ PolygonOffsetSlopeScale

f32 nirt::video::SMaterial::PolygonOffsetSlopeScale

Variable Z-Buffer offset based on the slope of the polygon.

For polygons looking flat at a camera you could use 0 (for example in a 2D game) But in most cases you will have polygons rendered at a certain slope. The driver will calculate the slope for you and this value allows to scale that slope. The complete polygon offset is: PolygonOffsetSlopeScale*slope + PolygonOffsetDepthBias A good default here is to use 1.f if you want to push the polygons away from the camera and -1.f to pull them towards the camera.

◆ Shininess

f32 nirt::video::SMaterial::Shininess

Value affecting the size of specular highlights.

A value of 20 is common. If set to 0, no specular highlights are being used. To activate, simply set the shininess of a material to a value in the range [0.5;128]:

sceneNode->getMaterial(0).Shininess = 20.0f;

You can change the color of the highlights using

sceneNode->getMaterial(0).SpecularColor.set(255,255,255,255);

The specular color of the dynamic lights (SLight::SpecularColor) will influence the the highlight color too, but they are set to a useful value by default when creating the light scene node. Here is a simple example on how to use specular highlights:

// load and display mesh
scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("data/faerie.md2"));
node->setMaterialTexture(0, driver->getTexture("data/Faerie2.pcx")); // set diffuse texture
node->setMaterialFlag(video::EMF_LIGHTING, true); // enable dynamic lighting
node->getMaterial(0).Shininess = 20.0f; // set size of specular highlights
// add white light
scene::ILightSceneNode* light = smgr->addLightSceneNode(0,
core::vector3df(5,5,5), video::SColorf(1.0f, 1.0f, 1.0f));
Scene node capable of displaying an animated mesh.
Definition IAnimatedMeshSceneNode.hpp:52
Scene node which is a dynamic light.
Definition ILightSceneNode.hpp:23
void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
Sets all material flags at once to a new value.
Definition ISceneNode.hpp:442
virtual video::SMaterial & getMaterial(u32 num)
Returns the material based on the zero based index i.
Definition ISceneNode.hpp:423
void setMaterialTexture(u32 textureLayer, video::ITexture *texture)
Sets the texture of the specified layer in all materials of this scene node to the new texture.
Definition ISceneNode.hpp:453
Class representing a color with four floats.
Definition SColor.hpp:574
f32 Shininess
Value affecting the size of specular highlights.
Definition SMaterial.hpp:374
@ EMF_LIGHTING
Will this material be lighted? Default: true.
Definition EMaterialFlags.hpp:26

◆ SpecularColor

SColor nirt::video::SMaterial::SpecularColor

How much specular light (highlights from a light) is reflected.

The default is to reflect white specular light. See SMaterial::Shininess on how to enable specular lights.

◆ UseMipMaps

bool nirt::video::SMaterial::UseMipMaps

Shall mipmaps be used if available.

Sometimes, disabling mipmap usage can be useful. Default: true

◆ Wireframe

bool nirt::video::SMaterial::Wireframe

Draw as wireframe or filled triangles? Default: false.

The user can access a material flag using

material.Wireframe=true

or

material.setFlag(EMF_WIREFRAME, true);
@ EMF_WIREFRAME
Draw as wireframe or filled triangles? Default: false.
Definition EMaterialFlags.hpp:17

◆ ZBuffer

u8 nirt::video::SMaterial::ZBuffer

Is the ZBuffer enabled? Default: ECFN_LESSEQUAL.

If you want to disable depth test for this material just set this parameter to ECFN_DISABLED. Values are from E_COMPARISON_FUNC.

◆ ZWriteEnable

E_ZWRITE nirt::video::SMaterial::ZWriteEnable

Is the zbuffer writable or is it read-only. Default: EZW_AUTO.

If this parameter is not EZW_OFF, you probably also want to set ZBuffer to values other than ECFN_DISABLED


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

Nirtcpp    @cppfx.xyz

Utxcpp    utx::print