Skip to content
On this page

Displacement caster

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 DisplacementCaster to generate a displacement map.

cpp
void GenerateDisplacementMap( spMappingImage mapping_image )
{
    // Cast displacement texture data.
    spDisplacementCaster cast = sg->CreateDisplacementCaster();       
    // The mapping image from the process.
    cast->SetMappingImage( mapping_image );
    cast->SetGenerateScalarDisplacement( true );
    cast->SetDistanceScaling( 0.1 ); // Divide values by 0.1
    cast->SetOutputChannels( 1 ); // 1 channel
    cast->SetOutputChannelBitDepth( 8 ); // 8 bits per channel
    cast->SetOutputFilePath( "displacement_out.png" );
    cast->CastMaterials();
}
csharp
void GenerateDisplacementMap(spMappingImage mapping_image)
{
    // Cast displacement texture data.
    spDisplacementCaster cast = sg.CreateDisplacementCaster();
    // The mapping image from the process.
    cast.SetMappingImage(mapping_image);
    cast.SetGenerateScalarDisplacement(true);
    cast.SetDistanceScaling(0.1f); // Divide values by 0.1
    cast.SetOutputChannels(1); // 1 channel
    cast.SetOutputChannelBitDepth(8); // 8 bits per channel
    cast.SetOutputFilePath("displacement_out.png");
    cast.RunProcessing();
}
python
def GenerateDisplacementMap( mapping_image ):
    #  Cast displacement texture data.
    cast = sg.CreateDisplacementCaster()       
	
    #  The mapping image from the process.
    cast.SetMappingImage( mapping_image )
    cast.SetGenerateScalarDisplacement( True )
    cast.SetDistanceScaling( 0.1 ) #  Divide values by 0.1
    cast.SetOutputChannels( 1 ) #  1 channel
    cast.SetOutputChannelBitDepth( 8 ) #  8 bits per channel
    cast.SetOutputFilePath( "displacement_out.png" )
    cast.CastMaterials()