Пример #1
0
        } // FloatToRgbm

        #endregion

        #region RGBM To Float

        /// <summary>
        /// Decode from RGBM to float.
        /// </summary>
        /// <param name="rgbm">RGBM Gamma Color</param>
        /// <param name="maxRange">Maximum float value</param>
        public static Vector3 RgbmGammaToFloatLinear(Color rgbm, float maxRange)
        {
            Vector4 rgbmLinear = GammaLinearSpaceHelper.GammaToLinear(rgbm);

            rgbmLinear.W *= maxRange;

            rgbmLinear.X *= rgbmLinear.W;
            rgbmLinear.Y *= rgbmLinear.W;
            rgbmLinear.Z *= rgbmLinear.W;

            return new Vector3(rgbmLinear.X, rgbmLinear.Y, rgbmLinear.Z);
        } // RgbmToFloat
Пример #2
0
        /// <summary>
        /// Encode from float (linear) to RGBM (gamma).
        /// </summary>
        /// <param name="r">Red</param>
        /// <param name="g">Green</param>
        /// <param name="b">Blue</param>
        /// <param name="maxRange">Maximum float value</param>
        public static Color FloatLinearToRgbmGamma(float r, float g, float b, float maxRange)
        {
            // Catch negative numbers.
            r = Math.Max(0, r);
            g = Math.Max(0, g);
            b = Math.Max(0, b);
            float maxRgb = Math.Max(r, Math.Max(g, b));
            float m = Math.Min(maxRgb / maxRange, 1.0f); // Catch max above MaxRange.
            
            r = r / (m * maxRange); // between 0 to 1
            g = g / (m * maxRange); // between 0 to 1
            b = b / (m * maxRange); // between 0 to 1

            // From linear to gamma space. Gamma space stores better lower values.
            return GammaLinearSpaceHelper.LinearToGamma(new Vector4(r, g, b, m));
        } // FloatToRgbm