繁体   English   中英

金属质感-绘制和擦除

[英]Metal texture - Draw and Erase

我正在尝试将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

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

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

该图显示了“擦除”如何不起作用。

简介:我正在渲染“金属”纹理以显示在屏幕上,但现在不介绍如何设置混合参数来“擦除”先前绘制的纹理的选定区域。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM