# Material casters
The material casting is a post-process of all mapping image generating processing objects, where the caller application can use the mapping image data to "cast" material and texture data from the original onto the processed geometry.
The casting process requires that the processing object has created a mapping image during the main processing. When creating new maps using material casting, opacity values can be baked down into either diffuse map's alpha value or baked down into a separate opacity map.
# MaterialCaster
All casting objects are derived from the MaterialCaster class, which implements the basic processing parameters of all casting objects. MaterialCaster contains settings for the output image format.
When using a caster designed to transfer materials from the original to the output mesh, a reference to the original material table must be set. If the input materials in the material table are defined using shading networks rather than the legacy material system, a texture table containing all textures referenced by the texture nodes in the shading networks must also be created and supplied.
# Source material casters
These casters bake material channels from the input scene to the processed scene, and hence require references to the input materials and textures.
Color caster
General color casting (diffuse/basecolor/roughness etc.). If using the remesher, the color values will be accumulated through mapping image layers using the defined opacity channel.Normal caster
Specialized normal map casting. If there is a normal map setup in the source materials, these will be decoded and baked into the new tangentspace (or objectspace) of the result scene. If no source normal map is set, the geometry normals from the original scene is still baked down to the LOD. Simplygon requires full RGB(TBN) tangent space normal maps, so if you have compressed maps with only two channels, you'll have to calculate the missing channel before setting up the source textures.Opacity caster
Casts the opacity channel, which for the remesher will be an accumulated opacity through all mapping image layers.Vertex color caster
This caster is a bit different in that it does not actually generate an output imagedata, instead it bakes the input material channels to vertex colors in the output scene.
# Other material casters
These casters do not require any references to the input materials and textures since they generate new data based on the input and output geometries.
Ambient occlusion caster
This caster will compute ambient occlusion for the scene based on the original geometry and create an ambient occlusion texture.Geometry data caster
This caster can cast arbitrary geometry fields like the original texcoords to imagedata, allowing things like indirect texturing or manual runtime material casting.Displacement caster
Generates an output texture with vector data contatining the displacement between the points on the original scene and the corresponding points on the LOD.
# Usage examples
# AmbientOcclusionCaster
The AmbientOcclusionCaster is used to generate an ambient occlusion map. The occlusion values are generated by ray casting from the original geometries, which will allow preservation of occlusion detail on an otherwise heavily optimized mesh. The quality and noise of the ambient occlusion mesh can be controlled by setting the number of rays per pixel, as well as the falloff and occlusion multiplier for the rays. Note that increasing the multisampling in the mapping image settings can be used to further reduce noise.
The following example shows how to use the IAmbientOcclusionCaster to generate an ambient occlusion map.
# ColorCaster
The ColorCaster is used to cast material color information from the original geometries. The caster can cast ambient, diffuse, specular, emmisive and opacity color data. It is possible to add color data, which is set using the ColorType parameter.
When casting the specular channel, Simplygon will cast the shininess of the input materials into the alpha channel of the output texture if one is available. To get the correct result, the alpha component of the base-color of the destination material must be set to 128 to ensure correct scaling of the shininess factor when the texture is created. For an example of how to bake shininess, see the reduction example. Simplygon supports textures both with and without sRGB color format. Call SetsRGB to set whether textures are in sRGB format.
The following example shows how to use the IColorCaster to cast diffuse color data.
# DisplacementCaster
The DisplacementCaster is used to generate a displacement map containing the delta-values between the original and the processed geometries. The caster can be configured to generate either a scalar displacement value, or a displacement vector.
The values are divided by a scaling value and clamped into the [-1,1] range, or clamped to length 1 in the case of vectors, before being stored in the map.
The following example shows how to use the IDisplacementCaster to generate a displacement map.
# NormalCaster
The NormalCaster is used to cast normals data from the original geometries.
The following example shows how to use the NormalCaster to generate a normal map.
# OpacityCaster
The OpacityCaster is used to cast opacity values, and can be used when opacity is needed as a separate texture.
The following example shows how to use the IOpacityCaster to generate an opacity map.