예제 #1
0
        public Texture2D GetTexture()
        {
            Texture2D tex = new Texture2D(DestImage.Width, DestImage.Height);

            for (int y = 0; y < tex.height; y++)
            {
                for (int x = 0; x < tex.width; x++)
                {
                    tex.SetPixel(x, y, DestImage.GetValue(x, y));
                }
            }

            tex.Apply();
            return(tex);
        }
예제 #2
0
        //Methods//
        public void Render()
        {
            int width  = SourceNoiseMap.Width;
            int height = SourceNoiseMap.Height;

            DestImage = new ImageMap(width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Color  destColor = gradient.GetColor(SourceNoiseMap.GetValue(x, y));
                    double lightIntensity;

                    if (IsLightEnabled)
                    {
                        int xLeftOffset, xRightOffset;
                        int yUpOffset, yDownOffset;

                        if (IsWrapEnabled)
                        {
                            if (x == 0)
                            {
                                xLeftOffset  = (int)width - 1;
                                xRightOffset = 1;
                            }

                            else if (x == (int)width - 1)
                            {
                                xLeftOffset  = -1;
                                xRightOffset = -((int)width - 1);
                            }

                            else
                            {
                                xLeftOffset  = -1;
                                xRightOffset = 1;
                            }

                            if (y == 0)
                            {
                                yDownOffset = (int)height - 1;
                                yUpOffset   = 1;
                            }

                            else if (y == (int)height - 1)
                            {
                                yDownOffset = -1;
                                yUpOffset   = -((int)height - 1);
                            }

                            else
                            {
                                yDownOffset = -1;
                                yUpOffset   = 1;
                            }
                        }

                        else
                        {
                            if (x == 0)
                            {
                                xLeftOffset  = 0;
                                xRightOffset = 1;
                            }

                            else if (x == (int)width - 1)
                            {
                                xLeftOffset  = -1;
                                xRightOffset = 0;
                            }

                            else
                            {
                                xLeftOffset  = -1;
                                xRightOffset = 1;
                            }

                            if (y == 0)
                            {
                                yDownOffset = 0;
                                yUpOffset   = 1;
                            }

                            else if (y == (int)height - 1)
                            {
                                yDownOffset = -1;
                                yUpOffset   = 0;
                            }

                            else
                            {
                                yDownOffset = -1;
                                yUpOffset   = 1;
                            }
                        }

                        double nc = (double)SourceNoiseMap.GetValue(x, y);
                        double nl = (double)SourceNoiseMap.GetValue(x + xLeftOffset, y);
                        double nr = (double)SourceNoiseMap.GetValue(x + xRightOffset, y);
                        double nd = (double)SourceNoiseMap.GetValue(x, y + yDownOffset);
                        double nu = (double)SourceNoiseMap.GetValue(x, y + yUpOffset);
                        lightIntensity  = CalcLightIntensity(nc, nl, nr, nd, nu);
                        lightIntensity *= LightBrightness;
                    }

                    else
                    {
                        lightIntensity = 1.0;
                    }

                    Color backgroundColor = Color.white;

                    if (BackgroundImage != null)
                    {
                        backgroundColor = BackgroundImage.GetValue(x, y);
                    }

                    DestImage.SetValue(x, y, CalcDestColor(destColor, backgroundColor, lightIntensity));
                }
            }
        }