{"id":13460300,"url":"https://github.com/eljommys/miniRT-for-Linux","last_synced_at":"2025-03-24T18:33:27.771Z","repository":{"id":115337917,"uuid":"301069459","full_name":"eljommys/miniRT-for-Linux","owner":"eljommys","description":"An easy way to understand the basics of raytracing and raymarching","archived":false,"fork":false,"pushed_at":"2021-08-24T17:54:39.000Z","size":2530,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T06:33:25.322Z","etag":null,"topics":["42","42born2code","42madrid","42projects","42school","linux","minirt","raymarching","raytracing"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eljommys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-04T07:44:24.000Z","updated_at":"2023-11-15T22:48:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"3bf840ea-fd6e-44e4-850a-ec4e2c35387d","html_url":"https://github.com/eljommys/miniRT-for-Linux","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eljommys%2FminiRT-for-Linux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eljommys%2FminiRT-for-Linux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eljommys%2FminiRT-for-Linux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eljommys%2FminiRT-for-Linux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eljommys","download_url":"https://codeload.github.com/eljommys/miniRT-for-Linux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245328529,"owners_count":20597441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["42","42born2code","42madrid","42projects","42school","linux","minirt","raymarching","raytracing"],"created_at":"2024-07-31T10:00:38.940Z","updated_at":"2025-03-24T18:33:27.393Z","avatar_url":"https://github.com/eljommys.png","language":"C","funding_links":[],"categories":["WELCOME"],"sub_categories":["**Minirt**"],"readme":"# miniRT-for-Linux\n\nminiRT-for-Linux is a 42 Programming School project that will help us to understand how raytracing and raymarching works in terms of primitive 3D objects. In several extra features are also developed (you can move the camera with the keyboard and mouse and the box element is added).\n\n[![jaeskim's 42Project Score](https://badge42.herokuapp.com/api/project/jserrano/miniRT)](https://github.com/JaeSeoKim/badge42)\n\n## Installation\n\n```bash\nsudo apt-get install gcc make xorg libxext-dev libbsd-dev\nsudo cp minilibx-linux-master/libmlx.a /usr/local/lib\nsudo cp minilibx-linux-master/mlx.h /usr/local/include\nmake\n./miniRT default.rt\n```\n\n## Default scene\nThis is the default.rt scene:\n\n![Preview](preview.png)\n\n## How to use it\n\nAt the start of the program it will be in preview mode which is just processing 1 of 8 pixels.\n\nIf you want to make a render it will be saved in the same folder as \"screenshot.bmp\" (don't worry if you can't open the file, just change its permissions by executing \"sudo chmod 666 sreenshot.bmp\").\n\nTo control the camera angle and position use W, A, S, D and move the mouse while clicking in the window.\nUse V to change between cameras and right click to reset them.\n\n## How does it work\n\nIn case you're wondering how this thing works which is very common. I suggest you to search for \"raymarching\" and \"sdf of an object\".\nI'll explain it a little bit anyway.\n\nYou have your camera in a 3D space so each pixel is a point in the space. In order to know which color you have to draw per pixel you have to send that point with the correct direction.\n\n### Vector of the ray\nThis direction is determined by a vector that can be computed by simply\n```c\n//This is pseudocode so don't take it literal.\n//We divide it by its module to normalize it because we're gonna displace it a certain distance.\nv = orientation Vector\nO = Origin of the camera\nP = Point that represent the pixel\nv = (O - P) / sqrt(O - P);\n```\n\n### Distance which displace the point\nThe distance you have to move the point in each loop is just the distance to the nearest object.\nFor example the distance from a point to a sphere is just\n```c\n//This is pseudocode so don't take it literal.\nd = Distance to a sphere\nP = Point\nS = Centre of the sphere\nr = Radius of the sphere\nd = sqrt(P - S) - r;\n```\n\nYou'll have to search a lot or be very witty to find the formulas of the asked primitives. You could also look at it in the dist/ folder but that would be cheating.\n\n### Apply ambient light\nOnce we know the ray (the displaced point) has hit with an object (it's hit if d \u003c 0.01 for example) we get the color of the hit object and do this operation.\n\n```c\n//No need to say that you have to do this for every Red, Blue and Green channel.\nrgb = Final rgb color\namb = Ambient rgb light\nobj = Object rgb color\nrgb = amb / 255 * obj\n```\n\n### Bounce ray\nTo know how different light sources affect the color of the object we just have to create another ray from the hit point to the light source. Using the same tecnique before you are know able to know if this ray hits an object or reaches the light source. If it hits an object you don't have to do anything, else you have to compute how this light source affects the color.\n\n```c\n//The intensity descends with the square of the distance\nrgb = Final rgb color\npnt = Point rgb color\nlgt = Light rgb color\nd = distance from the hit point to the light source\nrgb = rgb + lgt / d^2\n```\n### Some reference\nHere are some reference links that you might find useful.\n\n[Ray Marching for Dummies!](https://www.youtube.com/watch?v=PGtv-dBi2wE\u0026t=606s)\n\n[Distance functions or SDF](https://iquilezles.org/www/articles/distfunctions/distfunctions.htm)\n\n[SDF of a box](https://www.youtube.com/watch?v=62-pRVZuS5c\u0026t=344s)\n\n[Path-tracing](https://www.youtube.com/watch?v=1HYhrx9bzP8)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feljommys%2FminiRT-for-Linux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feljommys%2FminiRT-for-Linux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feljommys%2FminiRT-for-Linux/lists"}