A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | 0-9
Material - A material determines how the surface of a mesh will appear after being rendered. You can e.g. assign texture, set colours, enable lighting or shadow-receiving as well as assigning shader.
Transparency
If you have problems with transparency, look for some important material options.
- Use the correct value for alpha (0.0 is completely transparent and 1.0 is fully opaque)
- Set scene blend to alpha blend
- Disable depth write
Depth write can be turned off when rendering static backgrounds or when rendering a collection of transparent objects at the end of a scene so that they overlap each other correctly.
Apply in material script:
material TransparencyExample { technique { pass { //... scene_blend alpha_blend depth_write off } } }
Apply by code:
myMaterialPtr->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); myMaterialPtr->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
Apply by code (C# example for Mogre):
myMaterialPtr.GetTechnique(0).GetPass(0).SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA); myMaterialPtr.GetTechnique(0).GetPass(0).DepthWriteEnabled = false;
Both-side visibility
By default a material is only visible from one side.
This is usable for volumetric bodies. (e.g. an (unripped) monster you don't need to see from inside).
For flat surfaces (e.g. a water surface or billboards) often there is a whish to have a both-side visibility.
Enable both-side visibility by a *.material file:
(For details look to this section of the Ogre manual.)
material TransparencyExample { technique { pass { //... cull_hardware none cull_software none } } }
To enable both-side visibility by code call the material related method Pass::setCullingMode().
Example:
myMaterialPtr::getTechnique(0)::getPass(0)::setCullingMode(CullingMode::CULL_NONE);
Apply to Mesh
Apply a material to a (sub)mesh by code:
entity::getSubEntity(0)::setMaterialName("myMaterialName");
Dynamic usage
It's possible to update a ManualObject to change it's shape or properties. For this you need to set the dynamic flag:
ManualObject::setDynamic(true);
Then you can update its content:
manObj->beginUpdate(); ... // Recreate object ... manObj->end();
When you are going to be changing the number of vertices, you additionally should call this:
ManualObject::estimateVertexCount(); ManualObject::estimateIndexCount()
Alternatively you can use the low level class DynamicRenderable. A usage example is on page DynamicGrowingBuffers.
See also
- Ogre::Material Class Reference
- Texture
- Collection of Ogre material templates
- Displaying 2D Backgrounds
- Line 3D / MOGRE Line 3D - includes some code how to create a material by code
- Projective Decals - dynamic texture projection on top of a terrain texture
- Reloading materials and parsing material scripts
- MadMarx Tutorial 7 - Basic Material (part 1)
- MadMarx Tutorial 8 - Basic Material (part 2), about transparency, decals, environment map, mix percentage
- Yaose - Editor for material script files, including syntax highlighting and code suggestion
Ogre Manual:
- Materials
- Material Scripts
- Techniques
- Passes - Definition of colours, transparency, blending types, etc.
- Texture Units
- Script Inheritance
- Script Variables