コード例 #1
0
ファイル: MonteCarloRT.cs プロジェクト: Popa611/grcis
        /// <summary>
        /// Renders the single pixel of an image (using required super-sampling).
        /// </summary>
        /// <param name="x">Horizontal coordinate.</param>
        /// <param name="y">Vertical coordinate.</param>
        /// <param name="color">Computed pixel color.</param>
        public override void RenderPixel(int x, int y, double[] color)
        {
            Debug.Assert(color != null);
            Debug.Assert(MT.rnd != null);

            // !!!{{ TODO: this is exactly the code inherited from static sampling - make it adaptive!

            int bands = color.Length;
            int b;

            Array.Clear(color, 0, bands);
            double[] tmp = new double[bands];

            int    i, j;
            double step = 1.0 / superXY;
            double amplitude = Jittering * step;
            double origin = 0.5 * (step - amplitude);
            double x0, y0;

            MT.StartPixel(x, y, Supersampling);

            for (j = 0, y0 = y + origin; j++ < superXY; y0 += step)
            {
                for (i = 0, x0 = x + origin; i++ < superXY; x0 += step)
                {
                    ImageFunction.GetSample(x0 + amplitude * MT.rnd.UniformNumber(),
                                            y0 + amplitude * MT.rnd.UniformNumber(),
                                            tmp);
                    MT.NextSample();
                    for (b = 0; b < bands; b++)
                    {
                        color[b] += tmp[b];
                    }
                }
            }

            double mul = step / superXY;

            if (Gamma > 0.001)
            {
                // gamma-encoding and clamping
                double g = 1.0 / Gamma;
                for (b = 0; b < bands; b++)
                {
                    color[b] = Arith.Clamp(Math.Pow(color[b] * mul, g), 0.0, 1.0);
                }
            }
            else
            {
                // no gamma, no clamping (for HDRI)
                for (b = 0; b < bands; b++)
                {
                    color[b] *= mul;
                }
            }

            // !!!}}
        }
コード例 #2
0
ファイル: RayCastingBasic.cs プロジェクト: EbrithilNogare/mff
        /// <summary>
        /// Renders the single pixel of an image.
        /// </summary>
        /// <param name="x">Horizontal coordinate.</param>
        /// <param name="y">Vertical coordinate.</param>
        /// <param name="color">Computed pixel color.</param>
        public virtual void RenderPixel(int x, int y, double[] color)
        {
            MT.StartPixel(x, y, 1);
            ImageFunction.GetSample(x + 0.5, y + 0.5, color);

            // Gamma-encoding.
            if (Gamma > 0.001)
            {
                // Gamma-encoding and clamping.
                double g = 1.0 / Gamma;
                for (int b = 0; b < color.Length; b++)
                {
                    color[b] = Arith.Clamp(Math.Pow(color[b], g), 0.0, 1.0);
                }
            }

            // else: no gamma, no clamping (for HDRI)
        }