Paste Code
Paste Blends
Paste Images
uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;

const float blurclamp = 3.0; // max blur amount
const float bias = 0.6; //aperture - bigger values for shallower depth of field
uniform float focus; // this value comes from ReadDepth script.

void main()
{

float aspectratio = 800.0/600.0;
vec2 aspectcorrect = vec2(1.0,aspectratio);

vec4 depth1 = texture2D(bgl_DepthTexture,gl_TexCoord[0].xy );

float factor = ( depth1.x - focus );

vec2 dofblur = vec2 (clamp( factor * bias, -blurclamp, blurclamp ));


vec4 col = vec4(0.0);

col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,0.4 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.15,0.37 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,0.29 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.37,0.15 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.4,0.0 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.37,-0.15 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,-0.29 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.15,-0.37 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,-0.4 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.15,0.37 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,0.29 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.37,0.15 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.4,0.0 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.37,-0.15 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,-0.29 )*aspectcorrect) * dofblur);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.15,-0.37 )*aspectcorrect) * dofblur);

col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.15,0.37 )*aspectcorrect) * dofblur*0.9);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.37,0.15 )*aspectcorrect) * dofblur*0.9);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.37,-0.15 )*aspectcorrect) * dofblur*0.9);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.15,-0.37 )*aspectcorrect) * dofblur*0.9);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.15,0.37 )*aspectcorrect) * dofblur*0.9);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.37,0.15 )*aspectcorrect) * dofblur*0.9);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.37,-0.15 )*aspectcorrect) * dofblur*0.9);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.15,-0.37 )*aspectcorrect) * dofblur*0.9);

col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,0.29 )*aspectcorrect) * dofblur*0.7);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.4,0.0 )*aspectcorrect) * dofblur*0.7);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,-0.29 )*aspectcorrect) * dofblur*0.7);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,-0.4 )*aspectcorrect) * dofblur*0.7);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,0.29 )*aspectcorrect) * dofblur*0.7);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.4,0.0 )*aspectcorrect) * dofblur*0.7);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,-0.29 )*aspectcorrect) * dofblur*0.7);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,0.4 )*aspectcorrect) * dofblur*0.7);

col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,0.29 )*aspectcorrect) * dofblur*0.4);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.4,0.0 )*aspectcorrect) * dofblur*0.4);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,-0.29 )*aspectcorrect) * dofblur*0.4);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,-0.4 )*aspectcorrect) * dofblur*0.4);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,0.29 )*aspectcorrect) * dofblur*0.4);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.4,0.0 )*aspectcorrect) * dofblur*0.4);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,-0.29 )*aspectcorrect) * dofblur*0.4);
col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,0.4 )*aspectcorrect) * dofblur*0.4);

gl_FragColor = col/41.0;
gl_FragColor.a = 1.0;
}
  1. uniform sampler2D bgl_RenderedTexture;
  2. uniform sampler2D bgl_DepthTexture;
  3.  
  4. const float blurclamp = 3.0;  // max blur amount
  5. const float bias = 0.6; //aperture - bigger values for shallower depth of field
  6. uniform float focus;  // this value comes from ReadDepth script.
  7.  
  8. void main()
  9. {
  10.  
  11.         float aspectratio = 800.0/600.0;
  12.         vec2 aspectcorrect = vec2(1.0,aspectratio);
  13.        
  14.         vec4 depth1   = texture2D(bgl_DepthTexture,gl_TexCoord[0].xy );
  15.  
  16.         float factor = ( depth1.x - focus );
  17.          
  18.         vec2 dofblur = vec2 (clamp( factor * bias, -blurclamp, blurclamp ));
  19.  
  20.  
  21.         vec4 col = vec4(0.0);
  22.        
  23.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy);
  24.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,0.4 )*aspectcorrect) * dofblur);
  25.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.15,0.37 )*aspectcorrect) * dofblur);
  26.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,0.29 )*aspectcorrect) * dofblur);
  27.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.37,0.15 )*aspectcorrect) * dofblur);       
  28.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.4,0.0 )*aspectcorrect) * dofblur);   
  29.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.37,-0.15 )*aspectcorrect) * dofblur);       
  30.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,-0.29 )*aspectcorrect) * dofblur);       
  31.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.15,-0.37 )*aspectcorrect) * dofblur);
  32.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,-0.4 )*aspectcorrect) * dofblur); 
  33.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.15,0.37 )*aspectcorrect) * dofblur);
  34.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,0.29 )*aspectcorrect) * dofblur);
  35.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.37,0.15 )*aspectcorrect) * dofblur); 
  36.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.4,0.0 )*aspectcorrect) * dofblur); 
  37.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.37,-0.15 )*aspectcorrect) * dofblur);       
  38.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,-0.29 )*aspectcorrect) * dofblur);       
  39.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.15,-0.37 )*aspectcorrect) * dofblur);
  40.        
  41.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.15,0.37 )*aspectcorrect) * dofblur*0.9);
  42.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.37,0.15 )*aspectcorrect) * dofblur*0.9);           
  43.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.37,-0.15 )*aspectcorrect) * dofblur*0.9);           
  44.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.15,-0.37 )*aspectcorrect) * dofblur*0.9);
  45.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.15,0.37 )*aspectcorrect) * dofblur*0.9);
  46.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.37,0.15 )*aspectcorrect) * dofblur*0.9);            
  47.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.37,-0.15 )*aspectcorrect) * dofblur*0.9);   
  48.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.15,-0.37 )*aspectcorrect) * dofblur*0.9);   
  49.        
  50.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,0.29 )*aspectcorrect) * dofblur*0.7);
  51.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.4,0.0 )*aspectcorrect) * dofblur*0.7);       
  52.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,-0.29 )*aspectcorrect) * dofblur*0.7);   
  53.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,-0.4 )*aspectcorrect) * dofblur*0.7);     
  54.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,0.29 )*aspectcorrect) * dofblur*0.7);
  55.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.4,0.0 )*aspectcorrect) * dofblur*0.7);     
  56.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,-0.29 )*aspectcorrect) * dofblur*0.7);   
  57.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,0.4 )*aspectcorrect) * dofblur*0.7);
  58.                          
  59.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,0.29 )*aspectcorrect) * dofblur*0.4);
  60.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.4,0.0 )*aspectcorrect) * dofblur*0.4);       
  61.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.29,-0.29 )*aspectcorrect) * dofblur*0.4);   
  62.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,-0.4 )*aspectcorrect) * dofblur*0.4);     
  63.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,0.29 )*aspectcorrect) * dofblur*0.4);
  64.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.4,0.0 )*aspectcorrect) * dofblur*0.4);     
  65.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( -0.29,-0.29 )*aspectcorrect) * dofblur*0.4);   
  66.         col += texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy + (vec2( 0.0,0.4 )*aspectcorrect) * dofblur*0.4);       
  67.                        
  68.         gl_FragColor = col/41.0;
  69.         gl_FragColor.a = 1.0;
  70. }
  71.  
go to heaven