Cross-Platform Game Programming with gameplay3d/More about Materials

Materials, Techniques, Passes and Effects
As you may recall, a Model in gameplay3d is a specific instance of a Mesh, which consists of one or more MeshParts.

In order to render a  in gameplay3d, each of the   in that   must have an associated Material. Since each  can have a different , this allows different parts of the   to be rendered in a different way. For example, if you have a character that is wearing armor, you could apply a metallic material to that armor while applying simple texturing to the remaining parts of the.

A  contains one or more Technique(s). The idea behind having  is to permit the easy switching of render techniques at runtime, without setting an entirely new material on the. As an example, you may have a  to which you apply a bump mapping   when it is near the camera, but you switch to a simple texturing   when it is further away in order to improve performance.

Each  can have one or more Pass(es), each of which corresponds to a single OpenGL draw call. In order to use multipass rendering techniques, you would add more than one  to your.

contain:
 * an Effect, which basically represents an GLSL shader program (i.e. vertex and fragment shader);
 * various information regarding the render state (e.g. the blend function to be applied, whether depth test is enabled etc.);
 * a VertexAttributeBinding, which either encapsulates (or simulates, if you hardware doesn't support it) an OpenGL VAO (vertex attribute object), and sets out how the  data relates to the inputs in the GLSL shader program.

Phew! That may seem like a long list of things to remember, but you should find that this system provides a lot of flexibility for arranging your rendering behavior in a neat and orderly fashion.

Help! I can't see my model...
Here are some common reasons why you may not be able to see your model (or it shows up all in black):


 * You have not set all the required uniforms used by your shader. Have you remembered to call one of the following functions for every uniform used in your shader?:
 * ; or
 * ; or


 * The mesh used in your model does not contain all the attributes (i.e. per-vertex data) required by your shader. If your model was generated in a 3D modelling program, did the program export all necessary per-vertex data (e.g. tangents and binormal data for bump mapping) required by your shader? Note that the gameplay-encoder can generate tangent and binormal data for an FBX model that does not contain them by using the  option.


 * Your mesh data is corrupt. This may be a problem if you have created your mesh procedurally, or if there is a bug in the FBX exporter in your 3D modelling program.