19.6 Materials and Scripts


19.6 Materials and Scripts

A texture is an image that can be wallpapered onto a 3D model to enhance a game's realism. A material is the method by which textures are wallpapered onto objects in OGRE; for example, making a wall appear to be made of brick. A material contains a texture but also has other properties that affect its appearance. Materials can define how light reacts when it hits the surface of a model, and specifically materials can define how textures appear when in light, dark, shadows, etc. Furthermore, materials in OGRE have all kinds of extra properties to animate textures, transform their look, tile them across models, and so on. Although the subject of OGRE materials is too large to cover completely in a single chapter, we'll explain the fundamentals here.

In OGRE, materials are defined in a script file-a text file that defines material properties and is loaded by OGRE at run time. As it's loaded, the text file is processed and the materials are loaded according to the settings in the script. Most of the time, when models are exported from 3D packages such as 3ds Max or Blender 3D, the material data is also created; these details need not trouble the programmer. But often, as we shall see, it can be useful to define custom materials. Consider the following material defined in script form:

      material Examples/OgreLogo      {         technique         {            pass            {               ambient 0.8 0.8 0.8               texture_unit               {                  texture ogrelogo.png               }            }         }      } 

The script notation is a hierarchical system that uses braces ({}) to contain code. In short, this material is called Examples/OgreLogo, and it represents the image file ogrelogo.png. Naturally, readers will be curious to know how these textures are actually mapped to objects. In the case of OGRE, this is usually done automatically when the model is exported from the modeling software. Take a look at the OGRE website to see which model exporters are available for your 3D modeling software. The following list defines some of these basic tags found in the material script.

  • material

    This is the parent opening and closing tag to define a new material. A single script file can contain many different material definitions, and each one begins with the material keyword. The rest of the material definition is contained within braces. Each material keyword is followed by a unique material name.

  • technique

    A material can have many techniques, but each material should have at least one. Since graphics cards differ widely in their specifications and requirements, it's not always certain each material will appear the same on each device, and it's possible some cards support one subset of features while others support a different set. Therefore, multiple techniques can be defined and, in the event of one technique not being supported, another can be used. For any sample materials, and for simpler materials, one technique will usually be sufficient.

  • pass

    Each technique can have 1 to 16 passes, and most simple materials will use only one. Each pass represents one call to the rendering pipeline for each time the material is drawn to the display. By adding more passes it's possible to produce various kinds of effects. This subject is beyond the scope of this book, and the OGRE manual should be consulted for further details. This book covers materials that use one pass.

    Inside a pass, a material may have various properties. Specifically, a material can define color information such as ambient color (the color of the object when in light), specular color (the color of the shiny parts of an object), emissive color (the color of glow an object has), and so on. Specifically, the details a material can have set here are:

    ambientlighting
    diffuseshading
    specularpolygon_mode
    emissivefog_override
    scene_blendcolour_write
    depth_checkmax_lights
    depth_writeiteration
    depth_funcpoint_size
    depth_biaspoint_sprites
    alpha_rejectionxspoint_size_attenuation
    cull_hardwarepoint_size_min
    cull_softwarepoint_size_max

  • texture_unit

    Each pass can have a texture. This defines which image file, if any, is wallpapered onto the surface of any model assigned this material.




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net