예제 #1
0
파일: RayTracer.cs 프로젝트: bmjoy/RTUT
    static private Texture2D rayTrace(Texture2D texture)
    {
        const int ns            = 100;
        var       world         = Util.random_scene();
        var       lookfrom      = new Vector3(12, 2, 3);
        var       lookat        = new Vector3(0, 0.5f, 0);
        var       dist_to_focus = (lookfrom - lookat).magnitude;
        var       aperture      = 0.1f;
        var       cam           = new camera(lookfrom, lookat, new Vector3(0, 1, 0), 20, (float)texture.width / texture.height, aperture, dist_to_focus);

        for (var j = texture.height - 1; j >= 0; j--)
        {
            for (var i = 0; i < texture.width; i++)
            {
                var col = Color.black;
                for (var s = 0; s < ns; s++)
                {
                    var u = (i + Random.Range(0f, 1f - float.Epsilon)) / texture.width;
                    var v = (j + Random.Range(0f, 1f - float.Epsilon)) / texture.height;
                    var r = cam.get_ray(u, v);
                    col += color(r, world, 0);
                }
                col /= ns;
                col  = new Color(Mathf.Sqrt(col.r), Mathf.Sqrt(col.g), Mathf.Sqrt(col.b));
                texture.SetPixel(i, j, col);
            }
        }

        return(texture);
    }