【问题标题】:Render video in plane use shaderModifiers , but the color is too light平面渲染视频使用 shaderModifiers ,但颜色太浅
【发布时间】:2019-12-08 15:00:35
【问题描述】:

我使用ARKIT加载一个平面,平面修改SCNShaderModifierEntryPointFragment来显示解码后的视频。但是,渲染的视频图像比使用 metalLayer 渲染的视频太轻和更轻。为什么会这样?我也试过修改SCNShaderModifierEntryPointSurface,设置_surface.diffuse。我也尝试使用 rgb 代替 yuv。但还是一样。

这也不应该是因为光线。我尝试使用diffuse.content = image,没错。

在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};  

【问题讨论】:

  • 当我将 MTLTexture 发送到着色器显示时,颜色错误。
  • 如果我设置“material.diffuse.contents = AVPlayer;”,那就对了。但我不想使用 AVPlayer

标签: ios scenekit arkit


【解决方案1】:

如何生成金属纹理?尝试使用像素格式的“_sRGB”变体,例如MTLPixelFormatRGBA8Unorm_sRGB 而不是MTLPixelFormatRGBA8Unorm

或者,尝试将最终颜色(着色器修改器示例中的 rgb 变量)转换为线性颜色空间,如 this answer 中所述:

static float srgbToLinear(float c) {
    if (c <= 0.04045)
        return c / 12.92;
    else
        return powr((c + 0.055) / 1.055, 2.4);
}

【讨论】:

  • 我使用 CVMetalTextureCacheRef 来创建 MTLTextyre。我尝试使用 MTLPixelFormatR8Unorm_sRGB 代替 MTLPixelFormatR8Unorm,并使用 MTLPixelFormatRG8Unorm_sRGB 代替 MTLPixelFormatRG8Unorm。但它显示为绿色。
  • 这对我有帮助。非常感谢
猜你喜欢
  • 2018-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-08
  • 1970-01-01
  • 2014-03-28
  • 1970-01-01
  • 2019-07-16
相关资源
最近更新 更多