Skip to content

JasperJeuken/PythonRayTracer

Repository files navigation

Pure Python Ray Tracer

Note: I built a similar engine in C++ with more functionality and vastly better performance here.

1000 x 1000 Cornell box rendered with 1500 samples per pixel 1000x1000 Cornell box render

Features

  • Monte Carlo Ray Tracing
  • Colorable volumetric light sources
  • Multiple materials:
    • Diffuse (Lambertian)
    • Metallic (with color and fuzziness)
    • Dielectric (glass) with refractive index
  • Multiple textures:
    • Single color
    • Checkered
    • Perlin noise (marble-like)
    • Image (from file)
  • Multi-process rendering for multi-core CPUs
  • Bounding volume hierarchy for faster rendering
  • Customizable camera:
    • Change position and target
    • Depth of field using aperture and focus distance
    • Field of view and aspect ratio

Installation

Uses only helper functions from standard Python libraries, except for loading images to the image texture with the Python Imaging Library.

Usage

Run from command prompt:

C:path_to_folder> python main.py

Optional argument for specifying the number of processes to spread the render over:

C:path_to_folder> python main.py -p 4

Can also be compiled with PyPy using Just-in-Time compiling (JIT):

C:path_to_folder> pypy3 main.py

In main.py the camera and scene settings can be adjusted. scene.py contains several pre-made scenes, but more can easily be added by copying one of these functions.

Attribution

Created using "Ray Tracing in One Weekend Series" (v3.2.0) for C++ by Peter Shirley (Steve Hollasch, Trevor David Black).
With snippets from Arun Ravindran ArunRocks series Puray.

Gallery

2000 x 864 render showing the fuzziness parameter from 0 to 1 (left to right) 2000 x 864 render showing the fuzziness of metal

1600 x 1080 render showing three materials: metal, diffusive and dielectric 1600 x 1080 render of three different materials

1000 x 1000 render showing of a sphere with an Earth image texture applied 1000 x 1000 render showing an image-textured sphere

1000 x 1000 render showing a marble-like material generated with Perlin noise 1000 x 1000 render showing a marble-like material generated with Perlin noise

About

Ray tracer coded purely in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages