Shader programming: glow effect

Thoughts triggered by an interview question: What is the essence of the OpenGL glow effect?

A VIP reader asked: I just started trying to learn to write shaders recently. I actually didn’t understand this article very well. I would like to ask if the principle of OpenGL luminescence can be explained in layman’s terms.

Insert image description here

Today, let’s talk about it in layman’s terms, what is the essence of OpenGL’s luminous effect?

In fact, if you pay attention to the boundary of the light source, you can find that the brightness of the light changes sharply at the boundary of the light source. The brightness quickly weakens in the boundary area, but the brightness does not directly reduce to 0.

Let’s take the simplest luminous effect as an example, refer to shaderToy: https://www.shadertoy.com/view/4dGfDW
luminous effect

Insert image description here

It can be clearly seen that the brightness at the boundary of the light source weakens sharply, but the brightness does not reduce to 0, which physically gives people the feeling of crossing the boundary. This is the glowing effect.

Let’s take out the function of the luminous effect and simulate it: pow(0.06/abs(x), 2.8)

Insert image description here

It can be seen from the curve of the function that the function value decreases sharply near a certain position, and then slowly decreases to 0 after exceeding the boundary, which is basically in line with our judgment.

Insert image description here

Is this explanation simple enough? have a good weekend.

Guess you like

Origin blog.csdn.net/Kennethdroid/article/details/133243069