Skip to content
On this page

Compute caster

The ComputeCaster is complimentary caster to all the previously mentioned casters except for vertex color caster. Therefore it can be used to cast color, normal, opacity and etc to a image data object.

See compute casting for more details on what else is required from the users side to use the compute caster.

The following example shows how to use the ComputeCaster to generate a diffuse map. Note the below snippet only cover the setting up of compute caster object.

cpp
void GenerateDiffuseMapUsingComputeCaster( spMaterial output_material, spMappingImage mapping_image, spMaterialTable source_materials, spTextureTable source_textures )
{
    // Cast color data.
    auto cast = sg->CreateComputeCaster();
    cast->SetSourceMaterials( source_materials );
    cast->SetSourceTextures( source_textures );
    cast->SetMappingImage( mapping_image );

    cast->GetComputeCasterSettings()->SetDilation( 8 ); 
    cast->GetComputeCasterSettings()->SetMaterialChannel( SG_MATERIAL_CHANNEL_DIFFUSE );
	cast->GetComputeCasterSettings()->SetOutputPixelFormat( EPixelFormat::R8G8B8 );
	cast->GetComputeCasterSettings()->SetOutputColorSpace( EImageColorSpace::sRGB );
	cast->GetComputeCasterSettings()->SetFillMode( EAtlasFillMode::NoFill );

    cast->SetOutputFilePath( "diffuse.png" );

    auto errorCode = cast->RunProcessing();
    
    // Set material to point to created texture filename. 
    output_material->SetTexture( SG_MATERIAL_CHANNEL_DIFFUSE, "diffuse.png" );
}
csharp
void GenerateDiffuseMapUsingComputeCaster(spMaterial output_material, spMappingImage mapping_image, spMaterialTable source_materials, spTextureTable source_textures)
{
    // Cast color data.
    var cast = sg.CreateComputeCaster();
    cast.SetSourceMaterials( source_materials );
    cast.SetSourceTextures( source_textures );
    cast.SetMappingImage( mapping_image );

    cast.GetComputeCasterSettings().SetDilation( 8 ); 
    cast->GetComputeCasterSettings().SetMaterialChannel( Simplygon.Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE );
	cast->GetComputeCasterSettings().SetOutputPixelFormat( Simplygon.Simplygon.EPixelFormat.R8G8B8 );
	cast->GetComputeCasterSettings().SetOutputColorSpace( Simplygon.Simplygon.EImageColorSpace.sRGB );
	cast->GetComputeCasterSettings().SetFillMode( Simplygon.Simplygon.EAtlasFillMode.NoFill );

    cast.SetOutputFilePath("diffuse.png");

    var errorCode = cast.RunProcessing();

    // Set material to point to created texture filename.      
    output_material.SetTexture(Simplygon.Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE, "diffuse.png");
}
python
def GenerateDiffuseMapUsingComputeCaster( output_material, mapping_image, source_materials, source_textures ):
    #  Cast color data.
    cast = sg.CreateComputeCaster()       
    cast.SetSourceMaterials( source_materials )
    cast.SetSourceTextures( source_materials )
    cast.SetMappingImage( mapping_image )
    
    cast.GetComputeCasterSettings().SetDilation( 8 ); 
    cast.GetComputeCasterSettings().SetMaterialChannel( Simplygon.SG_MATERIAL_CHANNEL_DIFFUSE )
	cast.GetComputeCasterSettings().SetOutputPixelFormat( Simplygon.EPixelFormat_R8G8B8 )
	cast.GetComputeCasterSettings().SetOutputColorSpace( Simplygon.EImageColorSpace_sRGB )
	cast.GetComputeCasterSettings().SetFillMode( Simplygon.EAtlasFillMode_NoFill )

    cast.SetOutputFilePath( "diffuse.png" )
    cast.CastMaterials()
       
    #  Set material to point to created texture filename.      
    output_material.SetTexture( SG_MATERIAL_CHANNEL_OPACITY, "diffuse.png" )