Example #1
0
    private void InitRender()
    {
        int nx       = Screen.width;
        int ny       = Screen.height;
        int rayCount = nx * ny * ns;

        raysBuffer  = new NativeArray <jRay>(rayCount, Allocator.Persistent);
        raysBuffer1 = new NativeArray <jRay>(rayCount, Allocator.Persistent);

        zCamera zcam  = new zCamera(cam);
        uint    index = 0;

        for (int j = ny - 1; j >= 0; j--)
        {
            for (int i = 0; i < nx; i++)
            {
                for (int s = 0; s < ns; s++)
                {
                    float u = (float)(i + zRandom.Halton5(index++)) / (float)(nx);
                    float v = (float)(j + zRandom.Halton5(index++)) / (float)(ny);
                    raysBuffer[(j * nx + i) * ns + s]  = zcam.get_jobRay(u, v);
                    raysBuffer1[(j * nx + i) * ns + s] = zcam.get_jobRay(u, v);
                }
            }
        }

        JobGlobal.currentDepth = 0;
        JobGlobal.envColor     = env_Color;

        OnRenderComplete += () => {
            OutputRenderResult();
        };
    }
    IEnumerator Render()
    {
        int nx = Screen.width;
        int ny = Screen.height;

        progress   = 0f;
        startTime  = time();
        renderDone = false;

        Vector3 lookFrom      = new Vector3(1f, 2f, 2f);
        Vector3 lookAt        = new Vector3(0f, 0f, -1f);
        float   dist_to_focus = 2f;
        float   aperture      = 0f;
        zCamera zcam          = new zCamera(cam);
        uint    index         = 0;

        if (debugMod)
        {
            Color col = Color.black;
            for (int s = 0; s < 1; s++)
            {
                float u = (float)((int)debugPoint.x + zRandom.Halton5(index++)) / (float)(nx);
                float v = (float)((int)debugPoint.y + zRandom.Halton5(index++)) / (float)(ny);
                zRay  r = zcam.get_ray(u, v);
                DebugDrawer.Init(cam);
                col += color(r, world, 0);
            }
        }
        else
        {
            for (int j = ny - 1; j >= 0; j--)
            {
                Color col = Color.black;
                for (int i = 0; i < nx; i++)
                {
                    for (int s = 0; s < ns; s++)
                    {
                        float u = (float)(i + zRandom.Halton5(index++)) / (float)(nx);
                        float v = (float)(j + zRandom.Halton5(index++)) / (float)(ny);
                        zRay  r = zcam.get_ray(u, v);
                        col += color(r, world, 0);
                    }
                    col /= (float)ns;
                    col  = col.gamma;
                    rtResult.SetPixel(rtResult.width - i, j, col);
                }
                progress += nx;
                yield return(null);
            }
            rtResult.Apply();
            renderDone = true;
            timePassed = time();
        }
        yield return(null);
    }