Skip to content
On this page

Normal caster

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.

cpp
void CastNormalData( spMaterial output_material, spMappingImage mapping_image, spMaterialTable source_materials )
{
    // Cast the data using a normal caster.
    spNormalCaster cast = sg->CreateNormalCaster();       
    cast->SetSourceMaterials( source_materials );
    cast->SetMappingImage( mapping_image );       
    // Set output image settings. Use 3 channels
    // (the x, y and z values for the normal).
    cast->SetOutputChannels( 3 );
    cast->SetOutputChannelBitDepth( 8 );       
    cast->SetDilation( 10 );       
    cast->SetOutputFilePath( "normals_out.png" );
    cast->SetFlipBackfacingNormals( false );       
    cast->SetGenerateTangentSpaceNormals( true );   
   
    // Cast the data   
    cast->CastMaterials();
       
    // Set material to point to created texture filename.      
    output_material->SetTexture( SG_MATERIAL_CHANNEL_NORMALS, "normals_out.png" );
}
csharp
void CastNormalData(spMaterial output_material, spMappingImage mapping_image, spMaterialTable source_materials)
{
    // Cast the data using a normal caster.
    spNormalCaster cast = sg.CreateNormalCaster();
    cast.SetSourceMaterials(source_materials);
    cast.SetMappingImage(mapping_image);
    // Set output image settings. Use 3 channels
    // (the x, y and z values for the normal).
    cast.SetOutputChannels(3);
    cast.SetOutputChannelBitDepth(8);
    cast.SetDilation(10);
    cast.SetOutputFilePath("normals_out.png");
    cast.SetFlipBackfacingNormals(false);
    cast.SetGenerateTangentSpaceNormals(true);

    // Cast the data   
    cast.RunProcessing();

    // Set material to point to created texture filename.      
    output_material.SetTexture(Simplygon.Simplygon.SG_MATERIAL_CHANNEL_NORMALS, "normals_out.png");
}
python
def CastNormalData( output_material, mapping_image, source_materials ):
{
    #  Cast the data using a normal caster.
    cast = sg.CreateNormalCaster()       
    cast.SetSourceMaterials( source_materials )
    cast.SetMappingImage( mapping_image )       
	
    #  Set output image settings. Use 3 channels
    #  (the x, y and z values for the normal).
    cast.SetOutputChannels( 3 )
    cast.SetOutputChannelBitDepth( 8 )       
    cast.SetDilation( 10 )       
    cast.SetOutputFilePath( "normals_out.png" )
    cast.SetFlipBackfacingNormals( False )       
    cast.SetGenerateTangentSpaceNormals( True )   
   
    #  Cast the data   
    cast.CastMaterials()
       
    #  Set material to point to created texture filename.      
    output_material.SetTexture( Simplygon.SG_MATERIAL_CHANNEL_NORMALS, "normals_out.png" )
}