コード例 #1
0
        public static void childTracer(object data)
        {
            int offset = (int)data;


            int nx = rc.getNumXPixels();
            int ny = rc.getNumYPixels();
            int ns = rc.getNumSamples();

            int coreNum = offset + 1;

            Console.WriteLine("starting thread " + coreNum + " of " + numThreads);



            Vec3 col = new Vec3(0.0f, 0.0f, 0.0f);


            for (int j = ny - 1; j >= 0; j--)
            {
                for (int i = offset; i < nx; i += numThreads)
                {
                    for (int s = 0; s < ns; s++)
                    {
                        float u = (float)((float)i + (ConfigParams.aliasing_on ? Rng.f() : 0.0f)) / (float)nx;
                        float v = (float)((float)j + (ConfigParams.aliasing_on ? Rng.f() : 0.0f)) / (float)ny;

                        col = color(Camera.get_ray(u, v), 0);

                        rc.addR(i, j, col.r());
                        rc.addG(i, j, col.g());
                        rc.addB(i, j, col.b());
                    }
                }

                progressList[offset] += 1;
            }


            Interlocked.Increment(ref threadCounter); // signal this thread has finished

            return;
        } // end childTracer
コード例 #2
0
        public static void writeToPng(string fileName, RayCanvas rc)
        {
            // X := width  :: col
            // Y := height :: row

            int width  = rc.getNumXPixels();
            int height = rc.getNumYPixels();


            WriteableBitmap wbitmap = new WriteableBitmap(
                width, height, 96, 96, PixelFormats.Bgra32, null);

            byte[, ,] pixels = new byte[height, width, 4];


            for (int col = 0; col < width; col++)
            {
                for (int row = 0; row < height; row++)
                {
                    //for (int i = 0; i < 3; i++)
                    //{
                    pixels[row, col, 3] = 255; // alpha?
                    //}

                    int ir = (int)(256 * rc.getR(col, height - row - 1));
                    int ig = (int)(256 * rc.getG(col, height - row - 1));
                    int ib = (int)(256 * rc.getB(col, height - row - 1));

                    if (ir > 255)
                    {
                        ir = 255;
                    }
                    if (ig > 255)
                    {
                        ig = 255;
                    }
                    if (ib > 255)
                    {
                        ib = 255;
                    }

                    pixels[row, col, 0] = (byte)ib;  // Blue first,   PixelFormats.Bgra32
                    pixels[row, col, 1] = (byte)ig;  // Green
                    pixels[row, col, 2] = (byte)ir;  // Red last
                }
            }



            // X := width  :: col
            // Y := height :: row

            byte[] pixels1d = new byte[height * width * 4];
            int    index    = 0;

            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        pixels1d[index++] = pixels[row, col, i];
                    }
                }
            }



            Int32Rect rect   = new Int32Rect(0, 0, width, height);
            int       stride = 4 * width;

            wbitmap.WritePixels(rect, pixels1d, stride, 0);


            string filePath = fileName;

            var fileStream = new FileStream(filePath, FileMode.Create);

            BitmapEncoder encoder = new PngBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(wbitmap));
            encoder.Save(fileStream);

            fileStream.Close();
        }