History: -Material
Source of version: 22 (current)
Copy to clipboard
{INCLUDE(page="ogrelex ext tpl")/} --- __Material__ - A material determines how the surface of a ((-mesh|mesh)) will appear after being rendered. You can e.g. assign ((-texture|texture)), set colours, enable lighting or ((shadows|shadow))-receiving as well as assigning ((-shader|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: {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]