Code Snippets Metal

Short texts Metal 🧑‍💻 Code snippets Metal ✍️ Reading lists Metal 👀

RealityKitPostProcessShader.metal

#include using namespace metal; [[kernel]] void inverseColorKernel(texture2d sourceTexture [[texture(0)]], texture2d targetTexture [[texture(1)]], uint2 gridPosition [[thread_position_in_grid]]) { float4 sourceColor = sourceTexture.read(gridPosition); float4 inverseColor = float4(1.0 – sourceColor.rgb, sourceColor.a); targetTexture.write(inverseColor, gridPosition); }

2D Scaling Pixel Art Fragment Shader (Metal)

fragment float4 pixelArtFragmentShader(RasterizerData in [[stage_in]], texture2d_array texture_atlas [[ texture(0) ]]) { constexpr sampler textureSampler (mag_filter::linear, min_filter::linear); // This is the alpha value from the graph, or the size of the margin where you // want to apply bilinear filtering around a texel float2 alpha = float2(0.07); // As noted in the article, this is x […]