ShaderView

所属分类:GPU/显卡
开发工具:Swift
文件大小:5142KB
下载次数:0
上传日期:2017-11-02 05:22:47
上 传 者sh-1993
说明:  用于简单着色器编程的库
(A library for simple shader programming)

文件列表:
Images (0, 2017-11-02)
Images\PlaygroundExample.gif (5537220, 2017-11-02)
LICENSE (1068, 2017-11-02)
MSLPlayground.playground (0, 2017-11-02)
MSLPlayground.playground\Contents.swift (1376, 2017-11-02)
MSLPlayground.playground\Resources (0, 2017-11-02)
MSLPlayground.playground\Resources\MSLPlayground.metal (1194, 2017-11-02)
MSLPlayground.playground\Resources\target.png (13807, 2017-11-02)
MSLPlayground.playground\contents.xcplayground (191, 2017-11-02)
ShaderView.xcodeproj (0, 2017-11-02)
ShaderView.xcodeproj\ShaderView.xcworkspace (0, 2017-11-02)
ShaderView.xcodeproj\ShaderView.xcworkspace\contents.xcworkspacedata (140, 2017-11-02)
ShaderView.xcodeproj\project.pbxproj (12472, 2017-11-02)
ShaderView.xcodeproj\project.xcworkspace (0, 2017-11-02)
ShaderView.xcodeproj\project.xcworkspace\contents.xcworkspacedata (155, 2017-11-02)
ShaderView.xcworkspace (0, 2017-11-02)
ShaderView.xcworkspace\contents.xcworkspacedata (237, 2017-11-02)
ShaderView (0, 2017-11-02)
ShaderView\Info.plist (753, 2017-11-02)
ShaderView\MTKView+ShaderView.swift (412, 2017-11-02)
ShaderView\ShaderView.h (516, 2017-11-02)
ShaderView\ShaderViewRenderer.swift (3377, 2017-11-02)
ShaderView\TargetedExtension.swift (1169, 2017-11-02)

# ShaderView A library for simple shader programming.

A ShaderView example with Playground

## About ShaderView ### ShaderView wraps the MTKView setup. ShaderView is designed to extend `MTKView` which enables to do shader view programming simpler and easier, like [GLSL Sandbox](http://glslsandbox.com) or [Shadertoy](https://www.shadertoy.com). This library wraps the configuration process of `MTLLibrary`, `MTLFunction`, `MTLComputePipelineState`, `MTLCommandQueue`, `MTLCommandBuffer` and `MTLCommandEncoder`, and takes a simple kernel function with the arguments of output texture, current time, touch events and the position in the grid. Create `ShderViewRenderer`, set it on `MTLView` and add the MTLView to other UIKit view. ### Test with Playground. The screen recorded above is a playground attacked to this workspace MSLPlayground on which you can write/test simple MSLs. The shader function in the screenshot is converted from the GLSL on [Shadertoy](https://www.shadertoy.com/view/XsXXDn). ## Usage ShaderView is consisted mainly from `ShaderViewRenderer` and `MTKView`'s extension. ```swift import MetalKit import ShaderView // Create MTLDevice. MTLDevice is encouranged to create right after the app launch and retain throughout the life time of the app. guard let device = MTLCreateSystemDefaultDevice else { return } // Optional: Create MTLLibrary. This is optional and if you don't set your own MTLLibrary, ShaderViewRenderer will generate a default library from the device. var library: MTLLibrary? do { let path = Bundle.main.path(forResource: "MSLPlayground", ofType: "metal") let source = try String(contentsOfFile: path!, encoding: .utf8) library = try device.makeLibrary(source: source, options: nil) } catch let error as NSError { print("library error: " + error.description) } // Create MTLView let shaderView = MTKView(frame: NSRect(x: 0, y: 0, width: 400, height: 400), device: device) // Create ShaderViewRenderer with the device you created. let renderer = ShaderViewRenderer(device: device) // Optional: Set MTLLibrary to ShaderViewRenderer renderer.library = library // Set the kernel function name to ShaderViewRenderer. The function you specified must have the same arguments as "MSLPlayground.metal" in the example Playground. renderer.functionName = "playgroundSample" // Set the renderer to the metal view. shaderView.sv.set(renderer: renderer) ``` ## Requirements * Xcode 9.1 * Swift 4.0.2

近期下载者

相关文件


收藏者