Color caster
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 ColorCaster to cast diffuse color data.
void CastDiffuseColorData( spMaterial output_material, spMappingImage mapping_image, spMaterialTable source_materials )
{
// Cast diffuse texture data using a color caster.
spColorCaster cast = sg->CreateColorCaster();
cast->SetColorType( SG_MATERIAL_CHANNEL_DIFFUSE );
cast->SetSourceMaterials( source_materials );
// The mapping image from the process.
cast->SetMappingImage( mapping_image );
cast->SetOutputChannels( 3 ); // RGB, 3 channels
cast->SetOutputChannelBitDepth( 8 ); // 8 bits per channel, 24bpp
cast->SetOutputFilePath( "diffuse_out.png" );
cast->CastMaterials();
// Set the diffuse multiplier for the texture.
// 1 means it will not differ from original texture,
// Example: 0 would ignore a specified color and
// 2 would make a color twice as pronounced as the others.
output_material->SetColor( SG_MATERIAL_CHANNEL_DIFFUSE, 1.0, 1.0, 1.0, 1.0 );
// Set material to point to created texture filename.
output_material->SetTexture( SG_MATERIAL_CHANNEL_DIFFUSE, "diffuse_out.png" );
}
void CastDiffuseColorData(spMaterial output_material, spMappingImage mapping_image, spMaterialTable source_materials)
{
// Cast diffuse texture data using a color caster.
spColorCaster cast = sg.CreateColorCaster();
cast.SetColorType(Simplygon.Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE);
cast.SetSourceMaterials(source_materials);
// The mapping image from the process.
cast.SetMappingImage(mapping_image);
cast.SetOutputChannels(3); // RGB, 3 channels
cast.SetOutputChannelBitDepth(8); // 8 bits per channel, 24bpp
cast.SetOutputFilePath("diffuse_out.png");
cast.RunProcessing();
// Set the diffuse multiplier for the texture.
// 1 means it will not differ from original texture,
// Example: 0 would ignore a specified color and
// 2 would make a color twice as pronounced as the others.
output_material.SetColor(Simplygon.Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE, 1.0, 1.0, 1.0, 1.0);
// Set material to point to created texture filename.
output_material.SetTexture(Simplygon.Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE, "diffuse_out.png");
}
def CastDiffuseColorData( output_material, mapping_image, source_materials ):
# Cast diffuse texture data using a color caster.
cast = sg.CreateColorCaster()
cast.SetColorType( Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE )
cast.SetSourceMaterials( source_materials )
# The mapping image from the process.
cast.SetMappingImage( mapping_image )
cast.SetOutputChannels( 3 ) # RGB, 3 channels
cast.SetOutputChannelBitDepth( 8 ) # 8 bits per channel, 24bpp
cast.SetOutputFilePath( "diffuse_out.png" )
cast.CastMaterials()
# Set the diffuse multiplier for the texture.
# 1 means it will not differ from original texture,
# Example: 0 would ignore a specified color and
# 2 would make a color twice as pronounced as the others.
output_material.SetColor( Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE, 1.0, 1.0, 1.0, 1.0 )
# Set material to point to created texture filename.
output_material.SetTexture( Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE, "diffuse_out.png" )