Rendering#

SAMSON provides various rendering effects and integrates Cycles Renderer, a 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

  • Lightning

  • 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 the rendering preferences. You can add multiple render preset nodes in a document, copy them, and apply them to set the global rendering settings accordingly.

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
SAMSON.beginHolding("Add render preset")

SAMSON.hold(renderPreset)
# create a render preset node
renderPreset.create()

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

# stop the undoable operation
SAMSON.endHolding()

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

Apply a render preset#
# make the operation undoable
SAMSON.beginHolding("Apply render preset")
# apply a render preset
renderPreset.apply()
# stop the undoable operation
SAMSON.endHolding()

See also

SBRenderPreset

Rendering using Cycles#

SAMSON integrates Cycles Renderer, a path tracing renderer, from Blender. The Cycles Renderer offers you interactive photorealistic rendering capabilities that will allow you to create studio-quality rendering for images and animations right within 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
    SAMSON.beginHolding('Add material')

    # set a material appearance to the visual model
    visualModel.setMaterialAppearance('Transparent: Glass')

    # stop holding
    SAMSON.endHolding()
    # 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
    SAMSON.beginHolding('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')

    # stop holding
    SAMSON.endHolding()
    # 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)