使用 CUDA VBO 进行 OpenGL 高度图绘制
我之前在这里问过几个有关 VBO 的问题,根据我收到的评论,我决定必须采取一种新方法。
简而言之 - 我正在尝试绘制在大型 FLOAT 数组上定义的 Mandelbrot 集,大约 512X512 点。我的程序的目的是让用户控制缩放和世界的方向(它是一个 3D 模型)。 到目前为止,我已经使用 GL_TRIANGLE_STRIP 绘制了整个物体,但由于其绘制过程缓慢,因此这是一个糟糕的选择。还因为实现我的绘画风格(调用 glVertex 的顺序)对于 VBO 编码变得不可能。
所以我有几个问题。
即使在这个描述之后,我也不确定 VBO 是最好的选择,因为它是由用户来控制计算的。对于他由程序引起的每个计算,我必须重新计算 mandelbrot 集(~60ms),并重新复制指向缓冲区的点:这个过程需要一些时间(?毫秒)。
该程序还允许用户在世界中移动,因此这里不进行任何计算,因此 VBO 是一个绝佳的选择。
1.绘制高度图的最佳方法是什么(当数组中的每个单元格仅保存高度时)
2.我如何将其应用于VBO并将其传输到cuda(cudaRegisterBuffer或类似的东西)
3.有没有办法区分模式并决定何时需要 VBO(无计算模式)和何时不需要(计算模式)。
I've asked several questions regarding VBO previously here and from the comments i had received i decided that a new approach must be taken.
To put it simply - I'm trying to draw the Mandelbrot set which is defined on a large FLOAT array, around 512X512 Points. the purpose of my program is to let the user control the zooming and world's orientation (it's a 3d model).
so far I've painted the entire thing using GL_TRIANGLE_STRIP which turned to be a bad choice because of its slow painting process. also because implementing my painting style (order of calling the glVertex) became impossible for coding for VBOs.
so I've got several questions.
even after this description i'm not sure either the VBO is the best choice because it's up the user to control the calculations.for each calculation that he causes by the program, i have to recompute the mandelbrot set(~60ms),and recopy the points to the buffer : a process which takes some time(?ms).
the program allows the user also to move in the world so no calculations are done here therefore VBO is an excellent choice here.
1.what's the best way to paint height map(when each cell in the array holds only the height)
2.how can i apply it on VBO and transfer it to cuda (cudaRegisterBuffer or something like that)
3.is there a way to distinguish between the mode and decide when VBOs are needed(in a no calculations mode) and when they aren't(calculations mode).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将 CUDA 数组/VBO绑定到 DirectX/OpenGL VB,则无需每帧复制 CUDA 数据(有关详细信息,请参阅 CUDA 编程指南)。将数据渲染为高度场的一种方法是使用几何着色器根据高度场发出三角形。另一种方法是使用高度字段作为视差图(参考 DirectX SDK)。我个人最喜欢的是将高度场设置为位置数组 (X/Y/Z),并使用 CUDA 仅修改 Y 值,然后使用索引缓冲区来定义构成表面的多边形。请注意,您还需要更新顶点法线,如果您想对表面进行纹理处理,您可能还需要使用 XYZ/UV。如果 512x512 太大,请使用光栅操作(纹理采样)填充感兴趣区域的较低分辨率高度场。您可以在 CUDA 或 OpenGL/DirectX 中执行此阶段(我建议在 CUDA 中执行此操作,您可以轻松编写自己的采样内核以在下采样时查找像素)。
You don't need to copy the CUDA data each frame if you bind the CUDA array/VBO to the DirectX/OpenGL VB (refer to the CUDA Programming Guide for details). One way to render data as a height-field is to use the Geometry Shader to emit the tris based on the height-field. Another way is to use the height field as a parallax-map (ref DirectX SDK). My personal fave would be to make your height-field an array of positions (X/Y/Z) and use CUDA to modify only the Y-Values, then use an index buffer to define the polygons that compose the surface. Note that you'll also need to update the vertex normals, and you may also want to use XYZ/UV if you want to texture the surface. If 512x512 is too big, use raster-ops (texture sampling) to populate a lower-resolution height-field of the region of interest. You can do this stage in CUDA or OpenGL/DirectX (I'd recommend doing it in CUDA where you can easily write your own sampling kernel to lookup pixels when down-sampling).