NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Show HN: I wrote a C++ ray tracer from scratch without AI (github.com)
martiano 5 hours ago [-]
Hey HN,

5 years ago I was 17 and learning to code C/C++ in a coding bootcamp (42). One of the projects was a simple C ray tracer. I really enjoyed working on the project and always loved computer graphics, so I decided to create my own path tracer from scratch, in C++, without using any third-party libraries.

I ended up working on it consistently for over a year, then sporadically when CG excitement hit me again. Recently I polished it and completed some unfinished features and decided to make it public, finally. It's a C++20 Path Tracer with a CPU renderer. It is able to render good-looking images with reasonable performance and sample count.

Btw this was initially coded without AI, but I've used it for the recent clean up and features. This project is a personal favorite of mine, and it can improve a lot, so I'd love to hear your feedback.

hresvelgr 2 hours ago [-]
Great work, the examples look fantastic. I will say, it's misleading to put "without AI" in the title for you to then comment on your submission that you have in fact used it. While it may only be in a trivial capacity, you've still used it.
martiano 5 minutes ago [-]
I get your point. I consider it fair with the disclaimer because the "manual" version was very similar to current but missing some love
smartmic 2 hours ago [-]
> Btw this was initially coded without AI, but I've used it for the recent clean up and features

Then it makes sense to update the submission title. To me it reads as if the project was written completely without the help of AI (which might be a quality badge to some), but it is not 100% true then.

Anyhow, cool project ;)

pixelesque 2 hours ago [-]
JFYI: Your inverse ray direction calculation is not NaN-safe: if rays are completely axis-parallel in one dimension, so the direction value is 0.0 for that axis, you'll be doing the val / 0.0 which results in a NaN...

Also, as you're using full double/f64-precision all the time, you're leaving a fair bit of performance on the table: transcendentals (sin(), cos(), etc) in particular - can be a lot slower than when using f32, and generally double precision can be special-cased to particular areas of the renderer that need it (curve, sphere intersection, and some situations where volume scattering produces very small distances).

deliveryboyman 1 hours ago [-]
What's the proper way to handle a zero in the direction vector when calculating the reciprocal direction? Should it evaluate to infinity?
pixelesque 50 minutes ago [-]
Inverse is still 0.0 technically, but yes, there is a trick you can use with Inf and SIMD to mask them out, so Inf is sometimes used.

However, I'd just condition it for the moment.

so:

invDirX = dirX != 0.0 ? 1.0 / dirX : 0.0; etc, etc for each dimension.

Obviously doing the != 0.0 comparison is not great, as it suffers from potential issues again (especially if you have denormals), but you can generally get away with it I've found in most cases.

shinycode 2 hours ago [-]
Congrats on doing 42 and to have worked and shared your project, very nice results !
manoji 2 hours ago [-]
Hey ! Great work , I wanted to try something like this as well to begin my journey into games and computer graphics . I would love to know what resources you used to learn.
martiano 10 minutes ago [-]
The greatest resource I've found on the internet is the Ray Tracing in One Weekend series. (https://raytracing.github.io/) You can start there and go pretty far. Also you can mix random papers you'll find and eventually just testing and experimenting yourself.
pjmlp 2 hours ago [-]
Congratulations on achieving it.
ttoinou 3 hours ago [-]
Congrats ! Results look stunning
eleventen 33 minutes ago [-]
A C++ ray tracer from scratch was the course project for my computer graphics class in 2016. I enjoyed the exercise immensely. Not nearly as robust as yours of course.
Quarrel 27 minutes ago [-]
I basically was ready to come on and make a snarky comment like this. "I wrote one in the '90s!".

and then I saw the examples, and the feature set. I particularly like the blender-to-Luz export.

It seems great. Good luck to OP.

Phelinofist 25 minutes ago [-]
"Without AI" is the new "Written in Rust", SCNR
Alifatisk 1 hours ago [-]
> without AI

Now this is how you catch attention

glouwbug 59 minutes ago [-]
I expect similar headlines like “I saved on token cost by hiring juniors” to come in soon too
cultofmetatron 2 hours ago [-]
for anybody else interested in this undertaking, I recommend this book https://pragprog.com/titles/jbtracer/the-ray-tracer-challeng...
itsthecourier 10 minutes ago [-]
for the love of the game, very refreshing good ol' coding
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 14:07:45 GMT+0000 (Coordinated Universal Time) with Vercel.