Skip to content

Latest commit

 

History

History
46 lines (29 loc) · 1.38 KB

README.md

File metadata and controls

46 lines (29 loc) · 1.38 KB

MetalPetalJS

An experimental JavaScript API for MetalPetal using the JavaScriptCore.framework

Example

The example project demonstrate how to download shader libraries and render scripts from the server then use the downloaded renderer to process the test image.

The metal shader library and the render script is bundled in a zip file.

In the zip archive:

  • script.js

    The javascript file contains the render logic of this demo.

  • default.metallib

    The metal shader library contains the following shader code:

    #include "MTIShaderLib.h"
    
    using namespace metalpetal;
    
    fragment float4 shader(VertexOut vertexIn [[ stage_in ]],
                           texture2d<float, access::sample> inputTexture [[ texture(0) ]],
                           constant float &offset [[buffer(0)]],
                           sampler s [[ sampler(0) ]]) {
        float4 colorR = inputTexture.sample(s, vertexIn.textureCoordinate + float2(offset));
        float4 colorG = inputTexture.sample(s, vertexIn.textureCoordinate);
        float4 colorB = inputTexture.sample(s, vertexIn.textureCoordinate - float2(offset));
        return float4(colorR.r, colorG.g, colorB.b, 1.0);
    }
    

Install

You can use CocoaPods to install the lastest version.

use_frameworks!

pod 'MetalPetalJS', :git => 'https://github.com/MetalPetal/MetalPetalJS.git'