0
$\begingroup$

I am doing some animation jobs. I need to pack some pivots into UV and then my shader can read them.

I need to pack 4 float3 into a float4. Therefore, I need to pack each float3 into a float.

These 4 float3 are (model space position1, direction1, model space position2, direction2). I know how to handle the directions because they are normalized. I can use something like:

 #define f3_f(c) (dot(round((c) * 255), float3(65536, 256, 1)))
 #define f_f3(f) (frac((f) / float3(16777216, 65536, 256)))

But How can I pack these positions? I am using SM3.0 and I can't use bitwise operations

$\endgroup$
  • 2
    $\begingroup$ In general you cannot store $N$ bytes into $\frac{N}{3}$ bytes without some form of lossy compression. Depending on the different needs, assumptions, and constraints, entirely different compression methods may be adequate. $\endgroup$ – lightxbulb Dec 31 '19 at 12:07
  • $\begingroup$ Unit directions can always be represented in two floats (longitude & latitude), and you could store them quantized as a pair of half-floats. Does one of your directions point toward the other position? If that's true, you could store one position as 3 half-floats, and the other position as a half-float distance. That would be a total of 8 half floats, or 1 float4. $\endgroup$ – David Jan 1 '20 at 20:11
  • $\begingroup$ Are you sure you cannot add more attributes? you should have up to 16 vec4s worth of attribute space for the vertex shader input data. $\endgroup$ – ratchet freak Jan 3 '20 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.