예제 #1
0
        public static byte FinalizeColor(float pixelColor, int samplesPerPixel)
        {
            var c = pixelColor;

            // Replace NaN components with zero. See explanation in Ray Tracing: The Rest of Your Life.
            if (float.IsNaN(c))
            {
                c = 0.0f;
            }

            // Divide the color by the number of samples and gamma-correct for gamma=2.0.
            var scale = 1.0f / samplesPerPixel;

            c = MathF.Sqrt(scale * c);

            // return the translated [0,255] value of each color component.
            return(Convert.ToByte(255 * MathR.Clamp(c, 0.0f, 0.999f)));
        }
예제 #2
0
        public static byte[] FinalizeColor(Vec3 pixelColor, int samplesPerPixel)
        {
            (var r, var g, var b) = pixelColor;

            // Replace NaN components with zero. See explanation in Ray Tracing: The Rest of Your Life.
            //if (r != r) r = 0.0f;
            //if (g != g) g = 0.0f;
            //if (b != b)  b = 0.0f;

            // Divide the color by the number of samples and gamma-correct for gamma=2.0.
            var scale = 1.0f / samplesPerPixel;

            r = MathF.Sqrt(scale * r);
            g = MathF.Sqrt(scale * g);
            b = MathF.Sqrt(scale * b);

            // return the translated [0,255] value of each color component.
            return(new[] {
                Convert.ToByte(255 * MathR.Clamp(r, 0.0f, 0.999f)),
                Convert.ToByte(255 * MathR.Clamp(g, 0.0f, 0.999f)),
                Convert.ToByte(255 * MathR.Clamp(b, 0.0f, 0.999f))
            });
        }