Git Product home page Git Product logo

42_rt2's Introduction

Raytracer in C

Final Hive project

Task:

Create a 3d graphics renderer to simulate light (raytracer) in C from a scene description file. A minimum of 4 shapes are required, all which should be able to be translated, rotated and scaled. Multiple light sources are needed, and their position, brightness, colour and shininess should be able to be adjusted in the scene file.

Prerequisites

Clang for OSX (the project also requires the MLX library, but that can be found inside the repository. This unfortunately does not current work with Linux).

Building

git clone https://github.com/teemu-hakala/RT.git RT
cd RT
make

Running

To run provide the scene file path as an argument to the executable. (See above to build executable).
Scene files can be found in the scenes folder. eg :

./RT scenes/bonuses/composed_elem.json

Description

This raytracer was created with the help of "The Raytracer Challenge" book by James Buick.

All objects are unit objects, meaning their radius or side has a starting size of 1 unit, and are their origin is found at the world origin. Instead of changing an objects origin, each object has a transformation matrix, which holds the rotation, translation and scale inputed from the scene file. The inverse of this matrix is applied to the ray, in order to calculate the objects relative position in the 'world'.

The Phong reflection model is used to simulate the reflection of light from the object's surface, allowing it to appear 3D.

Reflection and refraction cast secondary rays each time an object that is reflective/transparent is hit. The additional rays are limited in the code to a maximum of 5. Schlick's approximation is used to approximate the Fresnel effect on transparent surfaces.

Textures are parsed from ppm type p3 files. Any image can be converted into a ppm3 file using ImageMagick's convert tool.

Features

  • JSON parsed scene descriptions
  • Ambient light
  • Parallel light
  • Reflection
  • Transparency
  • Refraction
  • Patterns:
    • can be scaled, rotated, shifted
  • Textures:
    • parsed with ppm3 files
    • can be applied to all objects with UV mapping
    • can be scaled, rotated, shifted
  • Normal disruption
  • Soft shadows
  • Composed elementes: cubes, made from 6 limited planes
  • Multithreading
  • Colour filters
  • Screenshots of rendered images from inside the project
    • saved as ppm6 files
  • Loading progress bar
  • Live interaction with the scene
    • first person camera
  • Skybox
  • Makefile to run all the available scenes

What's next?

If given more time, additional features could include:

  • anti-aliasing
  • perlin noise
  • simplex noise
  • negative objects
  • bump mapping
  • textures used to modify objects transparency
  • groups

Known issues

  • ambient light not working when value is 0.
  • soft shadows interfere with the edges of objects with a high refractive index.

Images

glass_sphere_with_airbubble

4_textured_objects

composed_element_different_textures

earth

reflection_refraction_transparency

interface

normal_disruption

โญ Credits

Jamis Buick The Ray Tracer Challenge

42_rt2's People

Contributors

deelliot avatar teemu-hakala avatar joakim-raivio avatar nootech avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.