Sombra is simple Raytracer written in pure Python.

Overview

Sombra

Sombra is simple Raytracer written in pure Python. It's main purpose is to help understand how raytracing works with a clean code. If you are looking for an efficient Raytracer you should probably use something like C++. The equations used are taken from the Image Synthesis class at Texas A&M University taught by professor Ergun Akleman.

The main program creates a raytraced image of a scene with simple objects like spheres and planes. It's using a resolution of 280x192px by default and random jitter anti-aliasing with 4 samples per axis.

showcase image

Usage

  • Install all dependencies by running python -m pip install -r requirements.txt
  • Run python -u main.py or python -u main.py -d to use debug mode which will not use Anti-Aliasing (-u is for displaying print messages in the console)
  • The output image will be stored in the project folder

Features

  • Sphere, Plane and Triangle objects
  • Diffuse, Specular and Border shaders
  • Area, Directional, Point and Spot lights
  • Change Field of View of camera by changing d (distance) and scale x and y parameters
  • Anti-Aliasing using Random Jitter
  • Reflection by setting Ks value to materials
  • Image textures
  • Normal Maps
  • Environment Sphere Map
  • Animation by running a physics simulation of a moving sphere

Documentation

You can see the documentation in the wiki

Testing

To run the tests use unittest in this way python -m unittest -v tests. This will run every test in the "tests" module, if you add new tests make sure to import them into the "__init__.py" file of the "tests" folder.

Dependencies

You will need to install

  • Python (3 and 2.7 are supported)

And external Python modules

  • numpy
  • pillow
  • progress

You can install the required python modules by running: python -m pip install -r requirements.txt or installing them individually: python -m pip install numpy pillow progress

Developed by Jesús Henríquez

You might also like...
Simple to use image handler for python sqlite3.

SQLite Image Handler Simple to use image handler for python sqlite3. Functions Function Name Parameters Returns init databasePath : str tableName : st

Wand is a ctypes-based simple ImageMagick binding for Python
Wand is a ctypes-based simple ImageMagick binding for Python

Wand Wand is a ctypes-based simple ImageMagick binding for Python, supporting 2.7, 3.3+, and PyPy. All functionalities of MagickWand API are implement

A simple python script to reveal the contents of a proof of vaccination QR code.

vaxidecoder A simple python script to reveal the contents of a proof of vaccination QR code. It takes a QR code image as input, and returns JSon data.

GTK and Python based, simple multiple image editor tool
GTK and Python based, simple multiple image editor tool

System Monitoring Center GTK3 and Python3 based, simple multiple image editor tool. Note: Development of this application is not completed yet. The ap

Simple Python package to convert an image into a quantized image using a customizable palette
Simple Python package to convert an image into a quantized image using a customizable palette

Simple Python package to convert an image into a quantized image using a customizable palette. Resulting image can be displayed by ePaper displays such as Waveshare displays.

Gaphor is the simple modeling tool
Gaphor is the simple modeling tool

Gaphor Gaphor is a UML and SysML modeling application written in Python. It is designed to be easy to use, while still being powerful. Gaphor implemen

MyPaint is a simple drawing and painting program that works well with Wacom-style graphics tablets.

MyPaint A fast and dead-simple painting app for artists Features Infinite canvas Extremely configurable brushes Distraction-free fullscreen mode Exten

A simple programming language for manipulating images.

f-stop A simple programming language for manipulating images. Examples OPEN "image.png" AS image RESIZE image (300, 300) SAVE image "out.jpg" CLOSE im

A simple Streamlit Component to  compare images in Streamlit apps. It integrates Knightlab's JuxtaposeJS
A simple Streamlit Component to compare images in Streamlit apps. It integrates Knightlab's JuxtaposeJS

streamlit-image-juxtapose A simple Streamlit Component to compare images in Streamlit apps using Knightlab's JuxtaposeJS. The images are saved to the

