why do we should use EncodeFloatRG instead of >> operation

inline float2 EncodeFloatRG( float v )
{
float2 kEncodeMul = float2(1.0, 255.0);
float kEncodeBit = 1.0/255.0;
float2 enc = kEncodeMul * v;
enc = frac (enc);
enc.x -= enc.y * kEncodeBit;
return enc;
}
inline float DecodeFloatRG( float2 enc )
{
float2 kDecodeDot = float2(1.0, 1/255.0);
return dot( enc, kDecodeDot );
}
Why should we use the function like above instead of the operation of ‘<<’

Because bitwise operators only work with DX10+ or OpenGL 3.0+, and only with int or uint values. DX9 and OpenGL ES 2.0 do not support any bitwise operators, though OpenGL ES 3.0 adds the same support that OpenGL 3.0 has. And as far as I can tell Metal supports all bitwise operators except bit shifts.

1 Like

Thanks for your reply