Пример #1
0
    public int GetInt(int x, int y, IntDataID id)
    {
        if (AreCoordinatesInvalid(x, y))
        {
            return(1);
        }

        PixelInformation info = GetPixelInformation(x, y);

        if (IsPixelInformationInvalid(info))
        {
            Debug.LogWarning("THigns went BAD " + info);
        }

        AreaIndex area = null;

        try
        {
            area = _areas[info.areaX, info.areaY];
        }
        catch (Exception e)
        {
            Debug.LogWarning("THigns went BAD " + e);
            info = GetPixelInformation(x, y);
        }

        switch (id)
        {
        case IntDataID.NoiseLayerData:
            return(area.DataLayer.NoiseLayerData.data[info.areaPixelX, info.areaPixelY]);
        }

        return(0);
    }
Пример #2
0
        private void CreateFramebuffers()
        {
            if (_downsampler != null)
            {
                _downsampler.ForEach(a => a.Reset());
            }
            if (_upsample != null)
            {
                _upsample.ForEach(a => a.Reset());
            }

            _downsampler = new List <Framebuffer>();
            _upsample    = new List <Framebuffer>();

            Vector2 windowSize = Pipeline.ConnectedWindow.WindowSize;

            float minDim     = (float)Math.Min(windowSize.X, windowSize.Y);
            float maxIter    = (Radius - 8.0f) + (float)(Math.Log(minDim) / Math.Log(2));
            int   maxIterInt = (int)maxIter;

            _iterations = Math.Max(Math.Min(MAXBLOOMSTEPS, maxIterInt), 1);

            _sampleSize     = .5f + maxIter - maxIterInt;
            _thresholdCurve = new Vector4(
                Threshold - Knee,
                Knee * 2,
                0.25f / Math.Max(1e-5f, Knee),
                Threshold);

            float intens = (Intensity * INTENSITY);

            _bloomColor = new Color4(Color.R * intens, Color.G * intens, Color.B * intens, 1f);

            PixelInformation pixel = new PixelInformation(PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.Float);

            Vector2     texSize = windowSize;
            Framebuffer f       = new Framebuffer(texSize);

            f.Append("0", new ColorAttachment(0, pixel));
            f.Append("1", new ColorAttachment(1, pixel));
            _downsampler.Add(f);
            for (int i = 0; i < _iterations; i++)
            {
                texSize /= 2;

                f = new Framebuffer(texSize);
                f.Append("0", new ColorAttachment(0, pixel));
                _downsampler.Add(f);

                if (i == _iterations - 1)
                {
                    break;
                }
                f = new Framebuffer(texSize);
                f.Append("0", new ColorAttachment(0, pixel));
                _upsample.Add(f);
            }
        }
Пример #3
0
    public void SetByte(int x, int y, byte value, ByteDataLyerID id)
    {
        PixelInformation info = GetPixelInformation(x, y);
        AreaIndex        area = _areas[info.areaX, info.areaY];

        switch (id)
        {
        case ByteDataLyerID.WaterLayerData:
            area.DataLayer.WaterLayerData.data[info.areaPixelX, info.areaPixelY] = value;
            break;
        }
    }
Пример #4
0
    public void SetInt(int x, int y, int value, IntDataID id)
    {
        PixelInformation info = GetPixelInformation(x, y);
        AreaIndex        area = _areas[info.areaX, info.areaY];

        switch (id)
        {
        case IntDataID.NoiseLayerData:
            area.DataLayer.NoiseLayerData.data[info.areaPixelX, info.areaPixelY] = value;
            break;
        }
    }
Пример #5
0
    public void SetUshort(int x, int y, ushort value, UshortDataID id)
    {
        PixelInformation info = GetPixelInformation(x, y);
        AreaIndex        area = _areas[info.areaX, info.areaY];

        switch (id)
        {
        case UshortDataID.HeightLayerData:
            area.DataLayer.HeightLayerData.data[info.areaPixelX, info.areaPixelY] = value;
            break;
        }
    }
