No Description

edgedetect.comp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 avg[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.avg[n] = (rgb.r + rgb.g + rgb.b) / 3.0;
  31. }
  32. }
  33. float[9] kernel;
  34. kernel[0] = -1.0/8.0; kernel[1] = -1.0/8.0; kernel[2] = -1.0/8.0;
  35. kernel[3] = -1.0/8.0; kernel[4] = 1.0; kernel[5] = -1.0/8.0;
  36. kernel[6] = -1.0/8.0; kernel[7] = -1.0/8.0; kernel[8] = -1.0/8.0;
  37. vec4 res = vec4(vec3(conv(kernel, imageData.avg, 0.1, 0.0)), 1.0);
  38. imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), res);
  39. }