Erik Sapir
Erik Sapir

Reputation: 135

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?

Upvotes: 0

Views: 1654

Answers (2)

warrenm
warrenm

Reputation: 31782

static_cast works, or you can use the more terse converting constructor:

float4 res_float4 = float4(res);

Upvotes: 3

VB_overflow
VB_overflow

Reputation: 1773

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

// cast to float4:
float4 res_float4 =  static_cast<float4>(res);

Upvotes: 1

Related Questions