iOS Metal:将 half4 变量转换为 float4 类型
iOS Metal: casting half4 variable to float4 type
我正在使用采样器从纹理中采样:
constexpr sampler cubeSampler(filter::linear, mip_filter::none);
half4 res = cubeTexture.sample(cubeSampler, texVec);
结果是 half4 类型,但我需要将其转换为 float4 才能执行数学运算。我该如何执行此转换?
constexpr sampler cubeSampler(filter::linear, mip_filter::none);
half4 res = cubeTexture.sample(cubeSampler, texVec);
// cast to float4:
float4 res_float4 = static_cast<float4>(res);
static_cast
有效,或者您可以使用更简洁的转换构造函数:
float4 res_float4 = float4(res);
我正在使用采样器从纹理中采样:
constexpr sampler cubeSampler(filter::linear, mip_filter::none);
half4 res = cubeTexture.sample(cubeSampler, texVec);
结果是 half4 类型,但我需要将其转换为 float4 才能执行数学运算。我该如何执行此转换?
constexpr sampler cubeSampler(filter::linear, mip_filter::none);
half4 res = cubeTexture.sample(cubeSampler, texVec);
// cast to float4:
float4 res_float4 = static_cast<float4>(res);
static_cast
有效,或者您可以使用更简洁的转换构造函数:
float4 res_float4 = float4(res);