DKGL2 sample codes

sharpen.comp 1.2KB

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