Search code examples
iosshadermetal

iOS Metal: casting half4 variable to float4 type


I am using a sampler to sample from texture:

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

The result is of type half4 but i need to cast it to float4 in order to perform math operations. How can i perform this cast?


Solution

  • constexpr sampler cubeSampler(filter::linear, mip_filter::none);
    half4 res = cubeTexture.sample(cubeSampler, texVec);
    
    // cast to float4:
    float4 res_float4 =  static_cast<float4>(res);