Jump to content

Compress a vec3 into a vec2


Josh
 Share

Recommended Posts

I didn't end up using this, but here's an interesting bit of code that can be used to compress an RGB color into two components. Does not work with blending:

vec2 toRGB565(in vec3 c)
{
ivec2 outcInt = ivec2(c.rb * 31.0);
int green = int(c.g*63.0);
ivec2 LOHI = ivec2(green & 7,green >> 3);
LOHI <<= ivec2(5);
return (vec2(outcInt | LOHI) / 255.0);
}

vec3 fromRGB565(in vec2 c)
{
vec3 outc;
ivec2 cInt = ivec2(c*255.0);
ivec2 cIntMod = cInt & 31;
outc.rb = vec2(cIntMod) / 31.0;
ivec2 gComps = cInt>>5;
outc.g = float(gComps.x | (gComps.y<<3)) / 63.0;
return outc;
}

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...