Rendering#

SAMSON provides a range of rendering effects and integrates Cycles Renderer, the path-tracing renderer from Blender.

Rendering effects#

SAMSON provides various rendering options (styles, special effects, etc) to help you create beautiful visualizations and animations:

  • Ambient occlusion

  • Anti-aliasing

  • Background

  • Bloom

  • Depth of field rendering

  • Fog

  • Lighting

  • Pinhole

  • Shadows

  • Silhouettes

You can change these rendering options using SAMSON.runCommand() (see Running actions):

Change background to white#
SAMSON.runCommand('Background > White')

Render presets#

SAMSON provides SBRenderPreset, a class that stores rendering preferences. You can add multiple render preset nodes to a document, copy them, and apply them to restore global rendering settings.

Please refer to SBRenderPreset for more information.

Create and add a render preset#
# create it based on the current rendering settings
renderPreset = SAMSON.createRenderPreset()
# or construct a render preset node with default settings
#renderPreset = SBRenderPreset("Render preset")

# change the render preset properties

# make the operation undoable
with SAMSON.holding("Add render preset"):
    SAMSON.hold(renderPreset)
    # create a render preset node
    renderPreset.create()

    # add it to the active document
    SAMSON.getActiveDocument().addChild(renderPreset)

You can then simply apply the render preset to change the rendering settings.

Apply a render preset#
# make the operation undoable
with SAMSON.holding("Apply render preset"):
    # apply a render preset
    renderPreset.apply()

See also

SBRenderPreset

Rendering using Cycles#

SAMSON integrates Cycles Renderer, a path-tracing renderer from Blender. Cycles provides interactive photorealistic rendering so you can create studio-quality images and animations directly inside SAMSON.

See also

User Guide: Rendering using Cycles

You can activate and deactivate the path tracing using SAMSON.runCommand():

Toggle path tracing#
SAMSON.runCommand('Trace')

You can change material appearances that affect the rendering with path tracing. For that, you can either modify specific attributes of the node’s material or set an appearance preset using the SBNode.setMaterialAppearance() function.

Set material appearances to the last visual model#
# get the indexer of visual models in the active document
visualModelIndexer = SAMSON.getNodes('node.type visualModel')
if len(visualModelIndexer):
    # get the last visual model
    visualModel = visualModelIndexer[-1]

    # make the operation undoable
    with SAMSON.holding('Add material'):
        # set a material appearance to the visual model
        visualModel.setMaterialAppearance('Transparent: Glass')

    # start path-tracing
    SAMSON.runCommand('Trace')
Set material appearances to visual models based on their type#
# get the indexer of visual models in the active document
visualModelIndexer = SAMSON.getNodes('n.t vm')
if len(visualModelIndexer):
    # make the operation undoable
    with SAMSON.holding('Add material'):
        for visualModel in visualModelIndexer:
            # set material appearances to the visual models based on their types
            if visualModel.isLicorice():
                visualModel.setMaterialAppearance('Emissive: Glowing (10)')
            elif visualModel.isVanDerWaals():
                visualModel.setMaterialAppearance('Transparent: Water')
            elif visualModel.isRibbon():
                visualModel.setMaterialAppearance('Smooth: Shiny plastic')

    # start path-tracing
    SAMSON.runCommand('Trace')

You can export a rendered image from SAMSON using the SAMSON.captureViewportToFile() function by setting its usePathTracing parameter to True:

Render the viewport into an image#
SAMSON.captureViewportToFile(filename = "/path/to/image.png",
    width = 1000, height = 800,
    usePathTracing = True)