Skip to content

Basic Ray Tracing program - created as part of the TAU Graphics course

License

Notifications You must be signed in to change notification settings

Boazius/TAU-Graphics-Ex2-RayTracing

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Ray Tracing Exercise

Basic ray tracer with Spheres, Cubes and planes - created as part of the TAU Graphics course
Report Bug · Request Feature

About The Project

Logo

Originally on https://github.com/nogakinor/RayTracing

Basic Ray Tracer

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.

Logo

Features

The ray tracer includes the following features:

Surfaces

  • Spheres
  • Infinite planes
  • Cubes

Materials

Each surface is associated with a specific material that includes attributes such as:

  • Diffuse color
  • Specular color
  • Phong specularity coefficient
  • Reflection color
  • Transparency

Lights

The scene is illuminated by point lights, each with attributes including position, color, specular intensity, shadow intensity, and light radius.

Camera and General Settings

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.

Implementation Details

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.

Soft Shadows

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

Built With

Python

(back to top)

Getting Started

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 and pip --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

  1. An absolute / relative path to the scene text file you want to process
  2. An absolute / relative path to the image png you want to create
  3. (Optional) height - the output image height, defaults to 500
  4. (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 Scene text 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.

"cam" = camera settings (there will be only one per scene file)

  • 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

"set" = general settings for the scene (once per scene file)

  • 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

"mtl" = defines a new material

  • 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

"sph" = defines a new sphere

  • 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

"pln" = defines a new plane

  • params[0,1,2] = normal (x, y, z)
  • params[3] = offset
  • params[4] = material index

"box" = defines a new box

  • 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

"lgt" = defines a new light

  • 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)

(back to top)

Prerequisites

  • Python
  • pip

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

I can be reached at at my email: boazyakubov@gmail.com

(back to top)

Acknowledgments

  • 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

(back to top)

About

Basic Ray Tracing program - created as part of the TAU Graphics course

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages