Beispiel #1
0
    private void preCompute(int i)
    {
        Vector3 position = SHMeshObject.vertices[i];
        Vector3 normal   = SHMeshObject.normals[i];

        Vector2[] randomVec = MCIntegrator(maxSamples);

        float[] result = new float[maxPower];
        for (int j = 0; j < maxPower; j++)
        {
            result [j] = 0.0f;
        }

        for (int j = 0; j < maxSamples; j++)
        {
            Vector3 tempDir = tranfer(randomVec[j].x, randomVec[j].y);
            float   csn     = Mathf.Clamp01(Vector3.Dot(tempDir.normalized, normal.normalized));
            float   shadow  = RayCast(position, tempDir);
            for (int k = 0; k < maxPower; k++)
            {
                int l = 0;
                int m = 0;
                SHFunc.tranferK(k, ref l, ref m);
                float y = SHFunc.SH(l, m, randomVec[j].x, randomVec[j].y);
                result [k] += y * shadow * csn * albedo;
            }
        }

        float factor = 4.0f * Mathf.PI / maxSamples;

        for (int j = 0; j < maxPower; j++)
        {
            AllIntegratorTasks [i].coffeeSHResult [j] = result [j] * factor;
        }
    }
Beispiel #2
0
    void Start()
    {
        int allTaskNum = SHMeshObject.vertexCount;

        AllIntegratorTasks = new IntegratorTask[allTaskNum];
        int tempIndex = 0;

        for (int j = 0; j < SHMeshObject.vertexCount; j++)
        {
            AllIntegratorTasks[j].coffeeSHResult = new float[maxPower];
        }

        SHFunc.Init();

        for (int i = 0; i < allTaskNum; i++)
        {
            preCompute(i);
        }

        Output();
    }