I’m utilizing following pipelineDescriptor and shader fragments.
I encountered an issue which I couldn’t discover answer for.
My textures photos match high-quality seems to be nice besides clear ones.
Clear elements (Alpha = 0) of my photos seems to be black on machine display as a substitute of
clear.
Additionally, depthStencilDescriptor.isDepthWriteEnabled = true
depthStencilDescriptor.depthCompareFunction = .much less
func buildPipelineState(machine: MTLDevice) -> MTLRenderPipelineState {
let library = machine.makeDefaultLibrary()
let vertexFunction = library?.makeFunction(title: vertexFunctionName)
let fragmentFunction = library?.makeFunction(title: fragmentFunctionName)
let renderPipelineDescriptor = MTLRenderPipelineDescriptor()
renderPipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
renderPipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
renderPipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
renderPipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .oneMinusBlendAlpha
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
renderPipelineDescriptor.depthAttachmentPixelFormat = .depth32Float
renderPipelineDescriptor.vertexFunction = vertexFunction
renderPipelineDescriptor.fragmentFunction = fragmentFunction
renderPipelineDescriptor.vertexDescriptor = vertexDescriptor
var renderPipelineState: MTLRenderPipelineState! = nil
do {
renderPipelineState = strive machine.makeRenderPipelineState(descriptor: renderPipelineDescriptor)
} catch let error as NSError {
Swift.print("(error)")
}
return renderPipelineState
}
fragment half4 basic_fragment_function(VertexOut vIn [[ stage_in ]],
fixed Mild &mild [[ buffer(1) ]]){
float4 coloration = vIn.coloration;
return half4(coloration);
}
fragment half4 textured_fragment_function(VertexOut vIn [[ stage_in ]],
fixed Mild &mild [[ buffer(1) ]],
sampler sampler2d [[ sampler(0) ]],
texture2d<float> texture [[ texture(0) ]]){
float4 coloration = texture.pattern(sampler2d, vIn.textCoors);
return half4(coloration);
}