Comments
  • chore(deps): bump pillow from 8.2.0 to 8.3.2

    chore(deps): bump pillow from 8.2.0 to 8.3.2

    Bumps pillow from 8.2.0 to 8.3.2.

    Release notes

    Sourced from pillow's releases.

    8.3.2

    https://pillow.readthedocs.io/en/stable/releasenotes/8.3.2.html

    Security

    • CVE-2021-23437 Raise ValueError if color specifier is too long [hugovk, radarhere]

    • Fix 6-byte OOB read in FliDecode [wiredfool]

    Python 3.10 wheels

    • Add support for Python 3.10 #5569, #5570 [hugovk, radarhere]

    Fixed regressions

    • Ensure TIFF RowsPerStrip is multiple of 8 for JPEG compression #5588 [kmilos, radarhere]

    • Updates for ImagePalette channel order #5599 [radarhere]

    • Hide FriBiDi shim symbols to avoid conflict with real FriBiDi library #5651 [nulano]

    8.3.1

    https://pillow.readthedocs.io/en/stable/releasenotes/8.3.1.html

    Changes

    8.3.0

    https://pillow.readthedocs.io/en/stable/releasenotes/8.3.0.html

    Changes

    ... (truncated)

    Changelog

    Sourced from pillow's changelog.

    8.3.2 (2021-09-02)

    • CVE-2021-23437 Raise ValueError if color specifier is too long [hugovk, radarhere]

    • Fix 6-byte OOB read in FliDecode [wiredfool]

    • Add support for Python 3.10 #5569, #5570 [hugovk, radarhere]

    • Ensure TIFF RowsPerStrip is multiple of 8 for JPEG compression #5588 [kmilos, radarhere]

    • Updates for ImagePalette channel order #5599 [radarhere]

    • Hide FriBiDi shim symbols to avoid conflict with real FriBiDi library #5651 [nulano]

    8.3.1 (2021-07-06)

    • Catch OSError when checking if fp is sys.stdout #5585 [radarhere]

    • Handle removing orientation from alternate types of EXIF data #5584 [radarhere]

    • Make Image.array take optional dtype argument #5572 [t-vi, radarhere]

    8.3.0 (2021-07-01)

    • Use snprintf instead of sprintf. CVE-2021-34552 #5567 [radarhere]

    • Limit TIFF strip size when saving with LibTIFF #5514 [kmilos]

    • Allow ICNS save on all operating systems #4526 [baletu, radarhere, newpanjing, hugovk]

    • De-zigzag JPEG's DQT when loading; deprecate convert_dict_qtables #4989 [gofr, radarhere]

    • Replaced xml.etree.ElementTree #5565 [radarhere]

    ... (truncated)

    Commits
    • 8013f13 8.3.2 version bump
    • 23c7ca8 Update CHANGES.rst
    • 8450366 Update release notes
    • a0afe89 Update test case
    • 9e08eb8 Raise ValueError if color specifier is too long
    • bd5cf7d FLI tests for Oss-fuzz crash.
    • 94a0cf1 Fix 6-byte OOB read in FliDecode
    • cece64f Add 8.3.2 (2021-09-02) [CI skip]
    • e422386 Add release notes for Pillow 8.3.2
    • 08dcbb8 Pillow 8.3.2 supports Python 3.10 [ci skip]
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • chore(deps): bump pillow from 8.1.1 to 8.2.0

    chore(deps): bump pillow from 8.1.1 to 8.2.0

    Bumps pillow from 8.1.1 to 8.2.0.

    Release notes

    Sourced from pillow's releases.

    8.2.0

    https://pillow.readthedocs.io/en/stable/releasenotes/8.2.0.html

    Changes

    Dependencies

    Deprecations

    ... (truncated)

    Changelog

    Sourced from pillow's changelog.

    8.2.0 (2021-04-01)

    • Added getxmp() method #5144 [UrielMaD, radarhere]

    • Add ImageShow support for GraphicsMagick #5349 [latosha-maltba, radarhere]

    • Do not load transparent pixels from subsequent GIF frames #5333 [zewt, radarhere]

    • Use LZW encoding when saving GIF images #5291 [raygard]

    • Set all transparent colors to be equal in quantize() #5282 [radarhere]

    • Allow PixelAccess to use Python int when parsing x and y #5206 [radarhere]

    • Removed Image._MODEINFO #5316 [radarhere]

    • Add preserve_tone option to autocontrast #5350 [elejke, radarhere]

    • Fixed linear_gradient and radial_gradient I and F modes #5274 [radarhere]

    • Add support for reading TIFFs with PlanarConfiguration=2 #5364 [kkopachev, wiredfool, nulano]

    • Deprecated categories #5351 [radarhere]

    • Do not premultiply alpha when resizing with Image.NEAREST resampling #5304 [nulano]

    • Dynamically link FriBiDi instead of Raqm #5062 [nulano]

    • Allow fewer PNG palette entries than the bit depth maximum when saving #5330 [radarhere]

    • Use duration from info dictionary when saving WebP #5338 [radarhere]

    • Stop flattening EXIF IFD into getexif() #4947 [radarhere, kkopachev]

    ... (truncated)

    Commits
    • e0e353c 8.2.0 version bump
    • ee635be Merge pull request #5377 from hugovk/security-and-release-notes
    • 694c84f Fix typo [ci skip]
    • 8febdad Review, typos and lint
    • fea4196 Reorder, roughly alphabetic
    • 496245a Fix BLP DOS -- CVE-2021-28678
    • 22e9bee Fix DOS in PSDImagePlugin -- CVE-2021-28675
    • ba65f0b Fix Memory DOS in ImageFont
    • bb6c11f Fix FLI DOS -- CVE-2021-28676
    • 5a5e6db Fix EPS DOS on _open -- CVE-2021-28677
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • chore(deps): bump pillow from 7.1.2 to 8.1.1

    chore(deps): bump pillow from 7.1.2 to 8.1.1

    Bumps pillow from 7.1.2 to 8.1.1.

    Release notes

    Sourced from pillow's releases.

    8.1.1

    https://pillow.readthedocs.io/en/stable/releasenotes/8.1.1.html

    8.1.0

    https://pillow.readthedocs.io/en/stable/releasenotes/8.1.0.html

    Changes

    Dependencies

    Deprecations

    ... (truncated)

    Changelog

    Sourced from pillow's changelog.

    8.1.1 (2021-03-01)

    • Use more specific regex chars to prevent ReDoS. CVE-2021-25292 [hugovk]

    • Fix OOB Read in TiffDecode.c, and check the tile validity before reading. CVE-2021-25291 [wiredfool]

    • Fix negative size read in TiffDecode.c. CVE-2021-25290 [wiredfool]

    • Fix OOB read in SgiRleDecode.c. CVE-2021-25293 [wiredfool]

    • Incorrect error code checking in TiffDecode.c. CVE-2021-25289 [wiredfool]

    • PyModule_AddObject fix for Python 3.10 #5194 [radarhere]

    8.1.0 (2021-01-02)

    • Fix TIFF OOB Write error. CVE-2020-35654 #5175 [wiredfool]

    • Fix for Read Overflow in PCX Decoding. CVE-2020-35653 #5174 [wiredfool, radarhere]

    • Fix for SGI Decode buffer overrun. CVE-2020-35655 #5173 [wiredfool, radarhere]

    • Fix OOB Read when saving GIF of xsize=1 #5149 [wiredfool]

    • Makefile updates #5159 [wiredfool, radarhere]

    • Add support for PySide6 #5161 [hugovk]

    • Use disposal settings from previous frame in APNG #5126 [radarhere]

    • Added exception explaining that repr_png saves to PNG #5139 [radarhere]

    • Use previous disposal method in GIF load_end #5125 [radarhere]

    ... (truncated)

    Commits
    • 741d874 8.1.1 version bump
    • 179cd1c Added 8.1.1 release notes to index
    • 7d29665 Update CHANGES.rst [ci skip]
    • d25036f Credits
    • 973a4c3 Release notes for 8.1.1
    • 521dab9 Use more specific regex chars to prevent ReDoS
    • 8b8076b Fix for CVE-2021-25291
    • e25be1e Fix negative size read in TiffDecode.c
    • f891baa Fix OOB read in SgiRleDecode.c
    • cbfdde7 Incorrect error code checking in TiffDecode.c
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Releases(v0.9.1)
  • v0.9.1(Oct 18, 2021)

    Optimization of rendering using multiprocessing. Now it's using about 30% of the memory it used before and it's faster. That's because now rays are created and traced in the same function that goes in parallel.

    Also now using imap_unordered function for memory optimization (https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.map)

    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Dec 28, 2020)

    • Use many processes with multiprocessing library
    • This is a first version, it's not efficient with memory. It creates every ray at the beginning (memory expensive) and creates a pool with all of them, in the future maybe it would be better to create some of the rays, start the workers, wait for them, then create more rays, and assign to workers like that in a loop until the entire screen is finished
    • At resolution of 720p it took ~10GB of RAM for 8 processes
    Source code(tar.gz)
    Source code(zip)
  • v0.8.0(Dec 27, 2020)

    • Pathtracing with Russian Roulette
    • Caustics using Light Raytracing (Backwards Raytracing) with Illumination Maps

    (see pathtracer.py inside examples)

    Source code(tar.gz)
    Source code(zip)
  • v0.7.0(Jul 12, 2020)

    Add Depth of Field (an out of focus effect) by using a virtual camera lens, with parameters:

    • f: focal distance, which is the distance from the view window (image plane) to the focal plane (where every object is in focus)
    • ap_sx: aperture size in the horizontal coordinate
    • ap_sy: aperture size in the vertical coordinate
    Source code(tar.gz)
    Source code(zip)
  • v0.6.1(Jun 28, 2020)

    • Fix variable with same name, light for barycentric shading and light for scene lights in compute_color function
    • Fix error when animation_out folder doesn't exist, in create_animation function
    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(May 24, 2020)

    • State class that stores position, velocity, rotation, angular velocity, scale and mass.
    • Simulation module that include RigidBody with a simulate_physics function, which changes State using a given time delta. The Simulation has a run function that will simulate physics on each RigidBody of the system for the duration time of the simulation.
    • Animation module which includes Keyframe and Transform, and can create a series of keyframes using a list of states and then use the list of keyframes to render a list of images.
    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Apr 25, 2020)

  • v0.3.0(Apr 9, 2020)

  • v0.2.0(Mar 31, 2020)

  • v0.1.0(Mar 24, 2020)

