I need to pass normal vector for a cube to shader using single float. no need to worry about precision as for a cube all normal vector components can be only -1,0,1 so one byte of a single will remain unused. I was trying to do it like that but the signs are messing up the float or sth
Code:
procedure packNormal(var a:single;x,y,z:smallint);
begin
a:=(x << 16) or ( y << 8) or z;
end;
//test
procedure unpackNormal(a:single;var x,y,z:smallint);
begin
x:=round(a) div 65536;
y:=round(a) div 256;
z:=round(a) mod 1;
end;
I guess I could use individual bits to encode the values but i feel like missing something obvious
maybe someone done something like that before?
Bookmarks