Exemplo n.º 1
0
    protected virtual void Start()
    {
        ppmTexture.Init(200, 100);

        RTRay   ray              = new RTRay();
        Vector3 origin           = Vector3.zero;
        Vector3 leftBottomCorner = new Vector3(-2, -1, -1);
        Vector3 horizontal       = new Vector3(4, 0, 0);
        Vector3 vertical         = new Vector3(0, 2, 0);

        for (int j = 0; j < ppmTexture.Height; ++j)
        {
            for (int i = 0; i < ppmTexture.Width; ++i)
            {
                float u = (float)i / ppmTexture.Width;
                float v = (float)j / ppmTexture.Height;
                ray.Set(origin, leftBottomCorner + horizontal * u + vertical * v);
                Color color = GetColor(ray, 0);
                ppmTexture.WriteAPixel(color);
            }
        }

        ppmTexture.Complete();
        RenderingComplete();
    }
Exemplo n.º 2
0
    protected override void Start()
    {
        ppmTexture = new PPMTexture();
        ppmTexture.Init(200, 100);

        for (int j = 0; j < ppmTexture.Height; ++j)
        {
            for (int i = 0; i < ppmTexture.Width; ++i)
            {
                float r = (float)i / ppmTexture.Width;
                float g = (float)j / ppmTexture.Height;
                float b = 0.2f;
                ppmTexture.WriteAPixel(r, g, b);
            }
        }

        ppmTexture.Complete();
    }
Exemplo n.º 3
0
    protected virtual void Start()
    {
        int canvasWidth  = isScreenSize ? Screen.width : 200;
        int canvasHeight = isScreenSize ? Screen.height : 100;

        cam = CreateCamera(canvasWidth, canvasHeight);
        ppmTexture.Init(canvasWidth, canvasHeight);

        renderingTasksManager = new RenderingTasksManager();

        int           pixelIndex = 0;
        RenderingTask task       = null;
        int           itemsCount = 0;

        for (int j = 0; j < ppmTexture.Height; ++j)
        {
            for (int i = 0; i < ppmTexture.Width; ++i)
            {
                if (multiThreadRendering)
                {
                    if (itemsCount == 0)
                    {
                        task = new RenderingTask();
                        task.Init(this, cam, ppmTexture.Width, ppmTexture.Height, numSamples);
                        renderingTasksManager.AddTask(task, RenderingTaskCompleteCB);
                    }
                    task.AddItem(i, j, pixelIndex);
                    ++itemsCount;
                    if (itemsCount == RenderingTask.SIZE)
                    {
                        itemsCount = 0;
                    }
                    ++pixelIndex;
                }
                else
                {
                    Color color = Color.black;
                    for (int s = 0; s < numSamples; ++s)
                    {
                        float u = (i + RTMath.Rnd01()) / ppmTexture.Width;
                        float v = (j + RTMath.Rnd01()) / ppmTexture.Height;

                        RTRay ray = cam.GetRay(u, v);
                        color += GetColor(ray, 0);
                    }
                    color /= numSamples;
                    ppmTexture.WriteAPixel(color);
                }
            }
        }

        if (!multiThreadRendering)
        {
            ppmTexture.Complete();
            RenderingComplete();
        }
        else
        {
            renderingTasksManager.Start();
        }
    }