motionblurdof.shader

00001 void main() 
00002 {
00003     // Use the first set of texture coordinates in the fragment shader 
00004     gl_TexCoord[0] = gl_MultiTexCoord0;
00005 
00006     // Transform the position to screen space
00007     gl_Position = ftransform(); 
00008 }
00009 
00010 ~~~~~
00011 
00012 uniform sampler2D Texture0;
00013 uniform sampler2D Texture1;
00014 uniform sampler2D Texture2;
00015 
00016 uniform float bias;
00017 uniform float blurclamp;
00018 uniform float motionbias;
00019 uniform float motionclamp;
00020 
00021 #define KERNEL_SIZE  4.0
00022 #define KERNEL_AREA 25.0
00023 
00024 void main() 
00025 {
00026     // Sample all the buffers
00027     vec4 depth   = texture2D( Texture1, gl_TexCoord[0].xy );
00028 
00029     // Get the focus point for the image
00030     vec4 focus = texture2D( Texture1, vec2( 0.5 ) );
00031 
00032     // Get the motion value
00033     vec4 vMotion = texture2D( Texture2, gl_TexCoord[0].xy ) * 2.0 - 1.0;
00034 
00035     // Get the blur amount
00036     float factor = ( depth.r - focus.r );
00037     float dofblur = clamp( factor * bias, -blurclamp, blurclamp );
00038     vec2 motionblur = clamp( vMotion.xy * vMotion.xy * motionbias, -motionclamp, motionclamp ) + dofblur;
00039 
00040     //blur parts which are out of focus
00041     vec4 col = vec4( 0, 0, 0, 0 );
00042     for ( float x = -KERNEL_SIZE + 1.0; x < KERNEL_SIZE; x += 1.0 )
00043     {
00044         for ( float y = -KERNEL_SIZE + 1.0; y < KERNEL_SIZE; y += 1.0 )
00045         {
00046             col += texture2D( Texture0, gl_TexCoord[0].xy + vec2( motionblur.x * x, motionblur.y * y ) );
00047         }
00048     }
00049     col /= KERNEL_AREA;
00050     
00051     gl_FragColor = col;
00052 }

Generated on Fri Mar 23 12:55:03 2007 for glsldemo by  doxygen 1.5.1-p1