如何在现代OpenGL中进行光线追踪? [英] How to do ray tracing in modern OpenGL?

查看:740
本文介绍了如何在现代OpenGL中进行光线追踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我现在应该开始点亮我平淡无奇的模特。测试应用程序是仅实现最新方法的测试案例,所以我意识到理想情况下它应该实施光线追踪(因为理论上它可能是几年内实时图形的理想之选)。

但是我该从哪里开始?



假设我从来没有在旧的OpenGL中完成光照,所以我将直接转向非弃用的方法。



该应用程序目前正确设置了顶点缓冲区对象,顶点,法线和颜色输入,并且能够以平坦的颜色正确绘制和转换空间模型。 p>

有没有一种信息来源可以从平面彩色顶点到通过GLSL获得正确结果所需的全部信息?理想情况下,可以使用任何其他额外的照明方法来补充它。

我不建议尝试实际的光线跟踪OpenGL,因为你需要很多黑客和技巧,如果你问我,那么再也没有这个意义了。
如果您想在GPU上进行光线追踪,您应该使用任何GPGPU语言,例如CUDA或OpenCL,因为它使事情变得更容易(但仍然很琐碎)。



为了进一步说明问题:
对于光线追踪,您需要追踪二次光线并测试与几何相交。因此,您需要在着色器中以某种巧妙的方式访问几何,但是在片段着色器中,如果不将其编码存储到几何纹理中,则无法访问几何。顶点着色器本身不会为您提供此几何信息,并且几何着色器仅知道邻居,所以此处已经开始出现问题。
接下来,您需要加速数据结构来获得任何合理的帧速率。然而,遍历例如着色器中的Kd-Tree是相当困难的,如果我没有记错的话,那么只有几篇论文就是关于这个问题的。
如果你真的想走这条路,那么这个主题有很多论文,找到它们不应该太难。



A射线追踪器需要非常精心设计的访问模式和缓存才能获得良好的性能。然而,你对GLSL内部的这些内部控制很少,优化性能会变得非常困难。

另外一点需要注意的是,至少据我所知,实时GPU上的光线追踪大多局限于静态场景,例如kd-trees仅适用于静态场景。如果你想拥有动态场景,你需要其他数据结构(例如BVH,iirc?),但你需要不断地维护这些。如果我没有遗漏任何东西,目前仍然有很多研究正在进行中。


So I'm at a point that I should begin lighting my flatly colored models. The test application is a test case for the implementation of only latest methods so I realized that ideally it should be implementing ray tracing (since theoretically, it might be ideal for real time graphics in a few years).

But where do I start?

Assume I have never done lighting in old OpenGL, so I would be going directly to non-deprecated methods.

The application has currently properly set up vertex buffer objects, vertex, normal and color input and it correctly draws and transforms models in space, in a flat color.

Is there a source of information that would take one from flat colored vertices to all that is needed for a proper end result via GLSL? Ideally with any other additional lighting methods that might be required to complement it.

解决方案

I would not advise to try actual ray tracing in OpenGL because you need a lot hacks and tricks for that and, if you ask me, there is not a point in doing this anymore at all. If you want to do ray tracing on GPU, you should go with any GPGPU language, such as CUDA or OpenCL because it makes things a lot easier (but still, far from trivial).

To illustrate the problem a bit further: For raytracing, you need to trace the secondary rays and test for intersection with the geometry. Therefore, you need access to the geometry in some clever way inside your shader, however inside a fragment shader, you cannot access the geometry, if you do not store it "coded" into some texture. The vertex shader also does not provide you with this geometry information natively, and geometry shaders only know the neighbors so here the trouble already starts. Next, you need acceleration data-structures to get any reasonable frame-rates. However, traversing e.g. a Kd-Tree inside a shader is quite difficult and if I recall correctly, there are several papers solely on this problem. If you really want to go this route, though, there are a lot papers on this topic, it should not be too hard to find them.

A ray tracer requires extremely well designed access patterns and caching to reach a good performance. However, you have only little control over these inside GLSL and optimizing the performance can get really tough.

Another point to note is that, at least to my knowledge, real time ray tracing on GPUs is mostly limited to static scenes because e.g. kd-trees only work (well) for static scenes. If you want to have dynamic scenes, you need other data-structures (e.g. BVHs, iirc?) but you constantly need to maintain those. If I haven't missed anything, there is still a lot of research currently going on just on this issue.

这篇关于如何在现代OpenGL中进行光线追踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