Linux 如何为 OpenGL 的线条添加发光效果?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8293839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add glowing effect to a line for OpenGL?
提问by joi
How can I add a glowing effect to a line that I draw? I'm using OpenGL for Linux.
如何为我绘制的线条添加发光效果?我在 Linux 上使用 OpenGL。
回答by Valmond
Check this out : http://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch21.html
看看这个:http: //developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch21.html
It explains easily how to make glow effects.
它很容易地解释了如何制作发光效果。
回答by edvaldig
I too once hoped there was a very simple solution to this, but unfortunately it is a little complicated, at least for a beginner.
我也曾经希望有一个非常简单的解决方案,但不幸的是它有点复杂,至少对于初学者来说。
The way glowing effects are implemented today, regardless of API (D3D,OpenGL) is with pixel/fragment-shaders. It usually involves multiple render passes where you render your scene, then render a pass where only "glowing objects" are visible, then you apply a bloom pixelshader and compose them together.
今天实现发光效果的方式,不管 API(D3D,OpenGL)是使用像素/片段着色器。它通常涉及多个渲染过程,您在其中渲染场景,然后渲染一个只有“发光对象”可见的过程,然后应用绽放像素着色器并将它们组合在一起。
See the link provided by @Valmond for details
有关详细信息,请参阅@Valmond 提供的链接
Edit:
编辑:
It should be added that this can be achieved with deferred rendering, where normals, positions and other information like a "glow flag" is rendered to a texture, i.e. stored in different components of the texture. Then a shader will read from the textures and do lightning computations and post-processing effects in a single pass since all data it needs is available from that rendered texture.
应该补充的是,这可以通过延迟渲染来实现,其中法线、位置和其他信息(如“发光标志”)被渲染到纹理,即存储在纹理的不同组件中。然后着色器将从纹理中读取并在单次传递中进行闪电计算和后处理效果,因为它需要的所有数据都可以从渲染纹理中获得。
回答by Zappotek
Without using shaders, you might also try rendering to texture and doing a radial blur. As a starting point check out NeHe-Tutorials.
在不使用着色器的情况下,您也可以尝试渲染到纹理并进行径向模糊。作为起点,请查看NeHe-Tutorials。
回答by karlphillip
You can implement the radial blureffect described on Nehe Lesson 36. The main idea is to render the drawing to a texture, and do that N times with a small offset after each render, until the drawing is ready to be copied to the framebuffer.
您可以实现Nehe 第 36 课中描述的径向模糊效果。主要思想是将绘图渲染到纹理,并在每次渲染后以小偏移量执行 N 次,直到绘图准备好复制到帧缓冲区。
I've written a small demo that uses Qt and OpenGL. You can see the original drawing(without the blur) below:
我写了一个使用Qt 和 OpenGL的小演示。您可以在下面看到原始绘图(没有模糊):
The next image shows the drawing with the blureffect turned on:
下图显示了启用模糊效果的绘图:
I know it's not much, but it's a start.
我知道这并不多,但这是一个开始。