Glittering effect

Many of you may know the famous example "Glitter" from Rendermonkey. Unfortunately it is too complicated and heavy for a mobile device and some of the prototypes do not work on GLES 2.0.

There is a clever trick anyway - we can mask the object. As a mask we use the alpha channel of the texture. This mask will not be black and white, but gradient. If this gradient is well done, it can be used for parallax mapping. There is nothing special in the vertex shader.

This is the GLSL version of the fragment shader: :

// DEFINES
#define GLITTER_MULT 2.5
#define DETAIL_MULT_1 25.0
#define DETAIL_MULT_2 15.0
#define PARALLAX_MULT 0.02

// UNIFORMS
uniform lowp sampler2D DiffuseSampler;
uniform lowp sampler2D GlitterSampler;
uniform highp vec2 GlitterOffset;

// VARYINGS
varying highp vec2 vTexCoord0;

void main()
{

lowp vec4 DiffuseColor = texture2D(DiffuseSampler, vTexCoord0);
lowp float Mask = DiffuseColor.a;

lowp vec3 GlitterColor1 = texture2D(GlitterSampler, vTexCoord0 * DETAIL_MULT_1 + GlitterOffset).rgb;
lowp float GlitterColor2 = texture2D(GlitterSampler, (vTexCoord0 + vec2(Mask, Mask) * PARALLAX_MULT) * DETAIL_MULT_2 - GlitterOffset).r;
lowp vec3 GlitterColor = GlitterColor1 * (GlitterColor2 * Mask * GLITTER_MULT);
gl_FragColor = vec4(DiffuseColor.rgb, 1.0) + vec4(GlitterColor, 0.0);
}

This is the texture that corresponds to the GlitterSampler:

If rim is used as an additional mask we add specular mapping and we get the same visible result. The difference of using this approach is that it operates tens of times faster. As further optimization we can transfer the calculations with texture coordinates in the vertex shader.

End result:

back...