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

#define PI 3.14159265

const float blurclamp = 0.03; // max blur amount
const float bias = 0.1; //aperture - bigger values for shallower depth of field

const float treshold = 0.7; // highlight treshold
const float brightness = 2.0; // highlight brightness
const float saturation = 6.0; // highlight saturation
const float contrast = 6.0; // highlight contrast

const int samples = 6; //samples on the first ring
const int rings = 8; //ring count

uniform float focus; //focus value (0.0-1.0)

vec4 sample(vec2 coo,float d) //processing the sample
{
vec3 col;

// with chromatic aberration

col.r = texture2D(bgl_RenderedTexture, coo - vec2(-0.04,-0.04)*d).r;
col.g = texture2D(bgl_RenderedTexture, coo - vec2(0.04,-0.04)*d).g;
col.b = texture2D(bgl_RenderedTexture, coo - vec2(0.0,0.04)*d).b;

// without chromatic aberration

//col.r = texture2D(bgl_RenderedTexture, coo).r;
//col.g = texture2D(bgl_RenderedTexture, coo).g;
//col.b = texture2D(bgl_RenderedTexture, coo).b;

// processing bokeh highlight treshold, brightness, contrast and saturation

float AvgLumR = 0.5;
float AvgLumG = 0.5;
float AvgLumB = 0.5;

vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);

vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
vec3 brtColor = col * brightness;
vec3 intensity = vec3(dot(brtColor, LumCoeff));
vec3 satColor = mix(intensity, brtColor, saturation);
vec3 conColor = mix(AvgLumin, satColor, contrast);

float tresh = max(((col.r+col.g+col.b)*0.33)-treshold, 0.0);

float brightamount = clamp(d * 30, 0.0, 1.0);

//return vec4(col + (conColor*brightamount),1.0);
return vec4(col+(conColor*tresh)*brightamount,1.0);
//return vec4(col,1.0);
}

void main()
{
//getting blur amount for depth of field
vec4 depth1 = texture2D(bgl_DepthTexture,gl_TexCoord[0].xy);
float factor = (depth1.x - focus);
vec2 blur = vec2 (clamp(factor * bias, -blurclamp, blurclamp));

vec4 col;
float s;

col += sample(gl_TexCoord[0].xy,blur); //middle sample

// processing circles of samples

for (int i = 0 ; i < rings; i += 1)
{
for (int j = 0 ; j < (samples*i); j += 1)
{
float step = PI*2.0 / (samples*i);
float x = cos(j*step)*i*0.1;
float y = sin(j*step)*i*0.1;

col += sample(gl_TexCoord[0].xy + vec2(blur.x*x, blur.y*y),blur.x);
s += 1.0;
}
}


col = col/s;

gl_FragColor.rgb = col;
gl_FragColor.a = 1.0;
}
  1. uniform sampler2D bgl_RenderedTexture;
  2. uniform sampler2D bgl_DepthTexture;
  3.  
  4. #define PI    3.14159265
  5.  
  6. const float blurclamp = 0.03; // max blur amount
  7. const float bias = 0.1; //aperture - bigger values for shallower depth of field
  8.  
  9. const float treshold = 0.7; // highlight treshold
  10. const float brightness = 2.0; // highlight brightness
  11. const float saturation = 6.0; // highlight saturation
  12. const float contrast = 6.0; // highlight contrast
  13.  
  14. const int samples = 6; //samples on the first ring
  15. const int rings = 8; //ring count
  16.  
  17. uniform float focus; //focus value (0.0-1.0)
  18.  
  19. vec4 sample(vec2 coo,float d) //processing the sample
  20. {
  21.         vec3 col;
  22.        
  23.         // with chromatic aberration
  24.        
  25.         col.r = texture2D(bgl_RenderedTexture, coo - vec2(-0.04,-0.04)*d).r;
  26.         col.g = texture2D(bgl_RenderedTexture, coo - vec2(0.04,-0.04)*d).g;
  27.         col.b = texture2D(bgl_RenderedTexture, coo - vec2(0.0,0.04)*d).b;
  28.        
  29.         // without chromatic aberration
  30.        
  31.         //col.r = texture2D(bgl_RenderedTexture, coo).r;
  32.         //col.g = texture2D(bgl_RenderedTexture, coo).g;
  33.         //col.b = texture2D(bgl_RenderedTexture, coo).b;
  34.  
  35.         // processing bokeh highlight treshold, brightness, contrast and saturation
  36.        
  37.         float AvgLumR = 0.5;
  38.         float AvgLumG = 0.5;
  39.         float AvgLumB = 0.5;
  40.        
  41.         vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
  42.        
  43.         vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
  44.         vec3 brtColor = col * brightness;
  45.         vec3 intensity = vec3(dot(brtColor, LumCoeff));
  46.         vec3 satColor = mix(intensity, brtColor, saturation);
  47.         vec3 conColor = mix(AvgLumin, satColor, contrast);
  48.        
  49.         float tresh = max(((col.r+col.g+col.b)*0.33)-treshold, 0.0);
  50.                        
  51.         float brightamount = clamp(d * 30, 0.0, 1.0);
  52.        
  53.         //return vec4(col + (conColor*brightamount),1.0);
  54.         return vec4(col+(conColor*tresh)*brightamount,1.0);
  55.         //return vec4(col,1.0);
  56. }
  57.  
  58. void main()
  59. {
  60.         //getting blur amount for depth of field
  61.         vec4 depth1 = texture2D(bgl_DepthTexture,gl_TexCoord[0].xy);
  62.         float factor = (depth1.x - focus);
  63.         vec2 blur = vec2 (clamp(factor * bias, -blurclamp, blurclamp));
  64.        
  65.         vec4 col;
  66.         float s;
  67.        
  68.         col += sample(gl_TexCoord[0].xy,blur); //middle sample
  69.        
  70.         // processing circles of samples
  71.        
  72.         for (int i = 0 ; i < rings; i += 1)
  73.         {
  74.                 for (int j = 0 ; j < (samples*i); j += 1)
  75.                 {
  76.                         float step = PI*2.0 / (samples*i);
  77.                         float x = cos(j*step)*i*0.1;
  78.                         float y = sin(j*step)*i*0.1;
  79.                
  80.                         col += sample(gl_TexCoord[0].xy + vec2(blur.x*x, blur.y*y),blur.x);
  81.                         s += 1.0;
  82.                 }
  83.         }
  84.        
  85.        
  86.         col = col/s;
  87.                
  88.         gl_FragColor.rgb = col;
  89.         gl_FragColor.a = 1.0;
  90. }
go to heaven