C++ OpenGL 创建发光线

C++ OpenGL 创建发光线

问题描述:

我研究过,用于制作晕染效果的方法通常基于将清晰和模糊的图像结合起来以产生发光效果.但我想知道如何使 gl_lines(或任何线)具有亮度.由于在我的游戏中我随机生成了一个简单的 2D 地形,因此我希望使地形线段发光.

I have researched and the methods used to make a blooming effects are usually based on having a sharp and blurred image conjoined to give the glow effect. But I want to know how I can make gl_lines(or any line) have brightness. Since in my game I am randomly generating a simple 2D terrain, I wish to make the terrain line segments glow.

使用片段着色器计算从片段到边缘的距离,并使用适当的颜色值为片段着色.您可以使用简单的控制曲线来控制发光的半径和强度(就像在 Photoshop 中一样).它还可以调整为像线框可视化一样.这个想法是你并没有真正使用绘制调用将点光栅化为线,只是根据每个像素与相应边缘的距离着色.

Use a fragment shader to calculate the distance from a fragment to the edge and color the fragment with the appropriate color value. You can use a simple control curve to control the radius and intensity anlong of the glow(like in photoshop). It can also be tuned to act like wireframe visualization. The idea is you don't really rasterize points to lines using a draw call, just shade each pixel based on its distance from the corresponding edge.

与使用模糊通道的不同之处在于,您首先会获得更好的性能,其次 - 对发光的每像素控制,您可以获得使用模糊无法获得的非均匀发光,因为它并没有真正意识到在实际线几何中,它只是盲目地处理像素,而通过边缘距离检测,您确实使用实际几何数据作为输入,而不会将其扁平化为像素.您还可以使用渐变发光之类的东西,例如发光颜色随半径不同而变化.

The difference from using a blur pass is that you will first get better performance, and second - per-pixel control over the glow, you can have non-uniform glow which you cannot get by using blur because it is not really aware of the actual line geometry, it just blindly works on pixels, whereas with edge distance detection you do use the actual geometry data as input without flatting it down to pixels. You can also have stuff like gradient glows, e.g. the glow color is different and changes with the radius.