fresnel

Overview

fresnel.Device

Hardware device to use for ray tracing.

fresnel.Scene

Content of the scene to ray trace.

Details

The fresnel ray tracing package.

fresnel.__version__

Fresnel version

Type

str

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 sets no limit.

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

examples/02-Advanced-topics/01-Devices

Tutorial: Using devices.

examples/02-Advanced-topics/02-Tracer-methods

Tutorial: Using tracers with devices.

When mode is auto, the default, Device GPU rendering and fall back on CPU rendering if there is no GPU available or GPU support was not compiled in. 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_modes

List of the available execution modes (static member).

Type

list

available_gpus

List of the available gpus (static member).

Type

list

mode

The active mode

Type

str

class fresnel.Scene(device=None, camera='auto', lights=[<fresnel.light.Light object>, <fresnel.light.Light object>])

Content of the scene to ray trace.

Parameters

device (Device) – Device to create this Scene on.

Scene defines the contents of the scene to be ray traced, including any number of geometry objects, the camera, background color, background alpha, and the lights.

Every Scene attaches to a Device. For convenience, Scene creates a default Device when device is None. If you want a non-default device, you must create it explicitly.

See also

examples/00-Basic-tutorials/00-Introduction

Tutorial: Introduction to scenes

examples/00-Basic-tutorials/04-Scene-properties

Tutorial: Setting scene properties.

examples/00-Basic-tutorials/05-Lighting-setups

Tutorial: Using lighting setups with scenes.

examples/02-Advanced-topics/01-Devices

Tutorial: Using devices.

Lights

lights is a sequence of up to 4 directional lights that apply to the scene globally. Each light has a direction and color. You can assign lights using one of the predefined setups:

scene.lights = fresnel.light.butterfly()

You can assign a sequence of Light objects:

scene.lights = [fresnel.light.Light(direction=(1,2,3))]

You can modify the lights in place:

>>> print(len(scene.lights))
2
>>> l.append(fresnel.light.Light(direction=(1,0,0), color=(1,1,1)))
>>> print(len(3))
1
>>> print(l[2]).direction
(1,0,0)
>>> l[0].direction = (-1,0,0)
>>> print(l[0]).direction
(-1,0,0)
device

Device this Scene is attached to.

Type

Device

camera

Camera view parameters, or ‘auto’ to automatically choose a camera.

Type

camera.Camera

background_color

Background color (r,g,b) as a tuple or other 3-length python object, in the linearized color space. Use fresnel.color.linear() to convert standard sRGB colors

Type

tuple[float]

background_alpha

Background alpha (opacity).

Type

float

lights

Globals lights in the scene.

Type

list[light.Light]

get_extents()

Get the extents of the scene

Returns

[[minimum x, minimum y, minimum z], [maximum x, maximum y, maximum z]]

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.

  • h (int) – Output image height.

  • 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 to rendering output with the Path tracer. See the Path tracer for a complete description.

fresnel.preview(scene, w=600, h=370, aa_level=0)

Preview a scene.

Parameters
  • scene (Scene) – Scene to render.

  • w (int) – Output image width.

  • h (int) – Output image height.

  • aa_level (int) – Amount of anti-aliasing to perform

preview() is a shortcut to rendering output with the Preview tracer. See the Preview tracer for a complete description.

Modules