DKGL2 sample codes

emboss.comp 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 avg[9];
  17. } imageData;
  18. void main()
  19. {
  20. // Fetch neighbouring texels
  21. int n = -1;
  22. for (int i=-1; i<2; ++i)
  23. {
  24. for(int j=-1; j<2; ++j)
  25. {
  26. n++;
  27. vec3 rgb = imageLoad(inputImage, ivec2(gl_GlobalInvocationID.x + i, gl_GlobalInvocationID.y + j)).rgb;
  28. imageData.avg[n] = (rgb.r + rgb.g + rgb.b) / 3.0;
  29. }
  30. }
  31. float[9] kernel;
  32. kernel[0] = -1.0; kernel[1] = 0.0; kernel[2] = 0.0;
  33. kernel[3] = 0.0; kernel[4] = -1.0; kernel[5] = 0.0;
  34. kernel[6] = 0.0; kernel[7] = 0.0; kernel[8] = 2.0;
  35. vec4 res = vec4(vec3(conv(kernel, imageData.avg, 1.0, 0.50)), 1.0);
  36. imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), res);
  37. }