ColorSpace.bslinc 906 B

12345678910111213141516171819202122232425262728293031323334353637
  1. mixin ColorSpace
  2. {
  3. code
  4. {
  5. /**
  6. * Converts a color in RGB space into YCoCg color space. Note that Co and Cg
  7. * components are in [-0.5, 0.5] range and therefore cannot be stored as-is
  8. * in a normal color texture.
  9. */
  10. float3 RGBToYCoCg(float3 input)
  11. {
  12. float Y = dot(input, float3(0.25f, 0.5f, 0.25f));
  13. float Co = input.r * 0.5f + input.b * -0.5f;
  14. float Cg = dot(input, float3(-0.25f, 0.5f, -0.25f));
  15. return float3(Y, Co, Cg);
  16. }
  17. /**
  18. * Converts a color in YCoCg color space into RGB color space.
  19. */
  20. float3 YCoCg(float3 input)
  21. {
  22. float R = input.r + input.g - input.b;
  23. float G = input.r + input.b;
  24. float B = input.r - input.g - input.b;
  25. return float3(R, G, B);
  26. }
  27. /** Calculates luminance from a color in RGB color space. */
  28. float LuminanceRGB(float3 input)
  29. {
  30. return 0.299f * input.r + 0.587f * input.g + 0.114f * input.b;
  31. }
  32. };
  33. };