Skip to main content

History: -Material

Source of version: 21

Copy to clipboard
            {INCLUDE(page="ogrelex ext tpl")/}
---
__Material__ - A material determines how the surface of a {LEX()}mesh{LEX} will appear after being rendered. You can e.g. assign {LEX()}texture{LEX}s, set colours, enable lighting or {LEX()}shadow{LEX}-receiving as well as assigning {LEX()}shader{LEX}s.


!!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:
{CODE(wrap="1")}material TransparencyExample
{
    technique
    {
        pass
        {
            //...
            scene_blend alpha_blend
            depth_write off
        }
    }
}
{CODE}


Apply by code:
{CODE(wrap="1", colors="c++")}
myMaterialPtr->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
myMaterialPtr->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
{CODE}


Apply by code (C# example for ((Mogre))):
{CODE(wrap="1", colors="c#")}
myMaterialPtr.GetTechnique(0).GetPass(0).SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
myMaterialPtr.GetTechnique(0).GetPass(0).DepthWriteEnabled = false;
{CODE}

%%%
!!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 ((-billboard|billboards))) often there is a whish to have a both-side visibility.

Enable both-side visibility by a __*.material__ file:
(For details look to [http://www.ogre3d.org/docs/manual/manual_16.html#SEC39|this section] of the Ogre manual.)
{CODE(wrap="1")}
material TransparencyExample
{
    technique
    {
        pass
        {
            //...
            cull_hardware none
            cull_software none 
        }
    }
}
{CODE}

To enable both-side visibility __by code__ call the material related method [http://www.ogre3d.org/docs/api/html/classOgre_1_1Pass.html#a8942abf3ede0f3cb43584c85c4071734|Pass::setCullingMode()].
Example:
{CODE(wrap="1", colors="c++")}
myMaterialPtr::getTechnique(0)::getPass(0)::setCullingMode(CullingMode::CULL_NONE);
{CODE}


%%%
!!Apply to Mesh

Apply a material to a (sub)mesh by code:
{CODE(wrap="1", colors="c++")}entity::getSubEntity(0)::setMaterialName("myMaterialName");
{CODE}

%%%
!!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:
{CODE(wrap="1", colors="c++")}
ManualObject::setDynamic(true);
{CODE}
Then you can update its content:
{CODE(wrap="1", colors="c++")}
manObj->beginUpdate();
...
// Recreate object
...
manObj->end();
{CODE}
When you are going to be changing the number of vertices, you additionally should call this:
{CODE(wrap="1", colors="c++")}
ManualObject::estimateVertexCount();
ManualObject::estimateIndexCount()
{CODE}

Alternatively you can use the low level class ''DynamicRenderable''. A usage example is on page ((DynamicGrowingBuffers )).

%%%
!!See also

* [http://www.ogre3d.org/docs/api/html/classOgre_1_1Material.html|Ogre::Material] __Class Reference__
* ((-Texture|Texture))
* ((Materials|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:__
* [http://www.ogre3d.org/docs/manual/manual_11.html#SEC14|Materials]
* [http://www.ogre3d.org/docs/manual/manual_14.html#SEC23|Material Scripts]
** [http://www.ogre3d.org/docs/manual/manual_15.html#SEC33|Techniques]
** [http://www.ogre3d.org/docs/manual/manual_16.html#SEC39|Passes] - Definition of colours, transparency, blending types, etc.
** [http://www.ogre3d.org/docs/manual/manual_17.html#SEC77|Texture Units]
** [http://www.ogre3d.org/docs/manual/manual_25.html#SEC139|Script Inheritance]
** [http://www.ogre3d.org/docs/manual/manual_27.html#SEC144|Script Variables]

        

History

Information Version
Wed 17 of Jun, 2020 22:19 GMT-0000 sercero 22
Thu 17 of Jul, 2014 12:12 GMT-0000 petersvp Fixed a typo ;] 21
Fri 08 of Feb, 2013 13:10 GMT-0000 spacegaier removed duplicated "See Also" section 20
Sun 31 of Jul, 2011 22:14 GMT-0000 jacmoe 19
Sun 24 of Apr, 2011 12:49 GMT-0000 Beauty added code snippet how to apply material by code 18
Wed 23 of Feb, 2011 13:08 GMT-0000 Beauty added section about both-side visibility 17
Mon 21 of Feb, 2011 10:53 GMT-0000 Beauty tiny change 16
Mon 21 of Feb, 2011 10:51 GMT-0000 Beauty added note for alpha value and transparency 15
Fri 11 of Feb, 2011 13:06 GMT-0000 Beauty added section about transparency 14
Fri 11 of Feb, 2011 13:01 GMT-0000 Beauty added section about transparency 13
Thu 03 of Feb, 2011 15:59 GMT-0000 Beauty added 2 links 12
Wed 08 of Dec, 2010 05:26 GMT-0000 sarcacid cleaned up lexicon links 11
Tue 07 of Dec, 2010 19:30 GMT-0000 Beauty added links to Ogre manual 10
Tue 07 of Dec, 2010 16:13 GMT-0000 Beauty highlight 9
Thu 09 of Sep, 2010 11:50 GMT-0000 Beauty added link 8
Wed 18 of Aug, 2010 15:44 GMT-0000 Beauty added link 7
Wed 18 of Aug, 2010 15:41 GMT-0000 Beauty added link 6
Fri 08 of Jan, 2010 00:06 GMT-0000 jacmoe 5
Thu 07 of Jan, 2010 22:36 GMT-0000 jacmoe 4
Thu 07 of Jan, 2010 22:36 GMT-0000 jacmoe 3
Tue 29 of Dec, 2009 09:40 GMT-0000 jacmoe 2
Sat 28 of Nov, 2009 17:32 GMT-0000 Spacegaier linked to the API 1