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.

37 lines
1.4 KiB

  1. //
  2. // SCNightModeEnhancementMetalModule.metal
  3. // Snapchat
  4. //
  5. // Created by Chao Pang on 12/21/17.
  6. //
  7. //
  8. #include <metal_stdlib>
  9. using namespace metal;
  10. typedef struct SampleBufferMetadata {
  11. int iosSpeedRating;
  12. float exposureTime;
  13. float brightness;
  14. }SampleBufferMetadata;
  15. kernel void kernel_night_mode_enhancement(texture2d<float, access::read> sourceYTexture [[texture(0)]],
  16. texture2d<float, access::read> sourceUVTexture [[texture(1)]],
  17. texture2d<float, access::write> destinationYTexture [[texture(2)]],
  18. texture2d<float, access::write> destinationUVTexture [[texture(3)]],
  19. constant SampleBufferMetadata &metaData [[buffer(0)]],
  20. uint2 gid [[thread_position_in_grid]],
  21. uint2 size [[threads_per_grid]]) {
  22. float valueY = sourceYTexture.read(gid).r;
  23. float2 valueUV = sourceUVTexture.read(gid).rg;
  24. float factor = 1.0 - metaData.brightness * 0.1;
  25. factor = max(min(factor, 1.3), 1.0);
  26. valueY = min(valueY * factor, 1.0);
  27. valueUV.rg = max(min((valueUV.rg - 0.5) * factor + 0.5, 1.0), 0.0);
  28. destinationYTexture.write(valueY, gid);
  29. destinationUVTexture.write(float4(valueUV.r, valueUV.g, 0, 0), gid);
  30. }