Autodesk Mudbox 2013 SDK Documentation > Materials, Textures, and Images >

# Sampling Texture Values

The following are the steps involved in accessing 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 combination 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 corresponding Material instance by calling the Material::TextureCount() and Material::Texture() functions. You can get the name of a texture by calling its implementation Node::Name() function. This list can change 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 a Node. Then cast to LayerContainer using dynamic_cast.

       LayerContainer* TexturePoolToLayerContainer(TexturePool* tp) {  Node* n = tp;  return dynamic_cast<LayerContainer*>(n);}

4. Once you have a pointer to a LayerContainer instance, you can check the list of layers and their names.
5. Based on your interpolated texture coordinate, you have to select the proper tile in the TexturePool by calling the 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 texture pixel (texel) at 0.3, 0.4 within that tile.
6. 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 preferable to copy the textures only once, and cache it.