Opacity caster
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 OpacityCaster to generate an opacity map.
cpp
void GenerateOpacityMap( spMaterial output_material, spMappingImage mapping_image, spMaterialTable source_materials )
{
// Cast displacement texture data.
spOpacityCaster cast = sg->CreateOpacityCaster();
cast->SetSourceMaterials( source_materials );
cast->SetMappingImage( mapping_image );
cast->SetOutputChannels( 1 ); // 1 channel
cast->SetOutputChannelBitDepth( 8 ); // 8 bits per channel
cast->SetOutputFilePath( "opacity_out.png" );
cast->CastMaterials();
// Set material to point to created texture filename.
output_material->SetTexture( SG_MATERIAL_CHANNEL_OPACITY, "opacity_out.png" );
}
csharp
void GenerateOpacityMap(spMaterial output_material, spMappingImage mapping_image, spMaterialTable source_materials)
{
// Cast displacement texture data.
spOpacityCaster cast = sg.CreateOpacityCaster();
cast.SetSourceMaterials(source_materials);
cast.SetMappingImage(mapping_image);
cast.SetOutputChannels(1); // 1 channel
cast.SetOutputChannelBitDepth(8); // 8 bits per channel
cast.SetOutputFilePath("opacity_out.png");
cast.RunProcessing();
// Set material to point to created texture filename.
output_material.SetTexture(Simplygon.Simplygon.SG_MATERIAL_CHANNEL_OPACITY, "opacity_out.png");
}
python
def GenerateDisplacementMap( output_material, mapping_image, source_materials ):
# Cast displacement texture data.
cast = sg.CreateOpacityCaster()
cast.SetSourceMaterials( source_materials )
cast.SetMappingImage( mapping_image )
cast.SetOutputChannels( 1 ) # 1 channel
cast.SetOutputChannelBitDepth( 8 ) # 8 bits per channel
cast.SetOutputFilePath( "opacity_out.png" )
cast.CastMaterials()
# Set material to point to created texture filename.
output_material.SetTexture( SG_MATERIAL_CHANNEL_OPACITY, "opacity_out.png" )