Пример #1
0
        public static void projectCube(ref mset.SHEncoding sh, Cubemap cube, int mip, bool hdr)
        {
            sh.clearToBlack();
            float totalarea = 0f;

            ulong faceSize = (ulong)cube.width;

            mip      = Mathf.Min(mset.QPow.Log2i(faceSize) + 1, mip);
            faceSize = (ulong)(faceSize >> mip);
            float[] dc = new float[9];
            Vector3 u  = Vector3.zero;

            for (ulong face = 0; face < 6; ++face)
            {
                Color   rgba   = Color.black;
                Color[] pixels = cube.GetPixels((CubemapFace)face, mip);
                for (ulong y = 0; y < faceSize; ++y)
                {
                    for (ulong x = 0; x < faceSize; ++x)
                    {
                        //compute cube direction
                        float areaweight = 1f;
                        mset.Util.invCubeLookup(ref u, ref areaweight, face, x, y, faceSize);
                        float shscale = 4f / 3f;
                        ulong index   = y * faceSize + x;
                        if (hdr)
                        {
                            mset.RGB.fromRGBM(ref rgba, pixels[index], true);
                        }
                        else
                        {
                            rgba = pixels[index];
                        }

                        //project on basis functions, and accumulate
                        dc[0] = project_l0_m0(u);

                        dc[1] = project_l1_mneg1(u);
                        dc[2] = project_l1_m0(u);
                        dc[3] = project_l1_m1(u);

                        dc[4] = project_l2_mneg2(u);
                        dc[5] = project_l2_mneg1(u);
                        dc[6] = project_l2_m0(u);
                        dc[7] = project_l2_m1(u);
                        dc[8] = project_l2_m2(u);
                        for (int i = 0; i < 9; ++i)
                        {
                            sh.c[3 * i + 0] += shscale * areaweight * rgba[0] * dc[i];
                            sh.c[3 * i + 1] += shscale * areaweight * rgba[1] * dc[i];
                            sh.c[3 * i + 2] += shscale * areaweight * rgba[2] * dc[i];
                        }
                        totalarea += areaweight;
                    }
                }
            }

            //complete the integration by dividing by total area
            scale(ref sh, 16f / totalarea);
        }
Пример #2
0
        public static void projectCubeBuffer(ref mset.SHEncoding sh, CubeBuffer cube)
        {
            sh.clearToBlack();
            float totalarea = 0f;
            ulong faceSize  = (ulong)cube.faceSize;

            float[] dc = new float[9];
            Vector3 u  = Vector3.zero;

            for (ulong face = 0; face < 6; ++face)
            {
                for (ulong y = 0; y < faceSize; ++y)
                {
                    for (ulong x = 0; x < faceSize; ++x)
                    {
                        //compute cube direction
                        float areaweight = 1f;
                        mset.Util.invCubeLookup(ref u, ref areaweight, face, x, y, faceSize);
                        float shscale = 4f / 3f;
                        ulong index   = face * faceSize * faceSize + y * faceSize + x;
                        Color rgba    = cube.pixels[index];

                        //project on basis functions, and accumulate
                        dc[0] = project_l0_m0(u);

                        dc[1] = project_l1_mneg1(u);
                        dc[2] = project_l1_m0(u);
                        dc[3] = project_l1_m1(u);

                        dc[4] = project_l2_mneg2(u);
                        dc[5] = project_l2_mneg1(u);
                        dc[6] = project_l2_m0(u);
                        dc[7] = project_l2_m1(u);
                        dc[8] = project_l2_m2(u);
                        for (int i = 0; i < 9; ++i)
                        {
                            sh.c[3 * i + 0] += shscale * areaweight * rgba[0] * dc[i];
                            sh.c[3 * i + 1] += shscale * areaweight * rgba[1] * dc[i];
                            sh.c[3 * i + 2] += shscale * areaweight * rgba[2] * dc[i];
                        }
                        totalarea += areaweight;
                    }
                }
            }

            //complete the integration by dividing by total area
            scale(ref sh, 16f / totalarea);
        }