Git Product home page Git Product logo

42minirt's Introduction

landing-page-gif

๐Ÿ‘‹ Hello, I'm Conrad

  • 42Heilbronn Student (Part of the 42Network)
  • Programmer
  • Gamer
  • Watching Anime
  • Always trying to learn something new

๐Ÿ“Š Github Stats

Isometric view of contributions in the last year. Language pie is based on recent commits

๐Ÿ”ง Skills:

Tech Stack:

My Skills

Tools:

My Skills

Currently Learning:

My Skills

Tech: C, C++, Docker, JavaScript, TypeScript, Vue, HTML, CSS, TailwindCSS
Tools: Github, Git, Figma, VSCode
Currently Learning: Go, Python, Django, AWS

โœ‰๏ธ Get In Touch

42minirt's People

Contributors

itseugen avatar realconrad avatar

Watchers

 avatar

Forkers

itseugen

42minirt's Issues

lighting and ambient lighting

Ambient lighting works correctly -> multiplies each ray colour with the ratio.

lighting has some issues but the idea for now is:

  1. Get hit point
  2. Get vector from hit point to light
  3. Normalize vector from hitpoint to light
  4. create a new vector from that
  5. Check if the vector hits the light or another object before that
  6. If another object is hit give it the ambient colour (for now)
    6a. If it hits the light, calculate the AMbient, the object and the light colour together
  7. Voilรก

Implement anti-aliasing

The current implementation of our ray tracing project lacks anti-aliasing, resulting in images with jagged edges and pixelation. To enhance the image quality, we need to implement a simple anti-aliasing technique. This will involve modifying our ray generation process to send multiple rays per pixel and average their colour.

Vectors are not Points!!!

viewport.pixel00_loc = vec_subtract(vec_add(viewport.pixel00_loc,
camera_vector), scene->camera.cords);

If you want a point result - like the center of a pixel. You need to add a vector to the point! if you subtract a point from a vector you are gonna get a translated vector from the provided point to the same vector's end!

Change subtract into add.

Finish parsing

  • Refactor parser to be more readable
  • Add sphere object
  • Add cylinder object
  • Add plains object

Implement plane object

Get the dot-product of the 3D orientation vector of the plane and the ray direction
d_pro = dot_product(plane->threed_vec, ray.direction);
If the absolute value of the dot product goes to near zero the ray and plane are parallel and won't hit -> no hit.

Afterwards we do:
vec_subtract(plane->cords, ray.origin)
This subtracts the origin of the ray (ray.origin) from the coordinates of the plane (plane->cords). This results in a vector pointing from the origin of the ray to a point on the plane.

dot_product(vec_subtract(...), plane->threed_vec)
This calculates the dot product between the vector obtained in step 1 and the normal vector of the plane (plane->threed_vec). The dot product is often used in geometry and physics to determine the angle between two vectors.

The result of the dot product is divided by d_pro, which is the dot product of the ray direction and the plane normal. This is part of solving an equation related to the intersection of a ray and a plane in 3D space.

The calculated value t represents the parameter of the intersection point along the ray. If t is less than 0, it means the intersection point is behind the origin of the ray, so it's not considered a valid intersection. In such cases, the function returns -1.0 to indicate no intersection.

Camera viewport

In order to draw anything, we need to calculate the ray based on the camera position and the current x, y coordinate we currently on.

In ray tracing, a viewport is a flat screen or window through which your camera looks at a 3D scene. Its where a 3D scene gets projected onto a 2D plane.

We will use the camera FOV thats provided to calculate the following:

  • Viewport height
  • Viewport width
  • Viewport vectors
  • Lower left corner vector
  • Camera direction

Some things to note:

  • The ray.origin will always be the camera coordinates
  • ray.direction will always depend which pixel coordinate we sending the ray to.

Calculations

Viewport height

Image

This is directly calculated by the FOV

Here, FOV * (pi / 180) converts the FOV from degrees to radians, since tan functions requires radians to work properly.

Why do we do tan(FOV / 2)?
It gives the ratio of half the viewports height to the distance from the camera.

Why do we multiply by 2?
After finding the tangent of half the FOV, we multiply by 2 to get the full viewport height.

Viewport width

Image

Since we already have the height of the viewport we can simply scale the width according to the aspect ratio.

Camera direction

viewport.camera_direction = normalize_vector(scene->camera.or_vect);

Here we can just normalize the camera direction (adjust the length of the vector to 1 while keeping its direction the same). We do this for calculations involving directions.

Here is how we would normalize a given vector:

  1. Take a given vector:
    Image

  2. Calculate the length of V above using:
    Image

  3. Divide each vector element by the length which will give us the normalized vector:
    Image

Viewports position

No need for calculation here, we already have everything we need, We can just store it for later calculations.

viewport.horizontal = (t_vector){vp_width, 0, 0};
viewport.vertical = (t_vector){0, vp_height, 0};

Lower left corner calculation:

This calculation gets the bottom left position of the viewport. We start at the camera position and move back and to the left based on viewport size and camera direction. We need this variable to generate rays correctly/

We can use the following formula:

  • L = Lower left corner of the viewport
  • C = Camera position vector
  • H = Horizontal vector
  • V = Vertical vector
  • D = Camera direction vector
    Image

In Code:

viewport.lower_left_corner = vec_subtract(
   vec_subtract(
      vec_subtract(scene->camera.cords, vec_divide(viewport.horizontal, (t_vector){2, 2, 2})),
      vec_divide(viewport.vertical, (t_vector){2, 2, 2})), 
   viewport.camera_direction);

void escape leaks memory

We need to make sure the escape function correctly frees the scene, we can most likely just use the exit_render function in it (copy and paste)

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.