Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330
  2.  
  3. layout (binding = 0) uniform sampler2D u_obstacles;
  4. layout (binding = 1) uniform sampler2D u_source;
  5.  
  6. out vec4 color;
  7.  
  8. void fetchNComp(ivec2 sourcePosition, ivec2 size, int offsetX, int offsetY, float multiplier, inout vec4 color) {
  9.     int x = sourcePosition.x + offsetX;
  10.     int y = sourcePosition.y + offsetY;
  11.  
  12.     if (x >= 0 && y >= 0 && x < size.x && y < size.y) {
  13.         color = max(color, texelFetch(u_source, ivec2(x, y), 0) * multiplier);
  14.     }
  15. }
  16.  
  17. void main() {
  18.     ivec2 position = ivec2(gl_FragCoord.x, gl_FragCoord.y);
  19.     ivec2 ts = textureSize(u_source, 0);
  20.     vec4 source = texelFetch(u_source, position, 0);
  21.     color = source;
  22.  
  23.     fetchNComp(position, ts, 1, 0, 0.95, color);
  24.     fetchNComp(position, ts, 2, 0, 0.85, color);
  25.     fetchNComp(position, ts, 3, 0, 0.75, color);
  26.     fetchNComp(position, ts, 4, 0, 0.60, color);
  27.     fetchNComp(position, ts, -1, 0, 0.95, color);
  28.     fetchNComp(position, ts, -2, 0, 0.85, color);
  29.     fetchNComp(position, ts, -3, 0, 0.75, color);
  30.     fetchNComp(position, ts, -4, 0, 0.60, color);
  31.  
  32.     fetchNComp(position, ts, 0, 1, 0.95, color);
  33.     fetchNComp(position, ts, 0, 2, 0.85, color);
  34.     fetchNComp(position, ts, 0, 3, 0.75, color);
  35.     fetchNComp(position, ts, 0, 4, 0.60, color);
  36.     fetchNComp(position, ts, 0, -1, 0.95, color);
  37.     fetchNComp(position, ts, 0, -2, 0.85, color);
  38.     fetchNComp(position, ts, 0, -3, 0.75, color);
  39.     fetchNComp(position, ts, 0, -4, 0.60, color);
  40.  
  41.     float obstacle = 1 - texelFetch(u_obstacles, position, 0).a;
  42.     color = max(source, color * obstacle);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement