想要写一个光线追踪器,纠结于使用什么代数库(C++)

发布于 2024-10-11 21:06:09 字数 583 浏览 5 评论 0原文

我一直想用 C++ 编写自己的多线程实时光线追踪器,但我不想实现它附带的所有向量和矩阵逻辑。我想我应该做一些研究来找到一个好的库,但我还没有取得太大的成功......

重要的是实现速度快,最好它带有一些友好的许可。我读过 boost 有基本代数,但我找不到任何关于它的速度有多好的信息。

对于其余的,Google 给了我 Armadillo,它声称速度非常快,并将其与我没有听说过的某些其他库进行了比较。
然后我得到了 Seldon,它也声称高效且方便,尽管我无法找出它们在秤上的具体位置。
最后,我读到了有关 Eigen 的内容,我在此处搜索时也看到 StackOverflow 上提到了它。

在我大学的 CG 讲座中,他们使用 HLSL 进行代数(让学生实现/优化光线追踪器的部分),这让我思考是否可以使用 GLSL代码> 为此。同样,我不知道什么选项最有效,也不知道代数库的普遍共识是什么。我希望 SO 可以在这里帮助我,这样我就可以开始一些真正的开发:)

PS:我尝试链接到网站,但我还没有足够的代表

I've been wanting to write my own multithreaded realtime raytracer in C++, but I don't want to implement all the vector and matrix logic that comes with it. I figured I'd do some research to find a good library for this, but I haven't had much success...

It's important that the implementation is fast, and preferably that it comes with some friendly licensing. I've read that boost has basic algebra, but I couldn't find anything on how good it was regarding its speed.

For the rest, Google gave me Armadillo, which claims to be very fast, and compares itself to certain other libraries that I haven't heard of.
Then I got Seldon, which also claims to be efficient and convenient, although I couldn't find out where exactly they are on the scale.
Lastly I read about Eigen, which I've also seen mentioned here on StackOverflow while searching here.

In the CG lecture at my university, they use HLSL for the algebra (making the students implement/optimise parts of the raytracer), which got me thinking whether or not I could use GLSL for this. Again, I have no idea what option is most efficient, or what the general consensus is on algebra libraries. I was hoping SO could help me out here, so I can get started with some real development :)

PS: I tried linking to sites, but I don't have enough rep yet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

瑾兮 2024-10-18 21:06:09

我建议您编写自己的例程。当我编写光线追踪器时,我发现大多数代数都使用相同的一小部分方法。基本上,您需要的只是一个支持加法、减法等的向量类。从那里您真正需要的是点和十字。

老实说,无论如何,使用 GLSL 不会给你带来更多的东西(它们只支持点、叉和简单的向量数学,其他一切都必须手动编码)。我还建议使用 C++ 进行原型设计,然后再转向 CUDA。调试 GPU 代码相当困难,因此您可以让它在 CPU 中工作,然后重新编码以在 CUDA 中工作。

实际上,光线追踪器相当简单。让他们跑得快是很困难的。加速结构将花费您大部分时间和优化。至少对我来说是这样。

I'd recommend writing your own routines. When I wrote my raytracer, I found that most of the algebra used the same small collection of methods. Basically all you need is a vector class that supports addition, subtraction, etc. And from there all you really need is Dot and Cross.

And to be honest using GLSL isn't going to give you much more than that anyways (they only support dot, cross and simple vector math, everything else must be hand coded). I'd also recommend prototyping in C++ then moving to CUDA afterwards. It's rather difficult to debug a GPU code, so you can get it working in the CPU then recode it a bit to work in CUDA.

In reality raytracers are fairly simple. It's making them fast that is hard. It's the acceleration structures that are going to take most of your time and optimization. At least it did for me.

八巷 2024-10-18 21:06:09

你应该看看 http://ompf.org/forum/

这个论坛讨论实时光线追踪,主要是在C++。它将为您提供指导和示例源。

大多数时候,在每个周期计数时,人们并不依赖外部向量数学库:优化取决于您使用的编译器、内联、是否使用 SSE(或种类)等。

You should take look at http://ompf.org/forum/

This forum treats of realtime raytracing, mostly in C++. It will give you pointers, and sample source.

Most of the time, as every cycle count, people do not rely on external vector math libs: optimizations depend on the compiler you're using, inlining, use of SSE (or kindof) or not, etc.

旧竹 2024-10-18 21:06:09

我推荐“IlmBase”,它是 OpenEXR 包的一部分。它是编写良好的 C++,由 ILM 开发,并被专业编写和使用图形软件的人们广泛使用。

I recommend "IlmBase" that is part of the OpenEXR package. It's well-written C++, developed by ILM, and widely used by people who professionally write and use graphics software.

长亭外,古道边 2024-10-18 21:06:09

对于我的项目,我使用了 glm,也许它也适合您。

请注意,诸如 boost::ublasseldon 之类的库可能不适合您,因为它们是面向 BLAS 的(我假设您正在寻找一个良好的 3D 驱动线性代数库)。

另外,dxmath DirectX 库非常好,尽管有时很难使用,因为它是 C 兼容的风格。

For my projects I used glm, maybe it would also suit you.

Note that libraries such as boost::ublas or seldon probably won't suit you, because they're BLAS-oriented (and I assume you're looking for a good 3D-driven linear algebra library).

Also, the dxmath DirectX library is pretty good, although sometimes hard to use, because of it's C-compatible style.

千秋岁 2024-10-18 21:06:09

您可以查看 POVRAY 的源代码

You might look at the source code for POVRAY

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文