I have posted a few questions recently about the drawing app I have been building over the last few years. I consider myself an intermediate coder and am reaching a point where my app is nearing completion. There are just a few things I have been unable to figure out on my own that I need help with.
One feature that I was able to achieve with a UIImageView was the ability to draw brushstrokes on the screen in a multiply blend mode. I loved this! However once I decided to switch over to using metal, I have been unable to achieve the same effect. I have tried different variations on the descriptor color attachments because that seems to be where I would make this feature happen. But alas I have been unable to make it work.
I am using an MTKView, capturing Apple Pencil touches, drawingPrimitives, and present(currentDrawable). My textures for the brushstrokes are pdf images.
Here is the descriptor code I am using in the pipeline setup for regular drawing. It works great:
One feature that I was able to achieve with a UIImageView was the ability to draw brushstrokes on the screen in a multiply blend mode. I loved this! However once I decided to switch over to using metal, I have been unable to achieve the same effect. I have tried different variations on the descriptor color attachments because that seems to be where I would make this feature happen. But alas I have been unable to make it work.
I am using an MTKView, capturing Apple Pencil touches, drawingPrimitives, and present(currentDrawable). My textures for the brushstrokes are pdf images.
Here is the descriptor code I am using in the pipeline setup for regular drawing. It works great:
Code Block let descriptor = MTLRenderPipelineDescriptor() descriptor.vertexFunction = vertProg descriptor.fragmentFunction = fragProg descriptor.colorAttachments[0].pixelFormat = .bgra8Unorm descriptor.colorAttachments[0].isBlendingEnabled = true descriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperation.add descriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperation.add descriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactor.sourceAlpha descriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactor.one descriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactor.oneMinusSourceAlpha descriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactor.oneMinusSourceAlpha
That is because blend modes of that kind can only be done manually in your fragment or kernel, not in the pipeline descriptor options. You have to write the math for it yourself and structure the render passes appropriately to perform the compositing.
Also fyi, you are going to get banding with that pixel format.
Also fyi, you are going to get banding with that pixel format.