예제 #1
0
        private void SetMoistureSampler()
        {
            if (!UseMoisture)
            {
                return;
            }

            AbsGeneratorNode gen = GetInputValue <AbsGeneratorNode>("MoistureGenerator");

            _moistureSampler = gen == null ? null : new GeneratorSampler(gen.GetGenerator());
        }
        public override Texture2D DidRequestTextureUpdate()
        {
            int       s   = PreviewTextureSize;
            Texture2D tex = new Texture2D(s, s);

            Generator g = GetGenerator();

            if (g == null)
            {
                return(tex);
            }

            GeneratorSampler sampler = new GeneratorSampler(g);

            //Retrieve values
            float min = float.PositiveInfinity;
            float max = float.NegativeInfinity;

            float[,] values = new float[s, s];

            for (int x = 0; x < s; x++)
            {
                for (int y = 0; y < s; y++)
                {
                    float val = sampler.GetValue(x, y, GridPosition.Zero, s, s, 1);

                    if (val < min)
                    {
                        min = val;
                    }
                    if (val > max)
                    {
                        max = val;
                    }

                    values[x, y] = val;
                }
            }

            //Normalize values and set texture
            for (int x = 0; x < s; x++)
            {
                for (int y = 0; y < s; y++)
                {
                    float val  = values[x, y];
                    float norm = (val - min) / (max - min);

                    tex.SetPixel(x, y, new Color(norm, norm, norm, 1f));
                }
            }

            tex.Apply();
            return(tex);
        }
예제 #3
0
        private void SetHeightmapSampler()
        {
            if (!UseHeightmap)
            {
                return;
            }

            AbsGeneratorNode gen = GetInputValue <AbsGeneratorNode>("HeightmapGenerator");

            _heightmapSampler = gen == null ? null : new GeneratorSampler(gen.GetGenerator());
        }