Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Awesome! I tried to look into building a simple raytracer many times, but the either math gets me everytime or I just didn't come across the right "raytracer for dummies" tutorials.

Any suggestions?



For many year I also tried to build a simple ray tracer. The math got me to, but in the end I was able to write different types of render engines.

What helped me:

  learn about vectors
  learn about (vector) normalization
  learn about camera models http://www.ventrella.com/Ideas/Camera/Arm_Camera.pdf
  learn about pixels (pixels are just dots without size)
  use a 3D coordinate-system that works for you (mine is: x = right, y = forward, z = up)
  start with a simple camera model (always looking forward)
  normalize all direction vectors
  place the screen of pixels 1 unit in front of the camera
  normalize the screen of pixels
  know that the center pixel is on the forward vector of the camera
  try to calculate a vector from the camera position to the left top of the pixel screen in front of the camera


The fully commented (but not entirely clean) code is here: http://www.gabrielgambetta.com/tiny_raytracer_full.js

Also, I'm halfway through writing a Computer Graphics textbook, half of it dedicated to raytracing.


I'd buy it, please post the link once its done, or if you want any proof readers or people to type in the code to check for typos I'd be happy to help.


Possibly more than you asked for, but it's great material:

http://scratchapixel.com/

(on a not-particularly-raytracing-related note, I can really recommend to anyone interested the lesson about colour spaces, first time the point of CIExy and sRGB became clear to me. also for anyone wondering why the colours in F.lux / Redshift shift the way they do, check the "blackbody radiation" chapter)




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: