GPU渲染到球体上 [英] GPU Render onto sphere

查看:105
本文介绍了GPU渲染到球体上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写优化的代码,该代码使用OpenGL将3D场景渲染到球体上,然后在屏幕上显示展开的球体,即生成纯反射球体的平面图.用数学术语来说,我想生成一个投影图,其中x轴是极角,y轴是方位角.

I am trying to write an optimized code that renders a 3D scene using OpenGL onto a sphere and then displays the unwrapped sphere on the screen ie producing a planar map of a purely reflective sphere. In math terms, I would like to produce a projection map where the x axis is the polar angle and y axis is the azimuth.

我正在尝试通过将相机放置在球形探测器的中心并围绕周围进行平面拍摄来做到这一点,以便用平截头体的平铺瓷砖近似球形四边形.然后,我可以将其用作纹理以应用于变形的平面补丁.

I am trying to do this by placing the camera at the center of the sphere probe and taking planar shots around so as to approximate spherical quads with planar tiles of the frustum. Then I can use this as texture to apply to a distorted planar patch.

在我看来,这是非常乏味的方法.我想知道是否有办法使用着色器或某些GPU智能方法.

Seems to me this is pretty tedious approach. I wonder if there is way to take this on using shaders or some GPU-smart method.

谢谢

S.

推荐答案

我可以给您两个解决方案.

I can give you two solutions.

第一个是制作标准的渲染到纹理",但附加了一个立方体贴图作为目标缓冲区.如果您的硬件足够新,则可以一次完成.这将为您处理HW中所有需要的数学运算,但是立方体贴图的数据重新分区不是理想的(如果出现拐角,则会产生很多失真).在大多数情况下,这应该足够了.

The first is to make a standard render-to-texture, but with a cubemap attached as the destination buffer. If your hardware is recent enough, it can be done in a single pass. This will deal with all the needed math in HW for you, but data repartition of cubemaps aren't ideal (quite a lot of distortion if the corners). In most cases, it should be enough though.

此后,将四边形渲染到屏幕上,然后在着色器中使用staightforwad球形贴图将UV坐标映射到xyz向量.硬件将为您计算要在哪个UV上获取立方体贴图的哪一侧.

After this, you render a quad to the screen, and in a shader you map your UV coordinates to xyz vectors using staightforwad spherical mapping. The HW will compute for you which side of the cubemap to take, at which UV.

第二个大致相同,但具有自定义变形和较少的硬件支持:双重抛物线.两个抛物面可能还不够,但是您可以随意对方程式进行一些修改并进行6次传递.渲染过程是相同的,但是这次您全靠自己来选择正确的纹理并计算UV.

The second is more or less the same, but with a custom deformation and less HW support : dual paraboloids. Two paraboloids may not be enough, but you are free to slightly modify the equations and make 6 passes. The rendering pass is the same, but this time you're all by yourself to choose the right texture and compute the UVs.

这篇关于GPU渲染到球体上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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