【问题标题】:iOS Metal: casting half4 variable to float4 typeiOS Metal:将half4变量转换为float4类型
【发布时间】:2017-05-12 15:02:36
【问题描述】:

我正在使用采样器从纹理中采样:

constexpr sampler cubeSampler(filter::linear, mip_filter::none);
half4 res = cubeTexture.sample(cubeSampler, texVec);

结果是 half4 类型,但我需要将其转换为 float4 才能执行数学运算。我该如何执行这个演员表?

【问题讨论】:

  • 结果是half4 类型,因为您大概将cubeTexture 声明为texturecube<half>。如果你想要float4,你应该考虑将它声明为texturecube<float>

标签: ios shader metal


【解决方案1】:

static_cast 有效,或者您可以使用更简洁的转换构造函数:

float4 res_float4 = float4(res);

【讨论】:

    【解决方案2】:
    constexpr sampler cubeSampler(filter::linear, mip_filter::none);
    half4 res = cubeTexture.sample(cubeSampler, texVec);
    
    // cast to float4:
    float4 res_float4 =  static_cast<float4>(res);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      • 2011-09-13
      • 2020-10-25
      • 2020-02-01
      • 1970-01-01
      • 2021-10-25
      • 2020-06-19
      相关资源
      最近更新 更多