Bez popisu

sharpen.comp 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (local_size_x = 16, local_size_y = 16) in;
  5. layout (binding = 0, rgba8) uniform readonly image2D inputImage;
  6. layout (binding = 1, rgba8) uniform image2D resultImage;
  7. float conv(in float[9] kernel, in float[9] data, in float denom, in float offset)
  8. {
  9. float res = 0.0;
  10. for (int i=0; i<9; ++i)
  11. {
  12. res += kernel[i] * data[i];
  13. }
  14. return clamp(res/denom + offset, 0.0, 1.0);
  15. }
  16. struct ImageData
  17. {
  18. float r[9];
  19. float g[9];
  20. float b[9];
  21. } imageData;
  22. void main()
  23. {
  24. // Fetch neighbouring texels
  25. int n = -1;
  26. for (int i=-1; i<2; ++i)
  27. {
  28. for(int j=-1; j<2; ++j)
  29. {
  30. n++;
  31. vec3 rgb = imageLoad(inputImage, ivec2(gl_GlobalInvocationID.x + i, gl_GlobalInvocationID.y + j)).rgb;
  32. imageData.r[n] = rgb.r;
  33. imageData.g[n] = rgb.g;
  34. imageData.b[n] = rgb.b;
  35. }
  36. }
  37. float[9] kernel;
  38. kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0;
  39. kernel[3] = -1.0; kernel[4] = 9.0; kernel[5] = -1.0;
  40. kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0;
  41. vec4 res = vec4(
  42. conv(kernel, imageData.r, 1.0, 0.0),
  43. conv(kernel, imageData.g, 1.0, 0.0),
  44. conv(kernel, imageData.b, 1.0, 0.0),
  45. 1.0);
  46. imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), res);
  47. }