fresnel

Overview

Device

Hardware device to use for ray tracing.

pathtrace

Path trace a scene.

preview

Preview a scene.

Scene

Content of the scene to ray trace.

Details

The fresnel ray tracing package.

class fresnel.Device(mode='auto', n=None)

Hardware device to use for ray tracing.

Parameters
  • mode (str) – Specify execution mode: Valid values are auto, gpu, and cpu.

  • n (int) – Specify the number of cpu threads / GPUs this device will use. None will use all available threads / devices.

Device defines hardware device to use for ray tracing. Scene and Tracer instances must be attached to a Device. You may attach any number of scenes and tracers to a single Device.

See also

Tutorials:

When mode is auto, the default, Device will select GPU rendering if available and fall back on CPU rendering if not. Set mode to gpu or cpu to force a specific mode.

Important

By default (n==None), this device will use all available GPUs or CPU cores. Set n to the number of GPUs or CPU cores this device should use. When selecting n GPUs, the device selects the first n in the available_gpus list.

Tip

Use only a single Device to reduce memory consumption.

The static member available_modes lists which modes are available. For a mode to be available, the corresponding module must be enabled at compile time. Additionally, there must be at least one GPU present for the gpu mode to be available.

>>> fresnel.Device.available_modes
['gpu', 'cpu', 'auto']
available_gpus = []

Available GPUS.

Type

list[str]

available_modes = []

Available execution modes.

Type

list[str]

property mode

The active mode.

Type

str

class fresnel.Scene(device=None, camera=None, lights=None)

Content of the scene to ray trace.

Parameters
  • device (Device) – Device to use when rendering the scene.

  • camera (camera.Camera) –

    Camera to view the scene. When None, defaults to:

    camera.Orthographic(position=(0, 0, 100),
                        look_at=(0, 0, 0),
                        up=(0, 1, 0),
                        height=100)
    

  • lights (list[Light]) – Lights to light the scene. When None, defaults to: light.rembrandt()

Scene defines the contents of the scene to be traced, including any number of Geometry objects, the Camera, the background_color, background_alpha, and lights.

Every Scene must be associated with a Device. For convenience, Scene creates a default Device when device is None.

property background_alpha

Background alpha (opacity) in the range [0,1].

Type

float

property background_color

Background color linear RGB.

Note

Use fresnel.color.linear to convert standard sRGB colors into the linear color space used by fresnel.

Type

((3, ) numpy.ndarray of numpy.float32)

property camera

Camera view parameters.

Type

camera.Camera

property device

Device this Scene is attached to.

Type

Device

get_extents()

Get the extents of the scene.

Returns

The lower left and upper right corners of the scene.

Return type

(3,2) numpy.ndarray of numpy.float32

property lights

Lights in the scene.

lights is a sequence of up to 4 directional lights that apply to the scene. Each light has a direction, color, and size.

Type

list[Light]

fresnel.pathtrace(scene, w=600, h=370, samples=64, light_samples=1)

Path trace a scene.

Parameters
  • scene (Scene) – Scene to render.

  • w (int) – Output image width (in pixels).

  • h (int) – Output image height (in pixels).

  • samples (int) – Number of times to sample the pixels of the scene.

  • light_samples (int) – Number of light samples to take for each pixel sample.

pathtrace() is a shortcut that renders output with tracer.Path.

fresnel.preview(scene, w=600, h=370, anti_alias=True)

Preview a scene.

Parameters
  • scene (Scene) – Scene to render.

  • w (int) – Output image width (in pixels).

  • h (int) – Output image height (in pixels).

  • anti_alias (bool) – Whether to perform anti-aliasing.

preview() is a shortcut that renders output with tracer.Preview.

Modules