Exemplo n.º 1
0
 internal void RenderPixel(int x, int y, SamplerBase sampler, Scene scene)
 {
     for (int k = 0; k < sampler.numSamples; k++)
     {
         var sample = sampler.Sample();
         Ray ray    = GetRayFromPixel(x + sample.x, y + sample.y);
         m_RenderTarget.SetPixel(x, y, scene.tracer.Tracing(ray, scene.sky, sampler));
     }
 }
Exemplo n.º 2
0
        protected override IRenderResult OnRenderDebugSinglePixel(int x, int y, RenderConfig config)
        {
            CameraBase camera = m_Scene.camera;

            if (camera == null)
            {
                throw new System.ArgumentNullException();
            }

            Texture result = new Texture(config.width, config.height);

            result.Fill(Color.black);

            var sampler = SamplerFactory.Create(config.samplerType, config.numSamples, config.numSets);

            camera.SetRenderTarget(result);


            Color col = Color.black;

            sampler.ResetSampler(); //重置采样器状态
            while (sampler.NextSample())
            {
                Ray ray = m_Scene.camera.GetRay(x, y, sampler);
                col += this.PathTracing(ray, sampler);
            }

            col /= sampler.numSamples;

            col.a = 1.0f;
            result.SetPixel(x, y, col);

            return(result);
        }
Exemplo n.º 3
0
        //public void SetPixel(int x, int y, Color color)
        //{
        //    int i = x - m_X;
        //    int j = y - m_Y;
        //    m_Colors[j * m_TileWidth + i] = color;
        //}

        //public Color GetPixel(int i, int j)
        //{
        //    return m_Colors[j * m_TileWidth + i];
        //}

        public bool ApplyToRenderResult(IRenderResult result)
        {
            Texture texture = result as Texture;

            if (texture != null)
            {
                //for(int i=0;i< m_TileWidth; i++)
                //{
                //    for(int j=0;j< m_TileHeight; j++)
                //    {
                //        Color color = m_Colors[j * m_TileWidth + i];
                //        texture.SetPixel(m_X + i, m_Y + j, color);
                //    }
                //}
                texture.SetPixel(m_X, m_Y, m_Color);
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public static Texture Create(string path)
        {
            if (!System.IO.File.Exists(path))
            {
                return(null);
            }
            var img = new System.Drawing.Bitmap(Image.FromFile(path));

            Texture tex = new Texture(img.Width, img.Height);

            for (int i = 0; i < img.Width; i++)
            {
                for (int j = 0; j < img.Height; j++)
                {
                    var   c   = img.GetPixel(i, j);
                    Color col = new Color(((float)c.R) / 255.0f, ((float)c.G) / 255.0f, ((float)c.B) / 255.0f,
                                          ((float)c.A) / 255.0f);
                    tex.SetPixel(img.Width - 1 - i, img.Height - 1 - j, col);
                }
            }

            return(tex);
        }
Exemplo n.º 5
0
        public static Texture Create(string path, float gamma)
        {
            if (!System.IO.File.Exists(path))
            {
                return(null);
            }
            if (!FreeImage.IsAvailable())
            {
                return(null);
            }

            FIBITMAP dib = new FIBITMAP();

            dib = FreeImage.LoadEx(path);
            if (dib.IsNull)
            {
                return(null);
            }
            var bpp = FreeImage.GetBPP(dib);

            if (bpp != 24 && bpp != 32 && bpp != 96 && bpp != 8)
            {
                FreeImage.UnloadEx(ref dib);
                return(null);
            }
            uint w = FreeImage.GetWidth(dib);
            uint h = FreeImage.GetHeight(dib);

            Texture tex = new Texture(w, h);

            for (int i = 0; i < h; i++)
            {
                if (bpp == 8)
                {
                    Scanline <Byte> scanline = new Scanline <Byte>(dib, i);

                    Byte[] data = scanline.Data;
                    for (int j = 0; j < data.Length; j++)
                    {
                        var   gray  = data[j];
                        Color color = Color.Color32(gray, gray, gray);
                        color.Gamma(gamma);
                        tex.SetPixel(j, i, color);
                    }
                }
                else if (bpp == 24)
                {
                    Scanline <RGBTRIPLE> scanline = new Scanline <RGBTRIPLE>(dib, i);

                    RGBTRIPLE[] data = scanline.Data;
                    for (int j = 0; j < data.Length; j++)
                    {
                        var   red   = data[j].rgbtRed;
                        var   green = data[j].rgbtGreen;
                        var   blue  = data[j].rgbtBlue;
                        Color color = Color.Color32(red, green, blue);
                        color.Gamma(gamma);
                        tex.SetPixel(j, i, color);
                    }
                }
                else if (bpp == 32)
                {
                    Scanline <RGBQUAD> scanline = new Scanline <RGBQUAD>(dib, i);

                    RGBQUAD[] data = scanline.Data;

                    for (int j = 0; j < data.Length; j++)
                    {
                        var   red   = data[j].rgbRed;
                        var   green = data[j].rgbGreen;
                        var   blue  = data[j].rgbBlue;
                        var   alpha = data[j].rgbReserved;
                        Color color = Color.Color32(red, green, blue, alpha);
                        color.Gamma(gamma);
                        tex.SetPixel(j, i, color);
                    }
                }
                else if (bpp == 96)
                {
                    Scanline <FIRGBF> scanline = new Scanline <FIRGBF>(dib, i);

                    FIRGBF[] data = scanline.Data;

                    for (int j = 0; j < data.Length; j++)
                    {
                        var   red   = data[j].red;
                        var   green = data[j].green;
                        var   blue  = data[j].blue;
                        Color color = new Color(red, green, blue);
                        tex.SetPixel(j, i, color);
                    }
                }
            }

            return(tex);
        }