Owner
Hernaldo Jesus Henriquez Nuñez
MS Viz (CG) at Texas A&M. BS CS at PUC. Have seen too many episodes of The Simpsons. Love God.
Hernaldo Jesus Henriquez Nuñez
A pure python implementation of the GIMP XCF image format. Use this to interact with GIMP image formats

Pure Python implementation of the GIMP image formats (.xcf projects as well as brushes, patterns, etc)

FHPyhtonUtils 8 Dec 30, 2022
MaryJane is a simple MJPEG server written in Python.

MaryJane is a simple MJPEG server written in Python.

bootrino 152 Dec 13, 2022
Simple Python image processing & automatization project for a simple web based game

What is this? Simple Python image processing & automatization project for a simple web based game Made using only Github Copilot (except the color and

SGeri 2 Aug 15, 2022
Gallery written in Python to manage your photos

GalleryMan Gallery written in Python to manage your photos Installation

Asian Cat 24 Dec 18, 2022
a lite weight photo editor written in python for day to day photo editing!

GNU-PhotoShop A lite weight Photo editing Program (currently CLI only) written in python3 for day to day photo editing. Disclaimer : Currently we don'

Kunal Sharma 5 May 30, 2022
Samila is a generative art generator written in Python

Samila is a generative art generator written in Python, Samila let's you create arts based on many thousand points. The position of every single point is calculated by a formula, which has random parameters. Because of the random numbers, every image looks different.

Sepand Haghighi 947 Dec 30, 2022
Py3D - A 3d rendering engine written entirely in python

Py3D is a 3d rendering engine written entirely in python. It is a simple and eas

1up Community 2 Nov 14, 2022
Raven is a tool written in Python3 allowing you to generate an unique image with some text.

?? Raven is a tool written in Python3 allowing you to generate an unique image with some text. It does it by searching the text on Google, do

Billy 39 Dec 20, 2022
The ctypes-based simple ImageMagick binding for Python

Wand Wand is a ctypes-based simple ImageMagick binding for Python, supporting 2.7, 3.3+, and PyPy. All functionalities of MagickWand API are implement

Eric McConville 1.2k Dec 30, 2022
Simple Python / ImageMagick script to package images into WAD3s for use as GoldSrc textures.

WADs Out For [The] Ladies Simple Python / ImageMagick script to package images into WAD3s for use as GoldSrc textures. Development mostly focused on L

null 5 Apr 9, 2022