I'm currently trying to draw graphics that will be animated using Metal in Swift. I successfully created one frame of my graphics. The graphics are simple, as you can see from this image. I cannot figure out how to make a multi-sample drawing. There are apparently very few references to Metal in general, especially regarding Swift syntax.

self.metalLayer = CAMetalLayer() self.metalLayer.device = self.device self.metalLayer.pixelFormat = .BGRA8Unorm self.metalLayer.framebufferOnly = true self.metalLayer.frame = self.view.frame self.view.layer.addSublayer(self.metalLayer) self.renderer = SunRenderer(device: self.device, frame: self.view.frame) let defaultLibrary = self.device.newDefaultLibrary() let fragmentProgram = defaultLibrary!.newFunctionWithName("basic_fragment") let vertexProgram = defaultLibrary!.newFunctionWithName("basic_vertex") let pipelineStateDescriptor = MTLRenderPipelineDescriptor() pipelineStateDescriptor.vertexFunction = vertexProgram pipelineStateDescriptor.fragmentFunction = fragmentProgram pipelineStateDescriptor.colorAttachments[0].pixelFormat = .BGRA8Unorm pipelineStateDescriptor.colorAttachments[0].blendingEnabled = true pipelineStateDescriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperation.Add pipelineStateDescriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperation.Add pipelineStateDescriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactor.SourceAlpha pipelineStateDescriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha pipelineStateDescriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactor.OneMinusSourceAlpha pipelineStateDescriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactor.OneMinusSourceAlpha
The question is how to smooth these ribs?
UPDATE:
So, I implemented the MultiSample texture and set sampleCount to 4. I don't notice any difference, so I suspect that I did something wrong.
COMPLETION:
So in the end, it seems like multithreaded work. Initially, I had vertices wrapping these "rays" with 0 alpha. This is a trick to make smoother edges. With these tops, multisampling did not improve the edges. When I go back to have 4 vertices per ray, multisampling has improved their edges.
let defaultLibrary = self.device.newDefaultLibrary() let fragmentProgram = defaultLibrary!.newFunctionWithName("basic_fragment") let vertexProgram = defaultLibrary!.newFunctionWithName("basic_vertex") let pipelineStateDescriptor = MTLRenderPipelineDescriptor() pipelineStateDescriptor.vertexFunction = vertexProgram pipelineStateDescriptor.fragmentFunction = fragmentProgram pipelineStateDescriptor.colorAttachments[0].pixelFormat = .BGRA8Unorm pipelineStateDescriptor.colorAttachments[0].blendingEnabled = true pipelineStateDescriptor.sampleCount = 4 pipelineStateDescriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperation.Add pipelineStateDescriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperation.Add pipelineStateDescriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactor.SourceAlpha pipelineStateDescriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha pipelineStateDescriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactor.OneMinusSourceAlpha pipelineStateDescriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactor.OneMinusSourceAlpha let desc = MTLTextureDescriptor() desc.textureType = MTLTextureType.Type2DMultisample desc.width = Int(self.view.frame.width) desc.height = Int(self.view.frame.height) desc.sampleCount = 4 desc.pixelFormat = .BGRA8Unorm self.sampletex = self.device.newTextureWithDescriptor(desc)
ios swift metal
Jeff becker
source share