Пример #6
0
        /// <summary>
        /// event is fired when the 'Canvas' is clicked.
        /// </summary>
        private void Canvas_Click(object sender, EventArgs e)
        {
            // locals
            int x;
            int y;

            // If the value for the property this.ColorPickerMode is true or RectangleMode is true
            if ((ColorPickerMode) || (RectangleMode))
            {
                // get the mouse event args
                MouseEventArgs mouseEventArgs = e as MouseEventArgs;

                // If the mouseEventArgs object exists
                if (mouseEventArgs != null)
                {
                    // Get the x & y
                    x = mouseEventArgs.X;
                    y = mouseEventArgs.Y;

                    if (ColorPickerMode)
                    {
                        // Handle the PixelInfo
                        HandlePixelInfo(x, y);
                    }
                    else if (RectangleMode)
                    {
                        // set the pixel
                        PixelInformation pixel = null;

                        if (Point1 == Point.Empty)
                        {
                            // Get the scaled Pixel
                            pixel = HandlePixelInfo(x, y);

                            // Create Point1
                            Point1 = new Point(pixel.X, pixel.Y);
                        }
                        else if (Point2 == Point.Empty)
                        {
                            // Get the scaled Pixel
                            pixel = HandlePixelInfo(x, y);

                            // Create Point1
                            Point2 = new Point(pixel.X, pixel.Y);

                            // Draw a rectangle
                            PixelDatabase.DrawRectangle(Point1, Point2);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// This method Display Pixel
        /// </summary>
        public void DisplayPixel(PixelInformation pixel)
        {
            // locals
            int red       = 0;
            int green     = 0;
            int blue      = 0;
            int alpha     = 0;
            int x         = 0;
            int y         = 0;
            int greenRed  = 0;
            int blueGreen = 0;
            int blueRed   = 0;
            int total     = 0;

            // store the arg
            this.Pixel = pixel;

            // If the pixel object exists
            if (NullHelper.Exists(pixel))
            {
                // set the values
                red       = pixel.Red;
                green     = pixel.Green;
                blue      = pixel.Blue;
                alpha     = pixel.Alpha;
                greenRed  = pixel.GreenRed;
                blueGreen = pixel.BlueGreen;
                blueRed   = pixel.BlueRed;
                total     = pixel.Total;
                x         = pixel.X;
                y         = pixel.Y;
            }

            // display the values
            this.RedLabel.Text    = red.ToString();
            this.GreenLabel.Text  = green.ToString();
            this.BlueLabel.Text   = blue.ToString();
            this.AlphaLabel.Text  = alpha.ToString();
            this.YellowLabel.Text = greenRed.ToString();
            this.CyanLabel.Text   = blueGreen.ToString();
            this.PurpleLabel.Text = blueRed.ToString();
            this.SumLabel.Text    = total.ToString();
            this.XLabel.Text      = x.ToString();
            this.YLabel.Text      = y.ToString();

            // Update the UI
            this.Refresh();
            Application.DoEvents();
        }
Пример #8
0
        /// <summary>
        /// Creates a color attachment with a specific id, specific pixel informations and multisamples.
        /// </summary>
        /// <param name="attachmentID"></param>
        /// <param name="pixelInformation"></param>
        /// <param name="size"></param>
        /// <param name="multisamples"></param>
        public ColorAttachment(int attachmentID, PixelInformation pixelInformation, Vector2?size = null, int multisamples = 0)
        {
            AttachmentID     = attachmentID;
            PixelInformation = pixelInformation;
            AttachmentSize   = size;

            if (multisamples > 8)
            {
                multisamples = 8;
            }
            _multisamples = multisamples;
            Target        = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;

            WrapMode = TextureWrapMode.ClampToEdge;
        }
Пример #9
0
    private PixelInformation GetPixelInformation(int x, int y)
    {
        PixelInformation info = default(PixelInformation);

        int areaDim        = _index.AreaDimensions;
        int trueAreaX      = (int)((_request.left + x) / areaDim);
        int requestedAreaX = (int)(_request.left / areaDim);
        int trueAreaY      = (int)((_request.top + y) / areaDim);
        int requestedAreaY = (int)(_request.top / areaDim);

        info.areaX      = trueAreaX - requestedAreaX;
        info.areaY      = trueAreaY - requestedAreaY;
        info.areaPixelX = (_request.left + x) % areaDim;
        info.areaPixelY = (_request.top + y) % areaDim;

        return(info);
    }
Пример #10
0
        public virtual void SetPixel(int x, int y, IPixel pel)
        {
            // If the pixel types match, then 
            PixelInformation pelInfo = new PixelInformation(pel.Layout, pel.ComponentType);
            if (PixRectInfo.GetPixelInformation().Equals(pelInfo))
            {
                // Find the byte offset for the pixel
                IntPtr pixelPtr = GetPixelPointer(x, y);

                // copy the color bytes into the array
                Marshal.Copy(pel.GetBytes(), 0, pixelPtr, pel.GetBytes().Length);
                return;
            }

            // If the pixel types don't match, then we have to go through
            // color instead of just copying the pixel directly.
            SetColor(x, y, Pixel.GetColor(pelInfo, pel.GetBytes()));

        }
Пример #11
0
        /// <summary>
        /// This method Handle History
        /// </summary>
        public void HandleHistory(int x, int y, Guid historyId, Color previousColor)
        {
            // If the History object exists
            if ((!this.HasHistory) || (History.Id != historyId) && (historyId != Guid.Empty))
            {
                // here a new History object is created and the pixels are added to it instead
                this.History = new History(historyId);
            }

            // If the History object exists
            if (this.HasHistory)
            {
                // Create a new instance of a 'PixelInformation' object.
                PixelInformation pixel = new PixelInformation();
                pixel.X     = x;
                pixel.Y     = y;
                pixel.Color = previousColor;

                // Add this pixel to history
                this.History.ChangedPixels.Add(pixel);
            }
        }
Пример #12
0
    public ushort GetUshort(int x, int y, UshortDataID id)
    {
        if (AreCoordinatesInvalid(x, y))
        {
            return(1);
        }

        PixelInformation info = GetPixelInformation(x, y);

        if (IsPixelInformationInvalid(info))
        {
            Debug.LogWarning("Thigns went BAD " + info);
        }

        AreaIndex area = _areas[info.areaX, info.areaY];

        switch (id)
        {
        case UshortDataID.HeightLayerData:
            return(area.DataLayer.HeightLayerData.data[info.areaPixelX, info.areaPixelY]);
        }

        return(0);
    }
Пример #13
0
    public byte GetByte(int x, int y, ByteDataLyerID id)
    {
        if (AreCoordinatesInvalid(x, y))
        {
            return(1);
        }

        PixelInformation info = GetPixelInformation(x, y);

        if (IsPixelInformationInvalid(info))
        {
            Debug.LogWarning("THigns went BAD " + info);
        }

        AreaIndex area = _areas[info.areaX, info.areaY];

        switch (id)
        {
        case ByteDataLyerID.WaterLayerData:
            return(area.DataLayer.WaterLayerData.data[info.areaPixelX, info.areaPixelY]);
        }

        return(0);
    }
Пример #14
0
        /// <summary>
        /// This method Handle Pixel Info
        /// </summary>
        public PixelInformation HandlePixelInfo(int x, int y)
        {
            // local
            PixelInformation pixel = null;

            // for debugging only
            int originalX = x;
            int originalY = y;

            // Get the current image
            Image  image  = this.Canvas.BackgroundImage;
            Bitmap bitmap = new Bitmap(image);

            // x & y must now be scaled
            double canvasWidth  = this.Canvas.Width;
            double canvasHeight = this.Canvas.Height;
            double bitmapWidth  = bitmap.Width;
            double bitmapHeight = bitmap.Height;

            // get the xScale and the yScale
            double scaleX  = bitmapWidth / canvasWidth;
            double scaleY  = bitmapHeight / canvasHeight;
            double doubleX = (double)x;
            double doubleY = (double)y;

            // reset the values
            x = (int)(doubleX * scaleX);
            y = (int)(doubleY * scaleY);

            // ensure x is in range
            if (x < 0)
            {
                // reset x
                x = 0;
            }

            // ensure x is in range
            if (x >= bitmap.Width)
            {
                // reset x
                x = bitmap.Width - 1;
            }

            // ensure y is in range
            if (y < 0)
            {
                // reset y
                y = 0;
            }

            // ensure y is in range
            if (y >= bitmap.Height)
            {
                // reset y
                y = bitmap.Height - 1;
            }

            // get the information about this pixel
            Color color = bitmap.GetPixel(x, y);

            // Create a new instance of a 'PixelInformation' object.
            pixel = new PixelInformation();

            // set the information on the pixel
            pixel.Color = color;
            pixel.X     = x;
            pixel.Y     = y;

            if (ColorPickerMode)
            {
                // Handle the display top in case the mouse is too far down
                int displayY = originalY;
                int displayX = LeftMarginPanel.Width + originalX + 32;

                // if the height is too far down
                if ((displayY + 60) > (canvasHeight - PixelInfo.Height - TitleBarHeight))
                {
                    // Move up a control's length
                    displayY = displayY - 64 - PixelInfo.Height;
                }

                // if the width is too far right
                if ((displayX + 60) > canvasWidth)
                {
                    // Move left
                    displayX = displayX - 96 - PixelInfo.Width;
                }

                // Display the PixelInfo
                this.PixelInfo.DisplayPixel(pixel);
                this.PixelInfo.Left    = displayX;
                this.PixelInfo.Top     = displayY;
                this.PixelInfo.Visible = true;
                this.PixelInfo.Refresh();

                // if draw line is set
                if (this.QueryTextBox.Text.ToLower().Contains("draw line"))
                {
                    // add to the current text
                    string text = this.QueryTextBox.Text + " " + x + "  " + y + " ";

                    // Remove the new line character out of the beginning
                    text = text.Replace(Environment.NewLine + " ", Environment.NewLine);

                    // Update the text
                    this.QueryTextBox.Text = text;

                    // Set the Selection Start
                    this.QueryTextBox.SelectionStart = text.Length - 1;
                }
            }

            // return value
            return(pixel);
        }
Пример #15
0
 public Pixel(PixelInformation pixInfo, byte[] data, int startIndex)
     : this(pixInfo.Layout, pixInfo.ComponentType, data, startIndex)
 {
 }
Пример #16
0
    public void GenerateTranslucencyTexture()
    {
        totalLightBase[0] = Vector3.zero;
        totalLightBase[1] = Vector3.zero;

        #region BakeObjectSpaceTextures
        if (CheckBakeObjectSpaceTextures())
        {
            BakedTextures bakedTextures = (new ObjectSpaceBaker()).GenerateTextures(
                this.gameObject, textureResolution, objSpcMultisample, objSpcSpread, objSpcSaveTextures);
            objectSpacePosition = bakedTextures.tex2DObjectPos;
            objectSpaceNormal   = bakedTextures.tex2DObjectNormal;
        }
        else if (objectSpacePosition == null || objectSpaceNormal == null)
        {
            return;
        }

        #endregion

        #region GetMaximumObjectSize
        Vector3 boundarySize = GetComponent <Renderer>().bounds.size;
        float   objectSize   = Mathf.Max(boundarySize.x, boundarySize.y, boundarySize.z);
        #endregion

        #region InitializeTextureObjectsInMemory
        Texture2D tex2DTranslucencyPositive = new Texture2D(textureResolution, textureResolution, TextureFormat.ARGB32, false);
        Texture2D tex2DTranslucencyNegative = new Texture2D(textureResolution, textureResolution, TextureFormat.ARGB32, false);
        tex2DTranslucencyPositive.filterMode = FilterMode.Bilinear;
        tex2DTranslucencyPositive.wrapMode   = TextureWrapMode.Clamp;
        tex2DTranslucencyNegative.filterMode = FilterMode.Bilinear;
        tex2DTranslucencyNegative.wrapMode   = TextureWrapMode.Clamp;
        Texture2D[] tex2DTranslucencyArray = new Texture2D[] { tex2DTranslucencyPositive, tex2DTranslucencyNegative };
        #endregion

        //This region initializes arrays for faster lookups
        #region StartObjectNormalAndPositionArrays
        Color[] osNormals   = objectSpaceNormal.GetPixels();
        Color[] osPositions = objectSpacePosition.GetPixels();

        Color[]   osNormalsPositive = GetAdjustedNormals(osNormals, 0);
        Color[]   osNormalsNegative = GetAdjustedNormals(osNormals, 1);
        Color[][] osNormalArray     = new Color[2][] { osNormalsPositive, osNormalsNegative };

        PixelInformation[][] pixels = new PixelInformation[textureResolution][];
        for (int i = 0; i < pixels.Length; i++)
        {
            pixels[i] = new PixelInformation[textureResolution];
            for (int j = 0; j < pixels[i].Length; j++)
            {
                pixels[i][j] = new PixelInformation();
            }
        }
        #endregion

        #region InitializePixelArray
        for (int x = 0; x < textureResolution; x++)
        {
            for (int y = 0; y < textureResolution; y++)
            {
                int arrIndex = x + y * textureResolution;

                //Checks if this pixel is mapped to a UV coord.
                if (osPositions[arrIndex].a >= 1f)
                {
                    pixels[x][y].initialized        = true;
                    pixels[x][y].x                  = x;
                    pixels[x][y].y                  = y;
                    pixels[x][y].arrayIndex         = arrIndex;
                    pixels[x][y].currentEmission[0] = osNormalArray[0][arrIndex];
                    pixels[x][y].currentEmission[1] = osNormalArray[1][arrIndex];

                    for (int xx = 0; xx < textureResolution; xx++)
                    {
                        for (int yy = 0; yy < textureResolution; yy++)
                        {
                            //We are now gonna map the distance between the pixel and every other pixel in the texture map.
                            //This saves processing time for multiple bounces.

                            int arrIndexB = xx + yy * textureResolution;

                            //Object Space Map should NOT be normalized.
                            if (osPositions[arrIndexB].a >= 0.9f || arrIndexB == arrIndex)
                            {
                                float distance = 0f;
                                if (arrIndex == arrIndexB)
                                {
                                    distance = 1f;
                                }
                                else
                                {
                                    distance = GetFullDistance(Distance(osPositions[arrIndex], osPositions[arrIndexB]));
                                }                                                                                             //*objectsize

                                //GetFullDistance already normalizes distance from 0 to 1 and considers depth cutout.
                                if (distance > 0f || arrIndex == arrIndexB)
                                {
                                    pixels[x][y].reflections.Add(new ReflectedCoordinate(pixels[xx][yy], distance));
                                }
                            }
                        }
                    }
                }
            }
        }
        #endregion

        #region InitializePixelList
        List <PixelInformation> pixelList = new List <PixelInformation>();
        for (int x = 0; x < textureResolution; x++)
        {
            for (int y = 0; y < textureResolution; y++)
            {
                if (pixels[x][y].initialized)
                {
                    pixelList.Add(pixels[x][y]);
                }
            }
        }
        pixels = new PixelInformation[0][];
        #endregion

        #region InitializeTranslucencyTexture
        //Gives them the base emission
        for (int x = 0; x < textureResolution; x++)
        {
            for (int y = 0; y < textureResolution; y++)
            {
                int arrIndex = x + y * textureResolution;
                tex2DTranslucencyPositive.SetPixel(x, y, osNormalArray[0][arrIndex] * (1f - transparency));
                tex2DTranslucencyNegative.SetPixel(x, y, osNormalArray[1][arrIndex] * (1f - transparency));
            }
        }
        tex2DTranslucencyPositive.Apply();
        tex2DTranslucencyNegative.Apply();
        #endregion

        #region CreateTranslucencyTexture
        GetBaseLightSum(pixelList);
        ScatterLight(pixelList);
        NormalizeLight(pixelList); //Energy conservation.

        BakeTranslucentTexture(pixelList, tex2DTranslucencyArray);
        SpreadPixels(osPositions, tex2DTranslucencyArray);

        if (saveTexture)
        {
            SaveTextures(gameObject.name, tex2DTranslucencyPositive, tex2DTranslucencyNegative);
        }
        #endregion

        translucencyTexturePositive = tex2DTranslucencyPositive;
        translucencyTextureNegative = tex2DTranslucencyNegative;


        GetComponent <Renderer>().sharedMaterial.SetTexture("_EmissionMap", tex2DTranslucencyPositive);
        GetComponent <Renderer>().sharedMaterial.SetColor("_MainColor", Color.black);
    }
Пример #17
0
 public ReflectedCoordinate(PixelInformation pixelInformation, float distance)
 {
     this.pixelInformation = pixelInformation;
     this.distance         = distance;
 }
Пример #18
0
        /// <summary>
        /// event is fired when the 'RandomizeButton' is clicked.
        /// </summary>
        private void RandomizeButton_Click(object sender, EventArgs e)
        {
            // setup our images
            string sliceImage       = SliceImageControl.Text;
            string targetImage      = TargetImageControl.Text;
            int    rowHeight        = 0;
            int    rowWidth         = 0;
            bool   isValid          = false;
            int    offSetX          = 0;
            int    offSetY          = 0;
            int    increment        = 0;
            int    incrementedValue = 0;

            // load the target database
            PixelDatabase targetDatabase = PixelDatabaseLoader.LoadPixelDatabase(targetImage, this.Callback);

            // verify both objects exist
            if (NullHelper.Exists(sliceDatabase, targetDatabase))
            {
                // Set the height and width
                rowHeight = sliceDatabase.Height;
                rowWidth  = sliceDatabase.Width;
                int min    = MinValueControl.IntValue;
                int max    = MaxValueControl.IntValue;
                int startX = StartXControl.IntValue;
                int startY = StartYControl.IntValue;
                increment = IncrementControl.IntValue;
                int indent = 0;
                LargeNumberShuffler shuffler = null;

                // verify everything is in rage
                if ((min > 0) && (max > 0) && (max > min) || (max == 0))
                {
                    // valid
                    isValid = true;

                    // setup the ProgressBar
                    this.Graph.Visible = true;
                    this.Graph.Minimum = 0;
                    this.Graph.Maximum = NumberSlicesControl.IntValue;

                    // If the value for max is greater than zero
                    if (max > 0)
                    {
                        // Create a new instance of a 'RandomShuffler' object.
                        shuffler = new LargeNumberShuffler(6, 1, 375894, NumberOutOfRangeOptionEnum.ReturnModulus);
                    }

                    // setup the section
                    for (int section = 0; section < NumberSlices; section++)
                    {
                        // Update the graph
                        Graph.Value = section;

                        // Add the increment to the incrementedValue
                        incrementedValue += increment;

                        // if max is set, else we do not need indent
                        if (max > 0)
                        {
                            // pull the next item
                            indent = (shuffler.PullNumber() % 86) + 1;
                        }

                        // now we need to copy the entire sourceImage onto the target, using this indent

                        // iterate the y pixels
                        for (int x = 0; x < rowWidth; x++)
                        {
                            for (int y = 0; y < rowHeight; y++)
                            {
                                // get this pixel
                                PixelInformation pixel = sliceDatabase.GetPixel(x, y);

                                // If the pixel object exists
                                if (NullHelper.Exists(pixel))
                                {
                                    // get the new x
                                    offSetX = indent + startX + x;
                                    offSetY = (section * rowHeight) + y + startY + incrementedValue;

                                    if (offSetY < (targetDatabase.Height - 1))
                                    {
                                        // Set the pixel color
                                        targetDatabase.SetPixelColor(offSetX, offSetY, pixel.Color, false, 0);
                                    }
                                }
                            }
                        }
                    }

                    // Set the image
                    TargetImageViewer.BackgroundImage = targetDatabase.DirectBitmap.Bitmap;

                    // UPdate this UI
                    Refresh();
                }
                else
                {
                    // not valid
                    isValid = false;
                }
            }
            else
            {
                // not valid
                isValid = false;
            }

            // Show the user a message
            if (!isValid)
            {
                // show a message to the user
                MessageBox.Show("Not valid", "Invalid");
            }
        }
Пример #19
0
 public PixelInformation GetPixelInformation()
 {
     PixelInformation info = new PixelInformation(Layout, ComponentType);
     return info;
 }
Пример #20
0
 private bool IsPixelInformationInvalid(PixelInformation info)
 {
     return(info.areaX >= _areas.Length || info.areaY >= _areas.GetLongLength(1));
 }
Пример #21
0
 public Pixel(PixelInformation pixInfo, byte[] data)
     : this(pixInfo, data, 0)
 {
 }