gpt4 book ai didi

ios - Metal 质感 - 绘制和删除

转载 作者:行者123 更新时间:2023-11-30 11:10:07 29 4
gpt4 key购买 nike

我正在尝试修改Apple的示例GLPaint(使用OpenGL的绘画应用程序)以使用Metal而不是OpenGL。我可以使用 Metal 将笔触渲染到屏幕上,但在“删除”它时遇到困难。

在 Metal 中,我使用以下混合参数:

renderPipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
renderPipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
renderPipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha

渲染函数使用上面的管道描述符:

let descriptor = MTLRenderPassDescriptor()

descriptor.colorAttachments[0].loadAction = .load
descriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0.0, green: 0.0, blue: 0.0, alpha:0.0)
descriptor.colorAttachments[0].storeAction = .store
descriptor.colorAttachments[0].texture = colorAttachmentTexture

let renderCommandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: descriptor)
renderCommandEncoder?.setRenderPipelineState( blendRGBAndAlphaPipelineState)
texturedQuad.encodeDrawCommands(encoder: renderCommandEncoder!, texture: texture)
renderCommandEncoder?.endEncoding()

如何创建管道描述符来“删除”先前渲染的纹理的部分?在 OpenGL 中,我可以通过执行以下操作在“绘图”和“删除”之间切换:

if(eraserEnabled)
{
glColor4f(0,0,0,1);
glBlendFunc( GL_ZERO,GL_ONE_MINUS_SRC_ALPHA);
}
else
{

// Set color of the brush
glColor4f(1,0,0,1);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}

我尝试在 Metal 中创建第二个 renderPipeline ,用于“删除”。我使用了下面的混合参数,但它不起作用。

renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .zero
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .zero
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha

image shows how "erase" is not working.

摘要:我正在将 Metal 纹理渲染到屏幕上,但现在不知道如何设置混合参数“删除”先前绘制的纹理的选定区域。

最佳答案

我只设置了这个sourceAlphaBlendFactor = .zero,没有sourceRGBBlendFactor。例如我使用 https://github.com/codelynx/MetalPaint 中的代码

关于ios - Metal 质感 - 绘制和删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52267291/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com