示例#1
0
    void DrawPicture()
    {
        int            sampleCount = 1;
        Hitable        sphere1     = new Sphere(new Vector3(0, 0, -1), 0.5f);
        Hitable        sphere2     = new Sphere(new Vector3(0, -100.5f, -1), 100);
        List <Hitable> hitList     = new List <Hitable>();

        hitList.Add(sphere1);
        hitList.Add(sphere2);
        Hitable   world  = new HitableList(hitList);
        CameraRay camRay = new CameraRay();

        for (int i = 0; i < screenWidth; ++i)
        {
            for (int j = 0; j < screenHeight; ++j)
            {
                Color c = Color.black;
                for (int k = 0; k < sampleCount; ++k)
                {
                    float t1 = Random.Range(0.0f, 1.0f);
                    float t2 = Random.Range(0.0f, 1.0f);
                    Ray   r  = camRay.GetRay((i + t1) / screenWidth, (j + t2) / screenHeight);
                    c += GetColor(r, world);
                }
                c = c / sampleCount;
                MoDraw.Instance.DrawPoint(new Vector2Int(i, j), c);
            }
        }
    }
示例#2
0
    public void Update(Scene scene)
    {
        if (sampleCount_ >= maxSampleNum_)
        {
            return;
        }
        --y_;
        if (y_ < 0)
        {
            y_ = height_ - 1;
            ++sampleCount_;
        }
        var alpha = 1.0f / sampleCount_;

        for (int x = 0; x < width_; ++x)
        {
            float u     = ((float)x + Util.UnitRandFloat()) / (float)width_;
            float v     = ((float)y_ + Util.UnitRandFloat()) / (float)height_;
            var   color = Util.ConvertToColor(scene.GetColor(cameraRay_.GetRay(u, v)));
            pixel_[x, y_] = Color.Lerp(pixel_[x, y_], color, alpha);
        }
    }