简体   繁体   English

iOS上使用C或ObjC进行实时raytracer吗?

[英]C or ObjC for real-time raytracer on iOS?

I'm starting to build a real-time raytracer for iOS. 我开始为iOS构建实时raytracer。 I'm new to this raytracing thing, all I've done so far is write a rudimentary one in ObjC. 我是这个光线追踪的新手,到目前为止,我所做的只是在ObjC中编写一个基本的东西。 It seems to me that a C-based raytracer is going to be faster than one written in ObjC, but the ObjC one will be far simpler, as object hierarchies come in very handy. 在我看来,基于C的raytracer会比用ObjC编写的raytracer快,但是ObjC会更简单,因为对象层次结构非常方便。 Speed is very important, though, as I want it to be real-time, say 30 fps. 但是,速度非常重要,因为我希望它是实时的,例如30 fps。

What's your opinion on whether the speed up of C be worth the extra complexity? 您对C的加速是否值得额外的复杂性有何看法? I can forsee the C code taking much longer and causing me headaches with lots of bugs (although I'm not new to C), but going for more speed is seductive initially. 我可以预见,C代码花费的时间会更长,并且会引起很多错误(尽管我对C并不陌生),但最初追求更高的速度是诱人的。

Are there any examples out there of raytracers written in C? 有没有用C编写的光线跟踪器的示例? My google search for such things is contaminated with lots of results for C++ and C#. 我的Google搜索此类内容被C ++和C#的大量结果所污染。

If you want fast ray tracing, you can pretty much forget about using either C or Objective C. You almost certainly want to use OpenCL. 如果你想快速的光线追踪,你几乎可以忘记使用C 目的C.你几乎肯定要使用OpenCL的。 It's still not going to be enough to get you (even very close to) 30 fps, but it'll probably be at least twice as fast as anything running on the CPU (and 5-10 times faster wouldn't be any real surprise). 它仍然不足以使您(甚至非常接近)30 fps,但是它可能至少是CPU上运行的任何东西的两倍(并且快5到10倍也就不足为奇了) )。

as zneak stated, c++ is the best combination for speed and polymorphism. 正如zneak所说,c ++是速度和多态性的最佳组合。

however, you can accomplish something close by reducing the objc calls (read: reduce the polymorphic interface to the minimum set required, then just putting the parts that need to be fast in plain c or c++). 但是,您可以通过减少objc调用来完成一些工作(阅读:将多态接口减少到所需的最小集,然后将需要快速处理的部分放在纯c或c ++中)。

objc message dispatch is quite fast, and you can typically remove much of the virtual/dynamic methods from your interfaces (assume every objc instance method is virtual). objc消息调度非常快,您通常可以从接口中删除许多虚拟/动态方法(假定每个objc实例方法都是虚拟的)。 c code in objc methods is still c code... from there, determine where your bottlenecks are -- it doesn't hurt to profile before changing working code, either ;) objc方法中的c代码仍然是c代码...从那里开始,确定您的瓶颈所在-在更改工作代码之前对配置文件也无妨;)

Writing a "realtime Raytracer" is without the use of Hand-Optimized Assembly (or the use of the "cheap" Intel compiler ;) , but this is not possible for this platform), impossible because you need the speed. 编写“实时Raytracer”无需使用“手动优化程序集”(或使用“便宜的” Intel编译器;),但是在此平台上是不可能的),因为您需要速度,所以这是不可能的。

Further more you need a lot of Processing power but i guess even the OpenCL path is not powerful enought (this is in my opinion the case even for real Desktop machines, the reason for this is the lack of an real big cache on the Graphics Processor). 此外,您还需要大量的处理能力,但我想即使OpenCL路径也不够强大(我认为即使对于真正的台式机也是如此,原因是图形处理器上缺乏真正的大缓存) )。

Have a look through http://ofps.oreilly.com/titles/9780596804824/ that is as close as you'll get. 浏览一下http://ofps.oreilly.com/titles/9780596804824/ ,它与您将近距离接触。

It isn't ray tracing, I have written a ray tracer and it is a huge amount of work. 这不是光线追踪,我已经编写了光线追踪器,这是大量工作。 GL uses a different technique for graphics, hence it will be unable for example to render the capacity of a diamond to capture light. GL使用不同的图形技术,因此将无法例如渲染钻石的光捕获能力。 that link contains sample code, you can download and run it. 该链接包含示例代码,您可以下载并运行它。 You will realise that even some of the moderately complex examples really chug on an actual device... we are talking < 1 fps. 您会意识到,即使是一些中等复杂的示例也确实会在实际设备上出现……我们正在谈论<1 fps。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM