Jump to content

RGBA to Float


Go to solution Solved by SpiderPig,

Recommended Posts

Posted

I have packed integers and floats into a texture to use in my shader.  Information is packed into the texture by poking a buffer and then assigning that buffer to an RGBA texture.  The following code extracts an integer from a texelFetch result in the fragment shader.  It seems to work well.

int BytesToInteger( in vec4 pixel ) {
	return ( int( ( pixel.w * 255.0f ) ) << 24 ) | ( int( ( pixel.z * 255.0f ) ) << 16 ) | ( int( ( pixel.y * 255.0f ) ) << 8 ) | int( ( pixel.x * 255.0f ) );
}

However the same process does not work for floats and I'm sure there is a reason why but I can't figure it out.  Any one know the answer? <_<

float BytesToFloat( in vec4 pixel ) {
	return float( ( int( ( pixel.w * 255.0f ) ) << 24 ) | ( int( ( pixel.z * 255.0f ) ) << 16 ) | ( int( ( pixel.y * 255.0f ) ) << 8 ) | int( ( pixel.x * 255.0f ) ) );
}

 

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.

×
×
  • Create New...