fresnel.tracer

Overview

fresnel.tracer.Path

Path tracer.

fresnel.tracer.Preview

Preview ray tracer.

fresnel.tracer.Tracer

Base class for all ray tracers.

Details

Ray tracers process a fresnel.Scene and render output images.

Fresnel provides a Preview tracer to generate a quick approximate render and Path which provides soft shadows, reflections, and other effects.

See also

Introduction

Tutorial: Introduction to tracers

Tracer methods

Tutorial: Configuring tracer parameters.

class fresnel.tracer.Path(device, w, h)

Path tracer.

Parameters
  • device (Device) – Device to use for rendering.

  • w (int) – Output image width.

  • h (int) – Output image height.

The path tracer applies advanced lighting effects, including soft shadows, reflections, etc…. It operates by Monte Carlo sampling. Each call to render() performs one sample per pixel. The output image is the mean of all the samples. Many samples are required to produce a smooth image.

sample() provides a convenience API to make many samples with a single call.

reset()

Clear the output buffer and start sampling a new image. Increment the random number seed so that the new image is statistically independent from the previous.

sample(scene, samples, reset=True, light_samples=1)
Parameters
  • scene (Scene) – The scene to render.

  • samples (int) – The number of samples to take per pixel.

  • reset (bool) – When True, call reset() before sampling

Returns

A reference to the current output buffer as a fresnel.util.image_array.

Note

When reset is False, subsequent calls to sample() will continue to add samples to the current output image. Use the same number of light samples when sampling an image in this way.

class fresnel.tracer.Preview(device, w, h, aa_level=0)

Preview ray tracer.

Parameters
  • device (Device) – Device to use for rendering.

  • w (int) – Output image width.

  • h (int) – Output image height.

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

aa_level

Amount of anti-aliasing to perform

Type

int

Overview

The Preview tracer produces a preview of the scene quickly. It approximates the effect of light on materials. The output of the Preview tracer will look very similar to that from the Path tracer, but will miss soft shadows, reflection, transmittance, and other lighting effects.

TODO: show examples

Anti-aliasing

Set aa_level to control the amount of anti-aliasing performed. The default value of 0 performs no anti-aliasing to enable the fastest possible preview renders. A value of 1 samples 2x2 subpixels, a value of 2 samples 4x4 subpixels, a value of 3 samples 8x8 subpixels, etc … Samples are jittered with random numbers. Different seed values will result in different output images.

TODO: show examples

Tip

Use aa_level = 3 when using the Preview tracer to render production quality output.

class fresnel.tracer.Tracer

Base class for all ray tracers.

Tracer provides operations common to all ray tracer classes.

Each Tracer instance stores a pixel output buffer. When you render() a Scene, the current data stored in the buffer is overwritten with the new image.

Note

You cannot instantiate a Tracer directly. Use one of the sub classes.

output

Reference to the current output buffer (modified by render())

Type

fresnel.util.image_array

linear_output

Reference to the current output buffer in linear color space (modified by render())

Type

fresnel.util.array

seed

Random number seed.

Type

int

disable_highlight_warning()

Disable the highlight clipping warnings.

enable_highlight_warning(color=(1, 0, 1))

Enable highlight clipping warnings.

When a pixel in the rendered image is too bright to represent, make that pixel the given color to flag the problem to the user.

Parameters

color (tuple) – Color to make the highlight warnings.

histogram()

Compute a histogram of the image.

The histogram is computed as a lightness in the sRGB color space. The histogram is computed only over the visible pixels in the image, fully transparent pixels are ignored. The returned histogram is nbins x 4, the first column contains the lightness histogram and the next 3 contain R,B, and G channel histograms respectively.

Returns

(histogram, bin_positions).

render(scene)

Render a scene.

Parameters

scene (Scene) – The scene to render.

Returns

A reference to the current output buffer as a fresnel.util.image_array.

Render the given scene and write the resulting pixels into the output buffer.

resize(w, h)

Resize the output buffer.

Parameters
  • w (int) – New output buffer width.

  • h (int) – New output buffer height.

Warning

resize() clears any existing image in the output buffer.