This reference page is linked to from the following overview topics: Scene Graph, Rendering, Shading, Materials, Writing Material Plug-ins, Sampling Texture Values.
Describes a material of a geometry including its surface colors, transparency and texture information.
The material class is responsible for the appearance of a surface when its rendered. Each mesh in Mudbox has an associated material, and multiple meshes can use the same material instance.
When Mudbox renders the mesh, it first uses the associated material to prepare the opengl pipeline for the mesh by calling the Material::Activate() function. The material class is also used to determine the list of paintable textures over the surface. The functions Material::TextureCount() and Material::Texture() are used for this purpose. For more details, see the TexturePool class.
You can derive from the Material class to create your own custom materials with texture channels that control any parameters you wish. See the SDK examples.
How to access a specific texture value at a point on the surface:
1. Calculate the texture coordinate associated for the surface point. This can be done by calculating a linear conbination of the texture coordinates at the corners of the face based on the information you have about where the point is inside the face.
2. Decide which texture are you interested in, by examining the list of textures in the corrseponding material instance by calling the TextureCount() and Texture() functions. You can get the name of a texture by calling the Texture::Name() function. This list is dynamic is because it can changed depending on the material implementation. The default Mudbox material has a fixed list, but materials created from custom cgfx files can have very different texture lists.
3. Since Mudbox supports layers for each texture, you next need to choose the layer you are interested in. To do this, cast the pointer obtained in step 2 to LayerContainer. Once you have a pointer to a layercontainer instance, you can check the list of layers and their names. Finally you have to cast the layer to a TexturePool again.
4. Based on your interpolated texture coordinate, you have to select the proper tile in the TexturePool by calling TexturePool::Tile() function. (If the UV space of an object goes beyond the range 0-1, Mudbox uses multiple tiles to represent each layer of a texture.) Pass in a bounding box representing the tile you are interested in. For example, if the desired texture coordinate is 1.3, 3.4, then you would pass in a bounding box between ( 1, 3, 0 ) and ( 2, 4, 0 ). (In texture space, the third coordinate is always 0.) Once you get the tile, you would sample the texel at 0.3, 0.4 within that tile. (See next step)
5. Once you got the texture, copy it to an Image object by calling the Texture::CopyTo() function. You can easily access the color of the needed pixel by calling the Image::ColorAt() function. Note that copying a texture to an image is a slow process, so if you want to sample multiple surface points, it is smart to copy the textures only once, and cache it.
Definition at line 73 of file material.h.
#include <material.h>
Public Member Functions |
|
~Material () | |
virtual bool | Activate (const Mesh *pMesh, const AxisAlignedBoundingBox &cUVArea, const Color &cColor=Color::white) |
Prepares the GPU to draw with this material.
|
|
virtual void | Deactivate (void) |
Sets the GPU back to its default state.
|
|
virtual float | Transparency (void) const |
Returns the overall transparency of the
surface. |
|
virtual void | SetTransparency (float fTransparency) |
Sets the transparency of the surface.
|
|
virtual bool | TexturesVisible (void) const |
Returns true if textures should be
visible on the rendered surface. |
|
virtual void | SetTexturesVisible (bool bVisible) |
Sets if the textures should be visible on
the surface. |
|
virtual bool | IsTCNeeded (void) const |
Returns true if the material implementation
needs texture coordinates from the mesh. |
|
virtual bool | IsTNBNeeded (void) const |
Returns true if the material implementation
needs tangent and binormal data from the mesh. |
|
virtual unsigned int | TextureCount (void) const |
Returns the number of textures associated
with the material. |
|
virtual class TexturePool * | Texture (unsigned int iTextureIndex) const |
Returns a pointer to the specified texture.
Do not delete this pointer. |
|
virtual void | SetTextureTileLive (const AxisAlignedBoundingBox &cUVArea, bool bLive, int iLODDelta=0) |
Loads or unloads the specified uv tile for
all textures in this material. |
|
virtual bool | IsTextureTileLive (const AxisAlignedBoundingBox &cUVArea) |
Returns if the specified uv tile is loaded
into memory. |
|
virtual unsigned int | TextureTileCount () const |
Returns the number of texture tiles
associated with this material. |
|
virtual AxisAlignedBoundingBox | TextureTileArea (unsigned int iTileIndex) const |
Returns the uv area covered by the given
tile. |
|
virtual void | ActivateUVArea (const AxisAlignedBoundingBox &cArea) |
Prepares the GPU to draw a specific uv area.
|
|
virtual VertexDataUsage | MapVertexData (VertexDataUsage eUsage) const |
This function is called to determine the
mapping of vertex shader inputs for the material. |
|
Protected Member Functions |
|
Material (void) | |
Constructor. |
Material | ( | void | ) | [protected] |
Constructor.
Do not use it directly; Use CreateInstance() instead.
Material *myMaterial = CreateInstance<Material>();
~Material | ( | ) |
virtual bool Activate | ( | const Mesh * | pMesh, |
const AxisAlignedBoundingBox & | cUVArea, | ||
const Color & | cColor = Color::white |
||
) | [virtual] |
Prepares the GPU to draw with this material.
This method is called by Mudbox when the material is about to used for a mesh. It should return true if additional rendering steps are needed. The cColor parameter is only as suggestion, its up to the material class how it uses (or ignores) it.
[in] | pMesh | The mesh to be rendered |
[in] | cUVArea | The UV tile of the mesh to be rendered (each tile is drawn separately) |
[in] | cColor | The suggested color for the tile |
virtual void Deactivate | ( | void | ) | [virtual] |
Sets the GPU back to its default state.
virtual float Transparency | ( | void | ) | const [virtual] |
Returns the overall transparency of the surface.
Range 0..1. Not currently used.
It is up to the material implementation how it handles this overall transparency value. It can ignore it, but then the user wont be able to control the transparency of their objects in the scene. 0 means totally transparent while 1 means opaque. This is currently not used in mudbox (transparency is always 1) but it might be used in future versions.
virtual void SetTransparency | ( | float | fTransparency | ) | [virtual] |
Sets the transparency of the surface.
Range 0..1. Called by Mudbox when the user changes the transparency for an object. Not currently used.
[in] | fTransparency | Ranges from 0 (transparent) to 1 (opaque) |
virtual bool TexturesVisible | ( | void | ) | const [virtual] |
Returns true if textures should be visible on the rendered surface.
It is up to the material implementation how it handles this parameter. It is provided in case a user wants to turn off texturing in the scene. In that case SetTexturesVisible() is called with false as the parameter.
If textures are set to invisible, then the material implementation should use a fixed value for the different channels that were using textures.
virtual void SetTexturesVisible | ( | bool | bVisible | ) | [virtual] |
Sets if the textures should be visible on the surface.
[in] | bVisible | To make textures visible, set this to true. |
virtual bool IsTCNeeded | ( | void | ) | const [virtual] |
Returns true if the material implementation needs texture coordinates from the mesh.
If you are deriving a new material class, you need to have this method return true if your material needs texture coordinate information to draw itself properly.
virtual bool IsTNBNeeded | ( | void | ) | const [virtual] |
Returns true if the material implementation needs tangent and binormal data from the mesh.
If you are deriving a new material class, you need to have this method return true if your material needs tangent and binormal data to draw itself properly.
virtual unsigned int TextureCount | ( | void | ) | const [virtual] |
Returns the number of textures associated with the material.
virtual class TexturePool* Texture | ( | unsigned int | iTextureIndex | ) | const [virtual] |
Returns a pointer to the specified texture. Do not delete this pointer.
[in] | iTextureIndex | Index of the texture to be returned |
virtual void SetTextureTileLive | ( | const AxisAlignedBoundingBox & | cUVArea, |
bool | bLive, | ||
int | iLODDelta =
0 |
||
) | [virtual] |
Loads or unloads the specified uv tile for all textures in this material.
To reduce memory footprint, users may opt to unload some tiles of the texture maps they are working with. This method is called by Mudbox to unload (remove from memory) or load (bring in from disk) those specific tiles. When a texture tile is unloaded, the material should use an arbitrary constant value for the channel it represents.
You probably don't need to override this method in your own materials.
[in] | cUVArea | The UV bounds of the tile you want |
[in] | bLive | Specify true to load the tile, false to unload it. |
[in] | iLODDelta | the delta of the LOD with which the tile proxy to be loaded |
virtual bool IsTextureTileLive | ( | const AxisAlignedBoundingBox & | cUVArea | ) | [virtual] |
Returns if the specified uv tile is loaded into memory.
[in] | cUVArea | The UV bounds of the tile you are interested in |
virtual unsigned int TextureTileCount | ( | ) | const [virtual] |
Returns the number of texture tiles associated with this material.
virtual AxisAlignedBoundingBox TextureTileArea | ( | unsigned int | iTileIndex | ) | const [virtual] |
Returns the uv area covered by the given tile.
[in] | iTileIndex | The index of the tile of interest. |
virtual void ActivateUVArea | ( | const AxisAlignedBoundingBox & | cArea | ) | [virtual] |
Prepares the GPU to draw a specific uv area.
This method is called by Mudbox when the uv region specified by cArea is about to be rendered. For example, for a mesh with 3 tiles Activate will be called for the first tile, and ActivateUVArea will be called for each subsequent area.
virtual VertexDataUsage MapVertexData | ( | VertexDataUsage | eUsage | ) | const [virtual] |
This function is called to determine the mapping of vertex shader inputs for the material.
The return value must be a direct value. The value eNotUsed should be returned if the data is not used by the shader.
[in] | eUsage | The usage to be mapped. This is always a generic value. See VertexDataUsage. |