The goal is to create a basic glow effect in OpenGL using a Shader.
Example without glow:
Example with glow:
To achieve this effect, the model is rendered twice: once by actually rendering the model and a second time by rendering a slightly bigger version that is partially transparent. A really easy method of achieving this glow is by using the Fresnel effect. The effect itself is related to the reflectivity of a surface depending on the viewing angle. We won’t model the effect realistically, but we will make use of this concept to create the glow.
Fresnel effect
The glow should be more prominent the closer to the object you are and get fainter and fainter the further away you are. Instead of using proximity to the object, we can use the angle between the viewing vector and the normal of the triangle that is being rendered. This way the glow becomes fainter when the surface of the object is less aimed at the viewer.
This effect can easily be calculated by using the dot-product of the normalized viewing vector and triangle normal (note that Face Culling is enabled in this situation, which means that triangles that are pointing away from the camera are not rendered).
Vertex Shader (not full implementation)
Fragment Shader (not full implementation)
This is the most basic implementation, but cannot yet be used in a general situation. For example, the offset is dependent on the size of the normal instead of the size of the object itself, which would make more sense.