Wednesday, June 9, 2010

Frosted glass Pixel Shader

We can get frosted glass effect by shifting pixel location with pseudo-random vector, such as after shift respective pattern emerges. Frosted glass GLSL pixel shader code:

uniform sampler2D tex;

float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(92.,80.))) +
cos(dot(co.xy ,vec2(41.,62.))) * 5.1);

void main()
vec2 rnd = vec2(rand(gl_TexCoord[0].xy),rand(gl_TexCoord[0].xy));
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy+rnd*0.05);

Original image

and processed with frosted glass filter

1 comment:

  1. Great1 A perfect and lovely photo regarding on showing the advantage and purpose of frosted glass. hope to see more info about it. Thank you!


Comment will be posted after comment moderation.
Thank you for your appreciation.