Skip to content

gouiferda/RTv1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RTv1 - Let there be light

Ray tracer in C

🚀 Clone and Run

cd ~/Desktop; gcl https://github.com/gouiferda/RTv1.git; cd RTv1; make run;

📝 To do

  • Minilibx functions

  • expose properly (mlx_expose_hook)

  • Functions and structures

    • vector
    • ray
    • figure (sphere,plane,cylinder,cone)
    • camera
    • light
  • Mapping the coords system (0,0,0) to screen (0,0)

  • ambiant light / intersection with ray

    • sphere
    • plane
    • cylinder
    • cone
  • diffusion: lambert diffuse model

  • specular: blinn specular model

  • Shadows

  • Moving and rotating the objects

  • Moving and rotating the camera

  • Norm & Handle errors and leaks and messages

  • Multi lights (spots)

  • Reflection

  • Extra Bonuses: Antialiasing, External files for scene description, Reflection, Transparency, Shadow according to transparency...

  • Research/learn about: ray tracing and vectors in maths

  • Do a test and understand: plane line intersection

  • cylinder/line intersection

  • cone/line intersection

  • Antialiasing

  • create YML maps parser (Read External files for scene description)

🗺 Key definitions

  • Ambiant: Color alone of the object
  • Diffuse: controls roghness/dullness of object
  • Specular: controls shinningness (noticable in : metal , marbles)
  • Specular + Diffuse: How surface responds to light
  • Indirect illumination: Light bounding off of other objects in the scene (Reflected rays)
  • Shading model: diffuse + specular reflection

Lambert: (Diffuse)

To caluclate the color we need:

  1. surface normal (intersection point - center of sphere) normalized
  2. direction to the light (light pos - intersection point) normalized
  3. do a dot product
  4. refelective color of the sphere

each rgb has from 0 to 1 color = (l.n) x light.intensity x color of figure rgb color = (L.N) x M diff x color of figure rgb L: Ray towards light direction N: normal at hit pos, M diffuse: material's diffuse coeficcient // how much the figure is absorbing light / 1 max 0 min C object: color of object Dot product should not be negative

Blinn-Phong shading model: (Specular shading)

Phong_term = (V.R)^k

V- Ray towards viewer R- Light ray reflexted direction k - Material's specular coefficient (shininess) (L: intersection to light, N normal, R referse of L : reflection, V intersection to viewer ray to point) Dot product should not be negative

Half way vector:

H = L + V H = norm (H)

Blinn term = (H.R)^k

Material:

  • Color:base color
  • Ambient: what color it reflects in ambient light
  • Diffuse: what color it reflect in diffuse light
  • Specular: what is the color of its specular hihglight

🔗 Helpful links

Ray tracing explained

Ray/Line intersection with figures/objects

Shading / Diffuse mat shading