2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.6 KiB

  1. //
  2. // SCExposureAdjustMetalModule.metal
  3. // Snapchat
  4. //
  5. // Created by Michel Loenngren on 7/11/17.
  6. //
  7. //
  8. #include <metal_stdlib>
  9. using namespace metal;
  10. kernel void kernel_exposure_adjust(texture2d<float, access::read> sourceYTexture [[texture(0)]],
  11. texture2d<float, access::read> sourceUVTexture [[texture(1)]],
  12. texture2d<float, access::write> destinationYTexture [[texture(2)]],
  13. texture2d<float, access::write> destinationUVTexture [[texture(3)]],
  14. uint2 gid [[thread_position_in_grid]],
  15. uint2 size [[threads_per_grid]]) {
  16. float valueY = sourceYTexture.read(gid).r;
  17. float2 valueUV = sourceUVTexture.read(gid).rg;
  18. float factor = 1.0 / pow(1.0 + valueY, 5) + 1.0;
  19. valueY *= factor;
  20. destinationYTexture.write(valueY, gid);
  21. destinationUVTexture.write(float4(valueUV.r, valueUV.g, 0, 0), gid);
  22. }
  23. kernel void kernel_exposure_adjust_nightvision(texture2d<float, access::read> sourceYTexture [[texture(0)]],
  24. texture2d<float, access::read> sourceUVTexture [[texture(1)]],
  25. texture2d<float, access::write> destinationYTexture [[texture(2)]],
  26. texture2d<float, access::write> destinationUVTexture [[texture(3)]],
  27. uint2 gid [[thread_position_in_grid]],
  28. uint2 size [[threads_per_grid]]) {
  29. float valueY = sourceYTexture.read(gid).r;
  30. float u = 0.5 - 0.368;
  31. float v = 0.5 - 0.291;
  32. destinationYTexture.write(valueY, gid);
  33. destinationUVTexture.write(float4(u, v, 0, 0), gid);
  34. }
  35. kernel void kernel_exposure_adjust_inverted_nightvision(texture2d<float, access::read> sourceYTexture [[texture(0)]],
  36. texture2d<float, access::read> sourceUVTexture [[texture(1)]],
  37. texture2d<float, access::write> destinationYTexture [[texture(2)]],
  38. texture2d<float, access::write> destinationUVTexture [[texture(3)]],
  39. uint2 gid [[thread_position_in_grid]],
  40. uint2 size [[threads_per_grid]]) {
  41. float valueY = sourceYTexture.read(gid).r;
  42. valueY = 1.0 - valueY;
  43. float u = 0.5 - 0.368;
  44. float v = 0.5 - 0.291;
  45. destinationYTexture.write(valueY, gid);
  46. destinationUVTexture.write(float4(u, v, 0, 0), gid);
  47. }