cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

bubu
Adept II

float3 from float4

What's the correct way to downcast a float4 into a float3 discarding the .w component, pls?

 

float4 b;

 

1. float3 a = as_float3(b); //this should be ok

2. float3 a = (float3)b; //I'm not sure about this

3. float3 a = (float3)(b.x,b.y,b.z); //obviously ok, but I want it simpler.

0 Likes
5 Replies

I would recommend using as_float3, it was provided for just this reason.
0 Likes

Originally posted by: MicahVillmow I would recommend using as_float3, it was provided for just this reason.


Thanks.

 

Btw, it's the #2 option legal? Just by curiosity.

0 Likes

Originally posted by: bubu
Originally posted by: MicahVillmow I would recommend using as_float3, it was provided for just this reason.


 

 

 

 

Btw, it's the #2 option legal? Just by curiosity.

 

Option #2 is not legal as per the spec.

0 Likes

Ok, thanks, all is clear now.

0 Likes

you can also do:

float 3 a = b.xyz;

float 3 a = b.s012;  // 1st, 2nd + 3nd terms (can use hex digit 0..F)

float 3 a = c.s7f3;  // 8th, 16th, 4rd term

or swizzle/duplicate the terms:

a = b.yzx;

a = b.xxz;

There's lots of examples of valid/invalid cases in the 1.1 spec in section 6.1.7

0 Likes