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
29 lines
1.1 KiB
//
|
|
// SCDepthToGrayscaleMetalModule.metal
|
|
// Snapchat
|
|
//
|
|
// Created by Brian Ng on 12/7/17.
|
|
//
|
|
|
|
#include <metal_stdlib>
|
|
using namespace metal;
|
|
|
|
typedef struct DepthToGrayscaleRenderData {
|
|
float depthRange;
|
|
float depthOffset;
|
|
} DepthToGrayscaleRenderData;
|
|
|
|
kernel void kernel_depth_to_grayscale(texture2d<float, access::read> sourceDepthTexture[[texture(0)]],
|
|
texture2d<float, access::write> destinationYTexture [[texture(1)]],
|
|
texture2d<float, access::write> destinationUVTexture [[texture(2)]],
|
|
constant DepthToGrayscaleRenderData &renderData [[buffer(0)]],
|
|
uint2 gid [[thread_position_in_grid]],
|
|
uint2 size [[threads_per_grid]]) {
|
|
float depthValue = sourceDepthTexture.read(uint2(gid.x/4, gid.y/4)).r;
|
|
float normalizedDepthValue = (depthValue - renderData.depthOffset) / renderData.depthRange;
|
|
|
|
destinationYTexture.write(normalizedDepthValue, gid);
|
|
destinationUVTexture.write(float4(0.5, 0.5, 0, 0), gid);
|
|
}
|
|
|
|
|