metal

Triangulation in Metal

时间秒杀一切 提交于 2019-12-11 17:19:46
问题 As Shown in the picture. The numbers are touchpoints in the screen in order. I need to draw the traingulation only inside Colored area. Can we do it in metal with its algorithm or Any suggestions please var temp1:VertexInFillBrus temp1 = VertexInFillBrush(a:drawPoints[0] , b:drawPoints[drawPoints.count - 1] , c: drawPoints[drawPoints.count - 2])) self.bezierCalculatedCoordinates.append(temp1) self.buildBuffers(device: device) In Draw Command commandEncoder.setRenderPipelineState

MTKView blend issues when re-using currentDrawable.texture in draw() loop

最后都变了- 提交于 2019-12-11 17:12:09
问题 I am working on a metal-backed painting application in which I divide the drawing of a stroke in two steps: the first step draws the leading edge of a stroke to screen and captures the entire to an MTLTexture via: metalTextureComposite = self.currentDrawable!.texture the second step draws an updated leading edge of the advancing stroke, and composites atop a polygon textured with the last saved metalTextureComposite. This method allows me to draw infinitely long strokes without sacrificing

MTKView vertex transparency is not getting picked up in “additive” blending mode

蓝咒 提交于 2019-12-11 16:22:16
问题 I am trying to implement a metal-backed drawing application where brushstrokes are drawn on an MTKView by stamping a textured square repeatedly along a path. I am varying the stamp's color/transparency at the vertex level as the brushstroke is drawn so I can simulate ink effects such as color/transparency fading over time, etc. This seems to work ok when I am using a classic "over" type blending (which does not accumulate value over time), but when I use "additive" blending, vertex

iOS CIFaceDetector very slow with Metal

孤人 提交于 2019-12-11 15:37:21
问题 I've been trying to apply filters to a certain part of the face detected in an image. In order to apply filters to the whole image, I used the sample code from apple: https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/avcamfilter_applying_filters_to_a_capture_stream If I just add one line of detecting faces via CIDetector, to the method which sends out CVPixelBuffers to FilterRenderer class and then to MTKView to render the filtered buffer, the performance is

MPSImageIntegral returning all zeros

孤人 提交于 2019-12-11 15:22:02
问题 I am trying to use MPSImageIntegral to calculate the sum of some elements in an MTLTexture . This is what I'm doing: std::vector<float> integralSumData; for(int i = 0; i < 10; i++) integralSumData.push_back((float)i); MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR32Float width:(integralSumData.size()) height:1 mipmapped:NO]; textureDescriptor.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite; id<MTLTexture>

metallib: Error reading module: Invalid bitcode signature

Deadly 提交于 2019-12-11 14:02:35
问题 I have following Filter.metal file #include <metal_stdlib> using namespace metal; #include <CoreImage/CoreImage.h> // includes CIKernelMetalLib.h extern "C" { namespace coreimage { float4 myColor(sample_t s) { return s.grba; } }} I am trying to compile it with: xcrun metal -fcikernel Filter.metal -o Filter.air xcrun metallib -cikernel Filter.air -o Filter.metallib But I get this Error: metallib: Error reading module: Invalid bitcode signature I am trying to create a custom CIFIlter and I

iOS Metal Shader - Texture read and write access?

那年仲夏 提交于 2019-12-11 12:40:26
问题 I'm using a metal shader to draw many particles onto the screen. Each particle has its own position (which can change) and often two particles have the same position. How can I check if the texture2d I write into does not have a pixel at a certain position yet? (I want to make sure that I only draw a particle at a certain position if there hasn't been drawn a particle yet, because I get an ugly flickering if many particles are drawn at the same positon) I've tried outTexture.read

MTKView vs GLKView performance on old devices

痴心易碎 提交于 2019-12-11 11:00:14
问题 I am running into weird performance issues on older device (iPad Mini 2 of year 2014) ever since migrating to MTKView from OpenGLES based views. To summarize, I am rendering live video preview using MTKView and also optionally record videos (like in RosyWriter sample code). My new app version is written in Swift and supports both Metal & OpenGLES. So I have both Open GL and Metal rendering code to compare. I also have a legacy version of app written in Objective C & uses OpenGLES for all

Is there a size limit to newBufferWithBytes()?

可紊 提交于 2019-12-11 10:21:27
问题 I have been rendering polyhedron using Metal. The problem happens when I tried to render an icosahedron entity, whose vertices consists of barely 1680 bytes of data in size using newBufferWithBytes(). Then the entire app halt, both CPU and GPU frame drop to zero, and everything went back to normal, except Metal view freezes. I have regular polyhedrons as Node's subclasses in implementation. class Node { let name : String var vertexBuffer: MTLBuffer? var uniformBuffer: MTLBuffer? var

Load a remote image using MTKTextureLoader

我只是一个虾纸丫 提交于 2019-12-11 08:42:31
问题 I'm trying to load a remote image into a MTLTexture with this code, let textureLoader = MTKTextureLoader(device: device) textureLoader.newTexture(withContentsOf: url, options: options) { [weak self] (texture, error) in if let t = texture { completion(t) } else { if let desc = error?.localizedDescription { NSLog(desc) } completion(nil) } } If the URL comes from a Bundle resource, then it works, e.g. let url = Bundle.main.url(forResource: name, withExtension: ext) However, it fails if I pass