在 OpenGL 中渲染火焰
我想基于粒子模拟在 OpenGL 中渲染火焰效果。我有数百个粒子,它们具有位置和温度(因此具有颜色)以及所有其他属性。简单地使用 glut 渲染 solidSphere
看起来不太现实,因为粒子分布得太宽。如何根据粒子信息绘制火焰?
I want to render a fire effect in OpenGL based on a particle simulation. I have hundreds of particles which have a position and a temperature (and therefore a color) as well as with all their other properties. Simply rendering a solidSphere
using glut doesn't look very realistic, as the particles are spread too wide. How can I draw the fire based on the particles information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只是想创建逼真的火焰效果,我会使用其他答案中推荐的某种重新存在的库。但在我看来,你似乎是在追求模拟的展示。
一个值得尝试的直接解决方案可能是用广告牌(即始终面向相机的图形图像)替换您当前的球体,广告牌在中间为纯白色,并向边缘褪色为透明 - 显然根据您的粒子对图像进行定位和着色。
我认为更好的解决方案是将火焰视为一组 2D 网格,您可以在其中控制网格上每个顶点的透明度和颜色。人们可以在 OpenGL 中通过从四边形构建一个平面并使用粒子系统来计算(通过从最近的粒子进行插值)每个顶点的颜色和透明度来实现这一点。 OpenGL 将为您在顶点之间插入每个像素,并为您提供“区域中的平均粒子”的平滑图像。
If you are just trying to create a realistic fire effect I would use some kind of re-existing library as recommended in other answers. But it seems to me you that you are after a display of the simulation.
A direct solution worth trying might be replace your current spheres with billboards (i.e. graphic image that always faces toward the camera) which are solid white in the middle and fade to transparent towards the edges - obviously positioning and colouring the images according to your particles.
A better solution I feel is to approach the flame as a set of 2D Grids on which you can control the transparency and colour of each vertex on the grid. One could do this in OpenGL by constructing a plane from quads and use you particle system to calculate (via interpolation from the nearest particles you have) the colour and transparency of each vertex. OpenGL will interpolate each pixel between vertexes for you and give you a smooth looking picture of the 'average particles in the area'.
您可能想使用粒子系统来渲染火焰效果,这里有一个关于如何做到这一点的 NeHe 教程:http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=19
You probably want to use a particle system to render a fire effect, here's a NeHe tutorial on how to do just that: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=19