且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在金属中复制OpenGL混合

更新时间:2023-01-27 13:55:58

我发现了问题所在,那就是纹理的创建方式,而不是正确的混合设置方式.当用MetalKit在一组上创建纹理时,我使用了以下选项: [MTKTextureLoaderOptionSRGB: NSNumber(value:0)]并且没有.当它们都设置为相同(1或0)时,它们匹配并且混合正确.

I found the problem, it was with how the textures were created, not how the blending was set up which was correct. When creating the textures with MetalKit on one set I used the option: [MTKTextureLoaderOptionSRGB: NSNumber(value:0)] and didn't on the other. When they both were set to be the same (either 1 or 0) they matched and blending worked correctly.

着色器最终成为:

fragment float4 terrainFragment(FragmentIn inFrag [[stage_in]],
                            texture2d<float, access::sample> colorTexture [[ texture(0) ]],
                            sampler colorSampler [[ sampler(0) ]]) {
    float4 color = colorTexture.sample(colorSampler, inFrag.uv * 1.33);
    color *= float4(inFrag.shadow,inFrag.shadow,inFrag.shadow,1);
    return color * 4;
}