Skip to content

yzeybek/miniRT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

This project has been created as part of the 42 curriculum by yzeybek, ibayandu.

miniRT

Description

Project Goal 🎯

The goal of this project is building a minimal version of ray tracing engine. This engine, allows to rendering realistic computer-generated images from a simply formatted file. Also dealing with computer graphics world, develops learner in mathematical face of coding. Along with the already known concepts like; parsing, high scale project developing and necessary limitation chooses, project introduce; ray tracing pipeline, illumination types and geometry based rendering.

Geometry based rendering is one of the approaches that used in intersection process in rendering pipeline. Which is also better option to choose over physical based rendering for keeping minimal approach that subject recommends. End of the they we can say, also this project purposes to teach what actually different ways to implement graphical rendering and where to choose what and why...

Especially of usage mlx library that provided by 42 offical repository and allowance to other explicit libraries, aims to reach a project that almost industry standart ray tracing engine. Keeping these implementations with Norm V4 rules, helps to keeping structure clean despite the large scale project.

Project Overview πŸ”

General structure of this project shapes around of general C projects structure and parser/renderer logic at the core of engine. Here is the folders and what they used for:

β”œβ”€β”€ .
β”œβ”€β”€ ..
β”œβ”€β”€ build                   # *.o files that comes from *.c compilation
β”œβ”€β”€ incs                    # *.h files that has prototypes or structures for sources
β”œβ”€β”€ libs                    # lib* folders that used in this project
β”‚   β”œβ”€β”€ libft               # Library that has useful Libc function implementations
β”‚   β”œβ”€β”€ libgnl              # Library that has file reading operations
β”‚   β”œβ”€β”€ libmem              # Library that has mini implementation of garbage collector
β”‚   β”œβ”€β”€ libvec              # Library that has vector math operations
β”‚   └── (minilibx-linux)    # Library that has mini implementatio of X Window functions (called by make)
β”œβ”€β”€ scenes                  # Example scene files
β”œβ”€β”€ srcs                    # Actual C files runs engine
β”‚   β”œβ”€β”€ parser              # Parser logic that parses .rt files
β”‚   β”‚   β”œβ”€β”€ parse_funcs     # Explicit functions that parse spesific identifiers
β”‚   β”‚   └── ...             # Other parser helper files
β”‚   β”œβ”€β”€ render              # Renderer logic that renders given scene
β”‚   β”‚   └── ...             # Source files for rendering
β”‚   └── ...                 # Other mainly used files
└── ...                     # Folder root files (Makefile and README.md)

After sharing this general structure, we can proceed with parser logic. Which uses pretty simple line parsing algorithm. Since the given .rt files has the structure of [identifier][properties] with each line of file, this choose is pretty efficient. Some of the identifier are must to have because of they are explicitly defines scene abilities:

  • "A" For Ambient Lightning
  • "C" For Camera
  • "L" For Mandatory Light

And here is the ones that not necessary to define but our RT can render:

  • "l" For Bonus Light
  • "pl" For Plane Shape
  • "sp" For Sphere Shape
  • "cn" For Cone Shape
  • "cy" For Cylinder Shape
  • "#" For Commenting

Each identifier has properties for required when rendering that object. These properties are not be included in here for incresing text. Anyone that wonders can checkout scenes and rendering logic. Better to talk about how ray tracing engine works after all these parsing ends...

Ray tracer, simply creates a ray from camera to each pixel onto screen. Then traces that lines if they are hits a shape and light. If there is a hit, it runs hit shader. If there is not hit, it runs miss shader. Miss shader simply returns black color for representing background. On the other hand, the hit shader does actual job. All the phong illumination and shadowing logic handles by that. For better understanding this loop here is an representative image that taken from actual nvidia's Ray Tracing pipeline:

graph LR
    %% Nodes
    Start([TraceRay Called])

    subgraph Traversal_Loop [Traversal Loop]
        direction LR
        Acc[Acceleration Traversal]
        Int[Intersection Shader]
        CheckClosest{Closest<br/>Hit?}
        CheckOp{Is<br/>Opaque?}
        AnyHit[Any-Hit Shader]
        Update[Update Closest<br/>Hit Data]
    end

    CheckHit{Have<br/>Hit?}

    subgraph Ray_Shading [Ray Shading]
        direction TB
        ClosestShader[Closest-Hit Shader]
        MissShader[Miss Shader]
    end

    End([Return from TraceRay])

    %% Connections
    Start --> Acc
    Acc --> Int
    Int --> CheckClosest

    %% Loop Logic
    CheckClosest -- No/Not Closest --> Acc
    CheckClosest -- Yes --> CheckOp

    CheckOp -- Yes --> AnyHit
    CheckOp -- No --> Update

    AnyHit -- Ignore hit --> Acc
    AnyHit -- Accept hit --> Update

    Update --> Acc

    %% Exit Loop
    Acc -- No potential hits --> CheckHit

    CheckHit -- Yes --> ClosestShader
    CheckHit -- No --> MissShader

    ClosestShader --> End
    MissShader --> End

    %% Styling (Optional - for dark mode compatibility default usually works best)
    style Traversal_Loop fill:#e1f5fe,stroke:#01579b,color:#000
    style Ray_Shading fill:#ffe0b2,stroke:#e65100,color:#000
Loading

Finally, rendering process ends with putting colored image into window. Both image putting and (previously) window creating operations are handled via minilibx-linux library that provided by 42 offical repository. This library allows to run X window calls with simplified version. Since the talking about this library won't end, here is the offical repo for who wants to examine.

Instructions

Installation ⬇️

This project is publicly available on yzeybek's github repository that named as miniRT. So simply clonning that repository via https is pretty enough for installation. Here is example command:

git clone https://github.com/yzeybek/miniRT.git

Compilation πŸ§‘β€πŸ’»

Our project uses Makefile for handling all compilation process. Which allows to compile all code with simple make command on project directory. The Makefile compiles every existing source files all together along with the libraries. But since the minilibx-linux library may not include on libs directory, it also clones via offical repository.

Note

Since the compilation has been strictly modified for 42 campus computers, there can be errors on other > environments. Here is some consideration:

  • The campus computers are Linux, so can be error occur on MacOS's.
  • The campus computers are using clang as link of cc. For changing the compiler, update the Makefile or change the cc command link.
  • The compilation process uses default optimization provided by compiler because of not explicitly allowed on Norm V4. So it might be better to compile with -O3 flag for faster rendering.

Execution βš™οΈ

Project executable (miniRT file) requires a file that ends with .rt extension. So here is an example call:

./miniRT scenes/stickman.rt

After this execution, engine will render after a while that changes by given file size. Ends of the rendering process, window can cleanly closable from close button or ESC click on keyboard.

Resources

Usage Of Sources πŸ“‹

  1. If need to start from scratch. (other episodes watchable if more needed)

  2. Mathematical Background of RT.

  3. Quick recap of RT journey.

  4. Actual guide on process.

  5. Genius guy making genius stuff.

  6. Books that highly recommended.

  7. Worth to read for better understanment.

  8. Nice coding introduction to phong lighting.

  9. Almost offical document for geometrical rendering.

  10. The guy that makes ShaderToy and stuff.

Usage Of AI's πŸ€–

We carried about avoiding usage of vibe coding tools on creation process of this project. Which allows us to actually showing our development skills. On the other hand, we got some help from AI chatting tools for:

  • Understanding complex math implementations
  • Planning our pipeline or project structure
  • Resource finding as quick search of internet.

End of the day, we were carreful about using AI as a tool instead of letting it to do the all job of us. Which is prevents to AI, use we as a tool for developing this project :)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors