示例#1
0
 protected void Max(Heightmap background)
 {
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = Mathf.Max(result[i], background[i]);
     }
 }
示例#2
0
 protected void Average(Heightmap background, float opacity)
 {
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = ((result[i] * opacity) + background[i]) * 0.5f;
     }
 }
示例#3
0
 protected void Multiply(Heightmap background, float opacity)
 {
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = (result[i] * opacity) * background[i];
     }
 }
        public override void Execute()
        {
            float height = GetInputValue("height", this.height);

            result = new Heightmap();
            result.Fill(height);
        }
示例#5
0
        public Heightmap Copy()
        {
            Heightmap clone = MemberwiseClone() as Heightmap;

            clone.matrix = new float[matrix.Length];
            matrix.CopyTo(clone.matrix, 0);

            return(clone);
        }
示例#6
0
        public override object OnRequestValue(Port port)
        {
            if (result == null)
            {
                // Grab an updated input Heightmap, cache, and then run the
                // transform method on it and notify listeners once complete.
                map = GetInputValue <Heightmap>("map");
                if (map != null)
                {
                    result = map.Copy();
                    Execute();
                }

                onUpdateResult?.Invoke(result);
            }

            return(result);
        }
        public override void Execute()
        {
            Rect  region     = GetInputValue("region", this.region);
            int   octaves    = GetInputValue("octaves", this.octaves);
            float amplitude  = GetInputValue("amplitude", this.amplitude);
            float lacunarity = GetInputValue("lacunarity", this.lacunarity);
            float invScale   = 1f / GetInputValue("scale", scale);

            result = new Heightmap();

            const float gain = 0.5f;

            float ystep = region.height / Heightmap.Size;
            float xstep = region.width / Heightmap.Size;

            // Algorithm from https://thebookofshaders.com/13/
            float ry = region.y;

            for (int y = 0; y <= Heightmap.Size; y++, ry += ystep)
            {
                float rx = region.x;
                for (int x = 0; x <= Heightmap.Size; x++, rx += xstep)
                {
                    float fx = rx * invScale;
                    float fy = ry * invScale;

                    float height = 0f;
                    float amp    = amplitude;

                    for (int j = 0; j < octaves; j++)
                    {
                        height += amp * Noise(fx, fy);
                        fx     *= lacunarity;
                        fy     *= lacunarity;
                        amp    *= gain;
                    }

                    result[x, y] = height;
                }
            }
        }
示例#8
0
        public override void Execute()
        {
            Rect  region   = GetInputValue("region", this.region);
            float invScale = 1.0f / GetInputValue("scale", scale);

            result = new Heightmap();

            float ystep = region.height / Heightmap.Size;
            float xstep = region.width / Heightmap.Size;

            float ry = region.y;

            for (int y = 0; y <= Heightmap.Size; y++, ry += ystep)
            {
                float rx = region.x;
                for (int x = 0; x <= Heightmap.Size; x++, rx += xstep)
                {
                    result[x, y] = Mathf.PerlinNoise(rx * invScale, ry * invScale);
                }
            }
        }
示例#9
0
        public override void Execute()
        {
            Heightmap background = GetInputValue("background", this.background);
            float     opacity    = GetInputValue("opacity", this.opacity);

            // No output until we have both inputs
            if (background == null)
            {
                result = null;
                return;
            }

            switch (mode)
            {
            case BlendMode.Add:
                Add(background, opacity);
                break;

            case BlendMode.Multiply:
                Multiply(background, opacity);
                break;

            case BlendMode.Average:
                Average(background, opacity);
                break;

            case BlendMode.Min:
                Min(background);
                break;

            case BlendMode.Max:
                Max(background);
                break;

            case BlendMode.Abs:
                Abs();
                break;
            }
        }
 public void DirtyResult()
 {
     result = null;
 }