Exemplo n.º 1
0
        /// <summary>
        /// Checks the brightness of each pixel and returns a vector representing the average direction of the brightness. Also fills
        /// out a histogram since it's touching all the pixels anyhow.
        /// </summary>
        /// <param name="map">Where do we get our brightness information from?</param>
        /// <param name="face">Which face of the cubemap are we looking at right now?</param>
        /// <param name="mipLevel">Which mip-map level do we pull color data from? Generaly, we don't want to be parsing lots of pixels.</param>
        /// <param name="histogram">The histogram we're filling out</param>
        private static Vector3 GetWeightedDirection(Cubemap map, CubemapFace face, int mipLevel, ref Histogram histogram)
        {
            // TODO: Switch to nativeArray
            Color[] colors    = map.GetPixels(face, mipLevel);
            int     width     = Mathf.Max(map.width >> mipLevel);
            float   texelSize = 2f / width;
            float   start     = -1f + texelSize / 2f;
            float   scale     = 1f / (width * width);

            Vector3 result = Vector3.zero;

            for (int y = 0; y < width; y++)
            {
                float yP = -(start + texelSize * y);
                for (int x = 0; x < width; x++)
                {
                    float xP        = start + texelSize * x;
                    Color color     = colors[x + y * width];
                    float intensity = color.grayscale;
                    histogram.Add(color.r, color.g, color.b, intensity);

                    // TODO: get rid of this inner loop normalize
                    result += new Vector3(xP, yP, 1).normalized *intensity;
                }
            }
            return(result * scale);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks the cubemap for the average direction of the light! (not normalized) Fills out a histogram for color data as long as we're in there digging through all the pixels.
        /// </summary>
        public Vector3 GetWeightedDirection(ref Histogram histogram)
        {
            int mipLevel = (int)(Mathf.Log(map.width) / Mathf.Log(2)) - 2;

            return(GetWeightedDirection(map, mipLevel, ref histogram).normalized);
        }