threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

color-encodings.ts 961B

1234567891011121314151617181920212223242526
  1. import {Color, Vector4} from 'three'
  2. // todo: move these to ts-browser-helpers maybe
  3. // reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html
  4. export function vRGBMToLinear(value: Vector4, maxRange: number): Vector4 {
  5. value.multiplyScalar(value.w * maxRange)
  6. value.w = 1.0
  7. return value
  8. }
  9. export function cRGBMToLinear(value: Vector4, maxRange: number): Color {
  10. vRGBMToLinear(value, maxRange)
  11. return new Color(value.x, value.y, value.z)
  12. }
  13. export function vLinearToRGBM(value: Vector4, maxRange: number): Vector4 {
  14. const maxRGB = Math.max(value.x, Math.max(value.y, value.z))
  15. let M = Math.max(Math.min(maxRGB / maxRange, 1.0), 0.0)
  16. M = Math.ceil(M * 255.0) / 255.0
  17. value.divideScalar(M * maxRange)
  18. value.w = M
  19. return value
  20. }
  21. export function cLinearToRGBM(value: Color, maxRange: number): Vector4 {
  22. return vLinearToRGBM(new Vector4(value.r, value.g, value.b, 1.0), maxRange)
  23. }