Live data from Hacker News

Show HN: I wrote a C++ ray tracer from scratch without AI

github.com

41–50 of 67 posts

Re: Show HN: I wrote a C++ ray tracer from scratch without AI

#41

Earlier quoted context omitted.

> Also, as you're using full double/f64-precision all the time, you're leaving a fair bit of performance on the table There's another issue that popped up on my quick naive profiling run: std::shared_ptr in the HitRecord/HittableLightSample is assigned/copied and destroyed a lot, and somehow these refcount operations show up as half of all samples on my profile (presumably because even if there's no hit and the point…

Yeah, passing std::shared_ptr by value in a multi-threaded setup can have a lot over overhead due to them being copied and destroyed a lot, and the fact that the atomic ref count value modifications effectively cause a write back to cache and can cause contention. Should pass them by const refs really to avoid this.

Or for a better alternative, just use plain old indices rather than shared pointers.

The scene is only going to be loaded / unloaded all at once, you can just load the data into contiguous arrays and index from them. No need to use shared_ptr since lifetimes aren't that complex.

Re: Show HN: I wrote a C++ ray tracer from scratch without AI

#43
This is (or at least used to be) a right of passage in the graphics world.

I think many people go through the very popular https://raytracing.github.io/

There was a big influx of this when Sebastian Lague did his video series on building a ray tracer.

Re: Show HN: I wrote a C++ ray tracer from scratch without AI

#44

This is (or at least used to be) a right of passage in the graphics world. I think many people go through the very popular https://raytracing.github.io/ There was a big influx of this when Sebastian Lague did his video series on building a ray tracer.

And if you've decided you want to take it a bit more seriously, move on to:

https://www.pbrt.org/

which is effectively the bible, and has been for years (I wrote mine and moved into the VFX industry when the Second edition was still out! - I feel old now)

Re: Show HN: I wrote a C++ ray tracer from scratch without AI

#45

_" Btw this was initially coded without AI, but I've used it for the recent clean up and features. "_ ???

To be fair, the title is "I wrote a C++ ray tracer from scratch without AI", not "This C++ ray tracer, right now, contains no AI-written code"

It sounds to me like there is some point in this project's history when both of the following were true:

1) It was a C++ raytracer

2) It was entirely human-written

So technically there is no lie here.

Re: Show HN: I wrote a C++ ray tracer from scratch without AI

#46
post #37

_" Btw this was initially coded without AI, but I've used it for the recent clean up and features. "_ ???

Wow, I also wrote a game 8 years ago and have been using AI to rebuild upon it. I'm excited to tell people that I wrote it from scratch without AI! Love these new rules!

Look at the commit history.

Out of 557 total commits in the repo, 510 have been done before the past 2 weeks. All those (minus 5 in 2023-2024) have been done on or before July 2022, months before ChatGPT had even launched.

Out of the 47 commits in the last 2 weeks, 26 were README updates / CI / docs. The remaining 21 commits are clearly cleanups, speedups, bugfixes, and tangential features like Blender import/export. Which leaves us with 505/557 commits (90%) if we're not generous --or 531/557 commits (95%) in the best case-- of non-AI commits to the repo.

OP clearly wrote most of the project by hand and has just been cleaning things up for public release the last couple weeks. Exactly as he disclosed in his comment.

Re: Show HN: I wrote a C++ ray tracer from scratch without AI

#47

Earlier quoted context omitted.

Yeah, passing std::shared_ptr by value in a multi-threaded setup can have a lot over overhead due to them being copied and destroyed a lot, and the fact that the atomic ref count value modifications effectively cause a write back to cache and can cause contention. Should pass them by const refs really to avoid this.

Or for a better alternative, just use plain old indices rather than shared pointers. The scene is only going to be loaded / unloaded all at once, you can just load the data into contiguous arrays and index from them. No need to use shared_ptr since lifetimes aren't that complex.

Or just raw pointers, indeed.

std::shared_ptrs can also (because they're implicitly for sharing) alias, so the compiler has to assume the worst and emit loads in other cases, and there's no way (unless a newer C++ version has introduced it and I haven't noticed?) to use '__restrict__' with shared ptrs.

Re: Show HN: I wrote a C++ ray tracer from scratch without AI

#49
post #37

Earlier quoted context omitted.

Wow, I also wrote a game 8 years ago and have been using AI to rebuild upon it. I'm excited to tell people that I wrote it from scratch without AI! Love these new rules!

Look at the commit history. Out of 557 total commits in the repo, 510 have been done before the past 2 weeks. All those (minus 5 in 2023-2024) have been done on or before July 2022, months before ChatGPT had even launched. Out of the 47 commits in the last 2 weeks, 26 were README updates / CI / docs. The remaining 21 commits are clearly cleanups, speedups, bugfixes, and tangential features like Blender import/export.…

I also wrote a huge chunk of my game by hand 8 years ago, but I wouldn't lead with 'it's built without AI' now because that would be disingenuous.
Post reply on HN