GithubHelp home page GithubHelp logo

minirt's Introduction

miniRT

A Raytracing engine written in C

Default settings

All the default configutations for debugging is inside the directory default.

Architecture

1. Command-line parser

Parses mandatory scene_file location and optional command line option such as:

./miniRT scene.rt --anti-alias=3 # anti aliasing sample count
./miniRT scene.rt --depth=5 # maximum recusion depth for ray bouncing
./miniRT scene.rt --threads=3
./miniRT scene.rt --max-distance=300 # maximum world distance (in world space unit), dont render after such distance
./miniRT scene.rt --ppm=output.ppm # switch to rendering using the ppm renderer instead of MLX42

Returns a struct s_mrt_renderer_config.

2. Scene file parser

Parses the .rt file that specify every objects, lights and camera in the scene.

Returns a struct s_mrt_scene.

3. World

Scene represents the pure logical data, the minimum data needed to describe an entity in the world space. To render the scene, all of the scene objects has to be wrapped into a world object that contains extra data to ease the rendering process.

The mrt_world_from_scene function wraps each union u_scene_entry_object inside the struct s_mrt_scene produced by the previous parser into union u_world_entry_object and store it inside a struct s_mrt_world.

In the process of creating world objects, it might need some meta-data, which is described inside the struct s_mrt_world_options.

After this process, the struct s_mrt_scene is freed but each scene object is stored inside its corresponding world object. The struct s_mrt_world is created.

4. Renderer

Reads the struct s_mrt_renderer_config produced by the command line parser to determine which renderer to use and how to render.

5. Ray creation

Shoot a ray to each pixel. Optionally, depending on the anti-aliasing sample count stated inside the struct s_mrt_renderer_config, it will shoot the amount of rays through each pixels. The precise location that the ray will be shoot to is determined by probablistic function.

6. Ray Intersection

Calculate the intersection point of a ray on an object.

7. Ray hits

Calculate the normal of the intersection point on that object.

Send a ray to each light source, see if it hits any object, determine light intensity of all the rays that did not hit any objects.

Calculate the dot product of every missed ray with a weight of the light intensity of that ray to the normal of that intersection point:

Cn = color_of_one_ray(intensity, ray_to_light, normal) = dot(intensity * ray_to_light, normal)

Color of the pixel = (sum(C1, C2, ... Cn) / n) * object_texture_color

8. Ray misses

Coloring the misses rays.

9. Transformation and rotation

4 kinds of 4x4 matrix is needed to describe different kind of vector transformation:

  1. Transformation matrix
  2. Shear matrix
  3. Scale matrix
  4. Rotation matrix

Quaternions might ease the creation of rotation matrix.

Extra

GLSL

mesh = [array of points] color vertex_shader(point, world_info) // world_info can be texture or anything

color_of_each_vertex = map(mesh, vectex_shader) // aray of colors color_of_each_pixel = interpolation(color_of_each_vertex)

color fragment_shader(color_of_one_pixel, world_info) result = map(color_of_each_pixel, fragment_shader)

minirt's People

Contributors

scaletsang avatar scarletsang avatar k-isikoglu avatar

Watchers

 avatar

Forkers

k-isikoglu

minirt's Issues

Parser bugs

  • Parsing does not parse the last line if it does not end with a newline character
  • segfault when parsing an empty file
  • error management in parser
  • Also in the world module, it needs to check if the world has an ambient light and a camera for the very least.

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.