[fpc-pascal] Float packing

Ryan Joseph ryan at thealchemistguild.com
Sun Nov 5 10:10:13 CET 2017


I’m trying to pass a value between 1-1000 to an GLSL shader program which only supports floats with a precision of 1 decimal place so the plan is to pack the value into a vec4 (RGBA components between 0-1) which I could decode in the shader program.

For example if I want to encode the value 50 I do: 50/1000 = 0.050 and get a value with 3 decimal places which could fit into an RGB value,

but how can I extract the decimal places? I think it has something to do bit shifting but I wasn’t able to figure it out. The final result should be:

r = 0
g = 5
b = 0


Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list