Common.cginc 629 B

12345678910111213141516171819202122
  1. // Pcx - Point cloud importer & renderer for Unity
  2. // https://github.com/keijiro/Pcx
  3. #define PCX_MAX_BRIGHTNESS 16
  4. uint PcxEncodeColor(half3 rgb)
  5. {
  6. half y = max(max(rgb.r, rgb.g), rgb.b);
  7. y = clamp(ceil(y * 255 / PCX_MAX_BRIGHTNESS), 1, 255);
  8. rgb *= 255 * 255 / (y * PCX_MAX_BRIGHTNESS);
  9. uint4 i = half4(rgb, y);
  10. return i.x | (i.y << 8) | (i.z << 16) | (i.w << 24);
  11. }
  12. half3 PcxDecodeColor(uint data)
  13. {
  14. half r = (data ) & 0xff;
  15. half g = (data >> 8) & 0xff;
  16. half b = (data >> 16) & 0xff;
  17. half a = (data >> 24) & 0xff;
  18. return half3(r, g, b) * a * PCX_MAX_BRIGHTNESS / (255 * 255);
  19. }