[Shader Library] Lens Circle Post Processing Effect (GLSL)



Shader Library - Lens Circle Post Processing Effect



More shaders are available here: Geeks3D Shader Library.

This simple shader adds a lens circle effect to the final scene image. The core of this effect is the smoothstep() function:

smoothstep(outer, inner, dist);

How this function works? If dist is greater than outer, smoothstep returns 0. If dist is lesser than inner, smoothstep returns 1. Between outer and inner, smoothstep returns an interpolated value between 0.0 and 1.0.

You can download the demo source code here:
Download PostFX_LensCircle.zip

To see the shader in real time, you need GeeXLab 0.1.12 and Python 2.6.3.

Unzip the source code somewhere, start GeeXLab and drop the file Lens_Circle_Effect_Demo.xml in GeeXLab.

Some results:

  • Core 2 Duo E8400 / Radeon HD 5770 (Cat9.10 beta) / WinXP SP2: 830 FPS (640×480) and 750 FPS (1920×1200)
  • AMD X2 3800+ / GeForce GTS 250 (fw191.07) / WinXP SP2: 644 FPS (640×480) and 620 FPS (1920×1080)

Shader desription (for NVIDIA and ATI)

Language: OpenGL 2 – GLSL

Type: Post processing filter

Inputs:

  • sceneBuffer (sampler2D): the scene buffer.
  • lensRadius (vec2): outer (default=0.45) and inner (default=0.38) radius.

Ouputs: color buffer

Shader code:

[Vertex_Shader]
void main(void)
{
  gl_Position = ftransform();
  gl_TexCoord[0] = gl_MultiTexCoord0;
}
[Pixel_Shader]
uniform sampler2D sceneTex; // 0
uniform vec2 lensRadius; // 0.45, 0.38
void main() 
{ 
  vec4 Color = texture2D(sceneTex, gl_TexCoord[0].xy);
  float dist = distance(gl_TexCoord[0].xy, vec2(0.5,0.5));
  Color.rgb *= smoothstep(lensRadius.x, lensRadius.y, dist);
  gl_FragColor = Color;
}




[ Subscribe to Geeks3D latest news by email ]

Geeks3D.com

↑ Grab this Headline Animator