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.

29 lines
1.1 KiB

  1. //
  2. // SCDepthToGrayscaleMetalModule.metal
  3. // Snapchat
  4. //
  5. // Created by Brian Ng on 12/7/17.
  6. //
  7. #include <metal_stdlib>
  8. using namespace metal;
  9. typedef struct DepthToGrayscaleRenderData {
  10. float depthRange;
  11. float depthOffset;
  12. } DepthToGrayscaleRenderData;
  13. kernel void kernel_depth_to_grayscale(texture2d<float, access::read> sourceDepthTexture[[texture(0)]],
  14. texture2d<float, access::write> destinationYTexture [[texture(1)]],
  15. texture2d<float, access::write> destinationUVTexture [[texture(2)]],
  16. constant DepthToGrayscaleRenderData &renderData [[buffer(0)]],
  17. uint2 gid [[thread_position_in_grid]],
  18. uint2 size [[threads_per_grid]]) {
  19. float depthValue = sourceDepthTexture.read(uint2(gid.x/4, gid.y/4)).r;
  20. float normalizedDepthValue = (depthValue - renderData.depthOffset) / renderData.depthRange;
  21. destinationYTexture.write(normalizedDepthValue, gid);
  22. destinationUVTexture.write(float4(0.5, 0.5, 0, 0), gid);
  23. }