Exemplo n.º 1
0
        private int Scan()
        {
            var camera       = new Camera(new Vector3(0, 0, 1), new Vector3(0, 0, -1), new Vector3(0, 1, 0), 75, 1);
            var recip_width  = 1f / Width;
            var recip_height = 1f / Height;

            for (j = 0; j < Height; j++)
            {
                for (i = 0; i < Width; i++)
                {
                    var color = new Color32(0, 0, 0, 0);
                    for (var s = 0; s < Samples; s++)
                    {
                        color += mode == Mode.Diffusing
                        ? Diffusing(camera.CreateRay(
                                        (i + Random.Range(0, 1f)) * recip_width,
                                        (j + Random.Range(0, 1f)) * recip_height), hitableList, 0)
                        : NormalMap(camera.CreateRay(
                                        (i + Random.Range(0, 1f)) * recip_width,
                                        (j + Random.Range(0, 1f)) * recip_height), hitableList);
                    }
                    color /= Samples;
                    color *= 1f;
                    buff.SetPixel(i, Height - j - 1, color.ToSystemColor());
                }
            }

            return(0);
        }
Exemplo n.º 2
0
        public Vector3 GetRandomPointInUnitSphere()
        {
            var p = new Vector3(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)) * 2f - Vector3.one;

            return(p.Normalized() * Random.Range(0f, 1f));
        }