Exemple #1
0
        /* Calculate light scattering value at point */
        private CalculatedInscatter CalculateForPoint(Vector2 point)
        {
            Vector2 closestPoint = GetClosestColourNeighbour((int)point.x, (int)point.y);
            double  sigma_s      = GetSigmaFromClassified(point);

            HDRPixelFloat thisColour  = originalSkyImage.GetPixel((int)point.x, (int)point.y).AsFloat();
            HDRPixelFloat closeColour = originalSkyImage.GetPixel((int)closestPoint.x, (int)closestPoint.y).AsFloat();
            HDRPixelFloat thisBG      = backgroundSkyImage.GetPixel((int)point.x, (int)point.y).AsFloat();
            HDRPixelFloat closeBG     = backgroundSkyImage.GetPixel((int)closestPoint.x, (int)closestPoint.y).AsFloat();

            CalculatedInscatter toReturn = new CalculatedInscatter();

            double da_r = CalculateDaForColour(thisColour.R, closeColour.R, thisBG.R, closeBG.R, sigma_s);
            double da_g = CalculateDaForColour(thisColour.G, closeColour.G, thisBG.G, closeBG.G, sigma_s);
            double da_b = CalculateDaForColour(thisColour.B, closeColour.B, thisBG.B, closeBG.B, sigma_s);

            toReturn.da = (da_r + da_g + da_b) / 3;

            float Lia_r = (float)CalculateLiaForColour(thisColour.R, thisBG.R, toReturn.da, sigma_s);
            float Lia_g = (float)CalculateLiaForColour(thisColour.G, thisBG.G, toReturn.da, sigma_s);
            float Lia_b = (float)CalculateLiaForColour(thisColour.B, thisBG.B, toReturn.da, sigma_s);

            toReturn.Lia = new Vector3(Lia_r, Lia_g, Lia_b);

            return(toReturn);
        }
Exemple #2
0
        /* Get the closest colour value within a radius of a pixel */
        private Vector2 GetClosestColourNeighbour(int initialX, int initialY, int radius = 5)
        {
            HDRPixelFloat targetColour       = originalSkyImage.GetPixel(initialX, initialY).AsFloat();
            float         closestColourMatch = int.MaxValue;
            Vector2       closestMatchPos    = new Vector2(0, 0);

            for (int x = initialX - radius; x < initialX + radius; x++)
            {
                for (int y = initialY - radius; y < initialY + radius; y++)
                {
                    if (x == initialX && y == initialY)
                    {
                        continue;
                    }
                    if (x < 0 || y < 0)
                    {
                        continue;
                    }
                    if (x >= originalSkyImage.Width || y >= originalSkyImage.Height)
                    {
                        continue;
                    }

                    HDRPixelFloat thisColour     = originalSkyImage.GetPixel(x, y).AsFloat();
                    float         thisColourDiff = ColourDiff(targetColour, thisColour);
                    if (thisColourDiff < closestColourMatch)
                    {
                        closestMatchPos.x  = x;
                        closestMatchPos.y  = y;
                        closestColourMatch = thisColourDiff;
                    }
                }
            }
            return(closestMatchPos);
        }
        public HDRPixelFloat AsFloat()
        {
            HDRPixelFloat asFloat = new HDRPixelFloat();

            asFloat.FromRGBE(R, G, B, E);
            return(asFloat);
        }
Exemple #4
0
        /* Get the difference in colour values between two given colours */
        private float ColourDiff(HDRPixelFloat colour1, HDRPixelFloat colour2)
        {
            float r = colour1.R - colour2.R;

            if (r < 0)
            {
                r *= -1;
            }
            float g = colour1.G - colour2.G;

            if (g < 0)
            {
                g *= -1;
            }
            float b = colour1.B - colour2.B;

            if (b < 0)
            {
                b *= -1;
            }
            return(r + g + b);
        }