Esempio n. 1
0
        public static void projectCubeBuffer(ref 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);
        }
Esempio n. 2
0
        public static void projectCubeBuffer(ref 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 );
        }
Esempio n. 3
0
        private static bool GUIToSky(ref Texture skyCube, ref bool skyHDR, mset.SHEncoding skySH, mset.CubemapGUI cubeGUI)
        {
            //cubeGUI -> sky
            bool    prevHDR   = cubeGUI.HDR;
            Texture prevInput = cubeGUI.input;

            cubeGUI.drawGUI();

            skyCube = cubeGUI.input;
            skyHDR  = cubeGUI.HDR;

            bool dirty = false;


            //copy spherical harmonics if they've changed
            if (cubeGUI.computeSH)
            {
                if (skySH != null)
                {
                    if (cubeGUI.SH == null)
                    {
                        skySH.clearToBlack();
                        dirty = true;
                    }
                    else if (!skySH.equals(cubeGUI.SH))
                    {
                        skySH.copyFrom(cubeGUI.SH);
                        dirty = true;
                    }
                    skySH.copyToBuffer();
                }
            }


            //return true if the cubeGUI gui changed any parameters
            dirty |= prevHDR != cubeGUI.HDR;
            dirty |= prevInput != cubeGUI.input;
            return(dirty);
        }
Esempio n. 4
0
 public void projectToSH(ref SHEncoding SH)
 {
     updateBuffers();
     SH.clearToBlack();
     SHUtil.projectCubeBuffer(ref SH, this.buffers[0]);
 }