我正在使用MetalKit,并且有一个复杂的呈现管道。结果被呈现为一个MTKView。
现在,我想将MTKView的内容提供给SCNScene,并使用SCNCamera来执行像HDR这样的后处理效果。
这怎麽可能?
我不想要一般的方向。如果可能的话我想要具体的电话。
发布于 2018-05-17 09:40:06
理想情况下,应该将后期处理作为金属渲染管道的一部分来执行。您建议的过程需要不必要的资源,因为您将在SceneKit中渲染一个3D的2D平面,仅仅是为了应用一些HDR效果。
不过,您可以通过将金属管道输出呈现为纹理,然后简单地将其应用到SceneKit中的平面上,从而实现您想要的结果。
首先分配您的纹理:
plane.materials.first?.diffuse.contents = offscreenTexture
然后将SceneKit呈现重写为金属呈现循环:
func renderer(_ renderer: SCNSceneRenderer, willRenderScene scene: SCNScene, atTime time: TimeInterval) {
doRender()
}然后执行以纹理为目标的金属渲染,一旦完成,您将呈现SceneKit场景:
func doRender() {
//rendering to a MTLTexture, so the viewport is the size of this texture
let viewport = CGRect(x: 0, y: 0, width: CGFloat(textureSizeX), height: CGFloat(textureSizeY))
//write to offscreenTexture, clear the texture before rendering using green, store the result
let renderPassDescriptor = MTLRenderPassDescriptor()
renderPassDescriptor.colorAttachments[0].texture = offscreenTexture
renderPassDescriptor.colorAttachments[0].loadAction = .clear
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0, 1, 0, 1.0); //green
renderPassDescriptor.colorAttachments[0].storeAction = .store
let commandBuffer = commandQueue.makeCommandBuffer()
// reuse scene1 and the current point of view
renderer.scene = scene1
renderer.pointOfView = scnView1.pointOfView
renderer.render(atTime: 0, viewport: viewport, commandBuffer: commandBuffer, passDescriptor: renderPassDescriptor)
commandBuffer.commit()
}`完整的示例项目:
https://stackoverflow.com/questions/50371498
复制相似问题