![Logo](/Boazius/TAU-Graphics-Ex2-RayTracing/raw/master/images/tauLogo.jpg)
Basic ray tracer with Spheres, Cubes and planes - created as part of the TAU Graphics course
Report Bug
·
Request Feature
Originally on https://github.com/nogakinor/RayTracing
This project involves the implementation of a basic ray tracer. The ray tracer simulates the propagation of light rays from an observer's eye (the camera) through a screen and into a scene containing various surfaces. The implementation calculates the intersections of rays with surfaces, determines the nearest intersection, and computes the color of the surface based on its material and lighting conditions.
The ray tracer includes the following features:
- Spheres
- Infinite planes
- Cubes
Each surface is associated with a specific material that includes attributes such as:
- Diffuse color
- Specular color
- Phong specularity coefficient
- Reflection color
- Transparency
The scene is illuminated by point lights, each with attributes including position, color, specular intensity, shadow intensity, and light radius.
The camera is defined by parameters such as position, look-at point, up vector, screen distance, and screen width. General settings include the background color, number of shadow rays, and maximum recursion level.
The ray tracer is implemented in Python and accepts a scene file as input. The scene file contains the definition of all surfaces, materials, light sources, camera settings, and general render settings. The code is designed to run in the command line and supports the generation of images based on the provided scene description.
The project incorporates soft shadows to simulate the effect of light sources with a certain area. The light intensity that hits the surface from the light source will be multiplied by the number of rays that hit the surface divided by the total number of rays we sent. For example, if we send 25 rays from the light source and 5 of them hit the surface at the given point, the surface will be 20% illuminated at that point. If the number of shadow rays parameter is 1 only one ray will be cast and the shadows will be hard. The sent rays should simulate a light which has a certain area. Each light is defined with a light radius
To get a local copy up and running follow these simple steps.
- clone or download the repository
- open shell in the repository folder
- verify python and pip are installed ( use
python --version
andpip --version
) - install requirements using
pip install -r requirements.txt
- copy your desired scene txt file into the folder, preferably into the input folder
now, to run the application simply type:
python Raytracer.py
with the following arguments
- An absolute / relative path to the scene text file you want to process
- An absolute / relative path to the image png you want to create
- (Optional) height - the output image height, defaults to 500
- (Optional) width - the output image width, defaults to 500
so for example
python raytracer.py "input/pool.txt", "scenes/pool200x200.png", "200", "200"
will run the ray tracer on pool.txt and output the pool200x200.png file.
The scenes are defined in text scene files with the following format. Every line in the file defines a single object in the scene, and starts with a 3 letter code that identifies the object type. After the 3 letter code a list of numeric parameters is given. The parameters can be delimited by any number of white space characters, and are parsed according to the specific order in which they appear. Empty lines are discarded, and so are lines which begin with the character ”#” which are used for remarks. The possible objects with their code and list of required parameters are given below.
- params[0,1,2] = position (x, y, z) of the camera
- params[3,4,5] = look-at position (x, y, z) of the camera
- params[6,7,8] = up vector (x, y, z) of the camera
- params[9] = screen distance from camera
- params[10] = screen width from camera
- params[0,1,2] = background color (r, g, b)
- params[3] = root number of shadow rays (N 2 rays will be shot)
- params[4] = maximum number of recursions
- params[0,1,2] = diffuse color (r, g, b)
- params[3,4,5] = specular color (r, g, b)
- params[6,7,8] = reflection color (r, g, b)
- params[9] = phong specularity coefficient (shininess)
- params[10] = transparency value between 0 and 1
- params[0,1,2] = position of the sphere center (x, y, z)
- params[3] = radius
- params[4] = material index (integer). each defined material gets an automatic material index starting from 1, 2 and so on
- params[0,1,2] = normal (x, y, z)
- params[3] = offset
- params[4] = material index
- params[0,1,2] = position of the box center (x, y, z)
- params[3] = scale of the box, length of each edge
- params[4] = material index
- params[0,1,2] = position of the light (x, y, z)
- params[3,4,5] = light color (r, g, b)
- params[6] = specular intensity
- params[7] = shadow intensity
- params[8] = light width / radius (used for soft shadows)
- Python
- pip
Distributed under the MIT License. See LICENSE.txt
for more information.
I can be reached at at my email: boazyakubov@gmail.com
- Noga Kinor for wonderful teamwork in this course
- Professor Daniel Cohen-Or for teaching this course at TAU
- Roey Eliyahu Bar-On for instructing us on the subject at TAU