在平面上渲染视频使用 shaderModifiers ,但颜色太浅
Render video in plane use shaderModifiers , but the color is too light
我用ARKIT加载一个平面,平面修改SCNShaderModifierEntryPointFragment来显示解码后的视频。但是渲染出来的视频画面太淡了,比使用metalLayer渲染出来的视频要亮。为什么会这样?我也试过修改SCNShaderModifierEntryPointSurface,设置为_surface.diffuse。我也尝试使用 rgb 而不是 yuv。但还是一样。
这应该也不是光线的原因。我尝试使用 diffuse.content = 图像,它是正确的。
在 metalLayer 中渲染
在 ar 中渲染
我尝试使用 SCNProgram、shaderModifiers 渲染 MTLTexture。渲染YUV或RGB结果,颜色更浅
texture2d textureY;
texture2d textureUV;
float3x3 coversionMatrix;
float3 yuv;
yuv.x = textureY.sample(textureSampler, _surface.diffuseTexcoord).r;
yuv.yz = textureUV.sample(textureSampler, _surface.diffuseTexcoord).rg;
float3 rgb = coversionMatrix * (yuv - offset);
_output.color = float4(rgb, 1.0);
//set the shaderModifiers
myMaterial.shaderModifiers = @{ SCNShaderModifierEntryPointFragment : shader};
如何生成金属纹理?尝试使用像素格式的“_sRGB”变体,例如 MTLPixelFormatRGBA8Unorm_sRGB
而不是 MTLPixelFormatRGBA8Unorm
。
或者,尝试将最终颜色(着色器修改器示例中的 rgb
变量)转换为线性颜色 space,如 :
中所述
static float srgbToLinear(float c) {
if (c <= 0.04045)
return c / 12.92;
else
return powr((c + 0.055) / 1.055, 2.4);
}
我用ARKIT加载一个平面,平面修改SCNShaderModifierEntryPointFragment来显示解码后的视频。但是渲染出来的视频画面太淡了,比使用metalLayer渲染出来的视频要亮。为什么会这样?我也试过修改SCNShaderModifierEntryPointSurface,设置为_surface.diffuse。我也尝试使用 rgb 而不是 yuv。但还是一样。
这应该也不是光线的原因。我尝试使用 diffuse.content = 图像,它是正确的。
在 metalLayer 中渲染
在 ar 中渲染
我尝试使用 SCNProgram、shaderModifiers 渲染 MTLTexture。渲染YUV或RGB结果,颜色更浅
texture2d textureY;
texture2d textureUV;
float3x3 coversionMatrix;
float3 yuv;
yuv.x = textureY.sample(textureSampler, _surface.diffuseTexcoord).r;
yuv.yz = textureUV.sample(textureSampler, _surface.diffuseTexcoord).rg;
float3 rgb = coversionMatrix * (yuv - offset);
_output.color = float4(rgb, 1.0);
//set the shaderModifiers
myMaterial.shaderModifiers = @{ SCNShaderModifierEntryPointFragment : shader};
如何生成金属纹理?尝试使用像素格式的“_sRGB”变体,例如 MTLPixelFormatRGBA8Unorm_sRGB
而不是 MTLPixelFormatRGBA8Unorm
。
或者,尝试将最终颜色(着色器修改器示例中的 rgb
变量)转换为线性颜色 space,如
static float srgbToLinear(float c) {
if (c <= 0.04045)
return c / 12.92;
else
return powr((c + 0.055) / 1.055, 2.4);
}