[Shader Library] Frosted Glass Post Processing Shader (GLSL)

Article Index

3 – Frosted Glass Effect: Second GLSL shader

GeeXLab, Frosted Glass Post Processing Shader

Language: OpenGL 2 – GLSL

Type: Post processing filter.

Inputs

  • sceneTex (sampler2D): the final scene image.
  • vx_offset (float): x position of the vertical red line
  • rnd_factor (float): effect param, default value: 0.05
  • rnd_scale (float): effect param, default value: 5.1
  • v1 (vec2): effect param, default value: vec2(92.,80.)
  • v2 (vec2): effect param, default value: vec2(41.,62.)

Ouput: color buffer

[Vertex_Shader]
void main(void)
{
  gl_Position = ftransform();
  gl_TexCoord[0] = gl_MultiTexCoord0;
}

[Pixel_Shader]
uniform sampler2D sceneTex; // 0
uniform float vx_offset;
uniform float rnd_factor = 0.05;
uniform float rnd_scale = 5.1;
uniform vec2 v1 = vec2(92.,80.);
uniform vec2 v2 = vec2(41.,62.);
uniform float rt_w; // GeeXLab built-in
uniform float rt_h; // GeeXLab built-in

float rand(vec2 co)
{
  return fract(sin(dot(co.xy ,v1)) + cos(dot(co.xy ,v2)) * rnd_scale);
}

void main() 
{ 
  vec2 uv = gl_TexCoord[0].xy;
  
  vec3 tc = vec3(1.0, 0.0, 0.0);
  if (uv.x < (vx_offset-0.005))
  {
    vec2 rnd = vec2(rand(uv.xy),rand(uv.yx));  
    tc = texture2D(sceneTex, uv+rnd*rnd_factor).rgb;  
  }
  else if (uv.x>=(vx_offset+0.005))
  {
    tc = texture2D(sceneTex, uv).rgb;
  }
  
  gl_FragColor = vec4(tc, 1.0);
}

Credits
This frosted glass shader is a modified version for GeeXLab of Agnius Vasiliauskas‘s original work.

Article Index