问题描述
我已经检查了这个问题.在纹理加载器选项中使用[MTKTextureLoader.Option.SRGB : false]
不起作用.发生的全部是当我执行[MTKTextureLoader.Option.SRGB : true]
时,它的颜色要深得多,而不是稍微深一些.肯定还有别的东西.这是此不良行为的示例.这是供参考的原始纹理:
如您所见,我正在使用鼠标将原始填充的冰纹理保留在渲染的冰纹理上.即使使用[MTKTextureLoader.Option.SRGB : false]
,它也要轻得多.即使我将鼠标悬停在渲染的纹理上的图像是稍微透明的,但仍然明显存在不想要的效果.
I already checked this question. Using [MTKTextureLoader.Option.SRGB : false]
in texture loader options doesn't work. All that happens is when I do [MTKTextureLoader.Option.SRGB : true]
, it's a lot darker instead of slightly darker. There must be something else. Here is an example of this unwanted behavior.Here is the original texture for reference:
As you can see I am using the mouse to hold the original packed ice texture over the rendered one. It's considerably lighter, even with [MTKTextureLoader.Option.SRGB : false]
. Even though the image I am hovering over the rendered texture is slightly transparent, the unwanted effect is still clearly present.
这是我的片段函数:
fragment half4 TextureFragment(VertexOut VertexIn [[stage_in]], texture2d<float> Texture [[texture(0)]]) {
constexpr sampler ColorSampler(mip_filter::nearest, mag_filter::nearest, min_filter::nearest);
float4 Color = Texture.sample(ColorSampler, VertexIn.TexCoord.xy / VertexIn.TexCoord.z);
return half4(Color.r, Color.g, Color.b, 1);
}
如何解决该问题?如何渲染实际的纹理而不是较暗的版本?
How can I fix the problem? How can I render the actual texture instead of a darker version?
注意:我必须修复问题,而不是解决它.解决方法类似于片段着色器中的return half4(Color.r+0.1, Color.g+0.1, Color.b+0.1, 1);
.我必须从根本上解决问题.为什么库中有那么多错误?
Note: I must fix the problem, not work around it. A workaround would be like return half4(Color.r+0.1, Color.g+0.1, Color.b+0.1, 1);
from the fragment shader. I must fix the problem from the root. Why are there so many bugs within the libraries?
我还尝试将黑色背景更改为白色,并且它不会更改纹理,因此不起作用.
I also tried changing the black background to white, and it doesn't change the texture, so that doesn't work.
我想我曾经被告知要使用Xcode的GPU帧调试器检查纹理.是什么意思?
I think I was once told to check the texture using Xcode's GPU frame debugger. What does that mean?
我们将不胜感激.
推荐答案
要加载这些PNG图像,我需要将pixelFormat设置为bgra8Unorm_srgb而不是bgra8Unorm.为什么默认情况下它不只是bgra8Unorm_srgb? 此答案指定如何执行此操作.我自己弄清楚了,与此同时,我没有其他意见,也没有其他答案.我基本上不得不独自解决这个问题.
For loading those PNG images, I need to set the pixelFormat to bgra8Unorm_srgb instead of bgra8Unorm. Why isn't it just bgra8Unorm_srgb by default? This answer specifies how to do this. I figured it out myself, meanwhile I got no other comments, no other answers. I basically had to figure it out alone.
MetalView.colorPixelFormat = .bgra8Unorm_srgb
我可以
PipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm_srgb
所以我得到了正确的图像
So I get the correct image rendered
这篇关于即使使用[MTKTextureLoader.Option.SRGB:false],金属也会渲染出奇特的深色纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!