Advertisement
Guest User

I Can't Escape: Darkness Indirect Lighting Shader

a guest
Jul 19th, 2014
656
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. varying vec2 vcoord; //passed from the vertex shader and is pos.xy*0.5+0.5, where pos is the vertex coordinate of the screen quad used to render the pass.
  2. uniform sampler2D color_buffer; //the back buffer (the previous pass's lighting).
  3. uniform sampler2D mask; //the conduction mask (with the conduction in the alpha channel because it is a GL_ALPHA texture).
  4. uniform vec2 radius; //vec2(1.0/mask.width, 1.0/mask.height) - the size of a single pixel
  5. void main(void){
  6.     vec4 ret = vec4(0.0); float sum = 0.0; vec2 coord = vcoord; float me = texture2D(mask,coord).a;
  7.     //left pixel (weight 2)
  8.     coord.x -= radius.x; float m = me*texture2D(mask,coord).a*2.0; sum += m; ret += m*texture2D(color_buffer,coord);
  9.     //top left pixel (weight 4)
  10.     coord.y -= radius.y; m = me*texture2D(mask,coord).a*4.0; sum += m; ret += m*texture2D(color_buffer,coord);
  11.     //bottom left pixel (weight 4)
  12.     coord.y += radius.y*2.0; m = me*texture2D(mask,coord).a*4.0; sum += m; ret += m*texture2D(color_buffer,coord);
  13.     //center pixel (weight 1)
  14.     coord.y -= radius.y; coord.x += radius.x; sum += 1.0; ret += texture2D(color_buffer,coord);
  15.     //top pixel (weight 2)
  16.     coord.y -= radius.y; m = me*texture2D(mask,coord).a*2.0; sum += m; ret += m*texture2D(color_buffer,coord);
  17.     //bottom pixel (weight 2)
  18.     coord.y += radius.y*2.0; m = me*texture2D(mask,coord).a*2.0; sum += m; ret += m*texture2D(color_buffer,coord);
  19.     //right pixel (weight 2)
  20.     coord.y -= radius.y; coord.x += radius.x; m = me*texture2D(mask,coord).a*2.0; sum += m; ret += m*texture2D(color_buffer,coord);
  21.     //top right pixel (weight 4)
  22.     coord.y -= radius.y; m = me*texture2D(mask,coord).a*4.0; sum += m; ret += m*texture2D(color_buffer,coord);
  23.     //bottom right pixel (weight 4)
  24.     coord.y += radius.y*2.0; m = me*texture2D(mask,coord).a*4.0; sum += m; ret += m*texture2D(color_buffer,coord);
  25.     sum = 1.0/sum; gl_FragColor = ret*sum;
  26. }
Advertisement
RAW Paste Data Copied
Advertisement