Exemplo n.º 1
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;

            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    int tx = FlipHorizontal ? parms.Width - x - 1 : x;
                    int ty = FlipVertical ? parms.Height - y - 1 : y;
                    mp.Value[x, y] = InputMask[tx, ty];
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;

            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    mp.Value[x, y] = mp.Value[x, y] * Gain + Bias;
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            gatherInputAndParameters(parms);

            NoiseGeneration.RigedMultiFractal pl = new NoiseGeneration.RigedMultiFractal();
            pl.mSeed = this.SeedParam;
            pl.mOctaveCount.Value = this.OctaveParam;
            pl.mFrequency.Value   = this.Frequency;
            pl.mLacunarity.Value  = this.Lacunarity;

            int sWidth  = 128;
            int sHeight = 128;

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(parms.Width, parms.Height);
            mp.Value.mConstraintMask = ConstraintMask;

            for (int y = 0; y < parms.Height; y++)
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    mp.Value[x, y] = BMathLib.Clamp((float)((pl.getValue((x / (float)parms.Width) * sWidth, (y / (float)parms.Height) * sHeight, 0) + 1) * 0.5f), 0, 1);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }


            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            if (InputChoice)
            {
                mp.Value = InputMaskA.Clone();
            }
            else
            {
                mp.Value = InputMaskB.Clone();
            }

            return(true);
        }
Exemplo n.º 5
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(InputMask.Width, InputMask.Height);

            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    Vector2 v      = TerrainGlobals.getTerrain().getGradiant(x, y);
                    float   factor = BMathLib.Clamp(v.Length(), 0, 1);
                    if (factor < 0)
                    {
                        continue;
                    }

                    mp.Value[x, y] = factor;
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;

            int     numTimesToRun = parms.Width >> 1;
            DAGMask outMask       = InputMask.Clone();//

            DAGMask distMask = new DAGMask(parms.Width, parms.Height);

            int maxRange = 0;

            for (int i = 0; i < numTimesToRun; i++)
            {
                DAGMask smallerMask = new DAGMask(parms.Width, parms.Height);
                bool    madeChange  = contractSetValue(ref outMask, ref smallerMask, ref distMask, i);

                outMask = smallerMask.Clone();
                if (madeChange)
                {
                    maxRange = i;
                }
                else
                {
                    break;
                }
            }


            //normalize our input now...
            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    mp.Value[x, y] = distMask[x, y] / (float)maxRange;
                }
            }

            outMask = null;

            return(true);
        }
Exemplo n.º 7
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            gatherInputAndParameters(parms);


            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(parms.Width, parms.Height);

            float mx    = CoreGlobals.getEditorMain().mITerrainShared.getBBMax().Y;
            float mn    = CoreGlobals.getEditorMain().mITerrainShared.getBBMin().Y;
            float delta = mx - mn;

            int numXVerts = CoreGlobals.getEditorMain().mITerrainShared.getNumXVerts();
            int numZVerts = CoreGlobals.getEditorMain().mITerrainShared.getNumXVerts();

            float[] fk = new float[numXVerts * numZVerts];
            for (int x = 0; x < numXVerts; x++)
            {
                for (int y = 0; y < numZVerts; y++)
                {
                    fk[x + numXVerts * y] = CoreGlobals.getEditorMain().mITerrainShared.getTerrainHeight(x, y);
                }
            }


            if (numXVerts != parms.Width || numZVerts != parms.Height)
            {
                float[] resizedHeights = ImageManipulation.resizeF32Img(fk, numXVerts, numZVerts, parms.Width, parms.Height, ImageManipulation.eFilterType.cFilter_Linear);
                fk = (float[])resizedHeights.Clone();
            }


            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    float k = fk[x + parms.Width * y];
                    k -= mn;
                    k /= delta;

                    mp.Value[x, y] = k;
                }
            }

            return(true);
        }
Exemplo n.º 8
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            setNoiseParms();


            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;


            for (int y = 0; y < parms.Height; y++)
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    float x0, y0;
                    float x1, y1;
                    float x2, y2;
                    x0 = x + (12414.0f / 65536.0f);
                    y0 = y + (65124.0f / 65536.0f);

                    x1 = x + (26519.0f / 65536.0f);
                    y1 = y + (18128.0f / 65536.0f);

                    x2 = x + (53820.0f / 65536.0f);
                    y2 = y + (11213.0f / 65536.0f);

                    float xDistort = ((float)(mXDistort.getValue(x0, y0, 0) * Power));
                    float yDistort = ((float)(mYDistort.getValue(x1, y1, 0) * Power));


                    int kx = (int)BMathLib.Clamp(x + (int)(xDistort * parms.Width), 0, parms.Width - 1);
                    int ky = (int)BMathLib.Clamp(y + (int)(yDistort * parms.Height), 0, parms.Height - 1);

                    mp.Value[x, y] = InputMask[kx, ky];
                }
            }

            return(true);
        }
Exemplo n.º 9
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            gatherInputAndParameters(parms);


            MaskParam mp = ((MaskParam)(connPoint.ParamType));
            // mp.Value = InputMask.Clone();

            DAGMask baseMask = InputMask.Clone();

            DAGMask addMask = new DAGMask(parms.Width, parms.Height);
            DAGMask subMask = new DAGMask(parms.Width, parms.Height);

            //if we're doing multiscale erosion
            if (MultiscaleEnable)
            {
                //subtract multiscale mask from our base mask before doing erosion
                multiscaleDisplace(ref baseMask, ref subMask, ref addMask);
            }


            //CLM it actually looks better (less noisy) w/o this high fidelity step!
            calculateErosion(baseMask, baseMask.Width, baseMask.Height, ref subMask, ref addMask, 0);


            //calculate our mask 'channels'

            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    baseMask[x, y] = baseMask[x, y] + addMask[x, y] - subMask[x, y];
                }
            }

            //need to find which output this connection point is connected to...
            mp.Value = baseMask.Clone();


            return(true);
        }
Exemplo n.º 10
0
      public void generatePreview(CanvasNode cn)
      {
          OutputGenerationParams ogp = new OutputGenerationParams();
          ogp.Width = 128;
          ogp.Height = 128;

          MaskDAGGraphNode gn = (MaskDAGGraphNode)cn;
          MaskParam mp = new MaskParam();
          InputConnectionPoint icp = new InputConnectionPoint(mp,true,"Preview",gn,this);
          gn.computeOutput(icp,ogp);

          if (onUpdateCallback != null)
          {
              DAGMask m = mp.Value;
              onUpdateCallback(ref m);
          }
       }
Exemplo n.º 11
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }


            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;

            if (ClampType == (int)eMethod.eScale) //scale between the values
            {
                float delta = MaxHeight - MinHeight;

                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = MinHeight + (InputMask[x, y] * delta);
                    }
                }
            }

            else if (ClampType == (int)eMethod.eClamp) //actually clamp
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = BMathLib.Clamp(InputMask[x, y], MinHeight, MaxHeight);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 12
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            //this is a splitter, so we need to duplicate the input values..
            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();

            return(true);
        }
Exemplo n.º 13
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            gatherInputAndParameters(parms);

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(parms.Width, parms.Height);
            mp.Value.mConstraintMask = ConstraintMask;
            mp.Value.setAllToValue(Value);



            return(true);
        }
Exemplo n.º 14
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            gatherInputAndParameters(parms);


            System.Drawing.Drawing2D.Matrix mTransformMat = new Matrix();
            mTransformMat.Translate(-(parms.Width >> 1), -(parms.Height >> 1));
            mTransformMat.Rotate(Direction, MatrixOrder.Append);
            mTransformMat.Translate((parms.Width >> 1), (parms.Height >> 1), MatrixOrder.Append);


            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(parms.Width, parms.Height);
            mp.Value.mConstraintMask = ConstraintMask;

            Point[] pts = new Point[1];


            float incStep = 1.0f / parms.Width;

            for (int y = 0; y < parms.Height; y++)
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    pts[0].X = x;
                    pts[0].Y = y;
                    mTransformMat.TransformPoints(pts);

                    mp.Value[x, y] = incStep * pts[0].X;
                }
            }



            return(true);
        }
Exemplo n.º 15
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;


            DAGMask outMask = InputMask.Clone();

            for (int i = 0; i < NumPixels; i++)
            {
                DAGMask smallerMask = new DAGMask(parms.Width, parms.Height);
                contractSetValue(ref outMask, ref smallerMask);

                outMask = smallerMask.Clone();
            }


            //normalize our input now...
            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    mp.Value[x, y] = outMask[x, y];
                }
            }

            outMask = null;

            return(true);
        }
Exemplo n.º 16
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(InputMask.Width, InputMask.Height);


            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    if (InputMask[x, y] >= MinHeight && InputMask[x, y] <= MaxHeight)
                    {
                        mp.Value[x, y] = 1.0f;
                    }
                    else if (InputMask[x, y] >= MinHeight - FalloffAmt && InputMask[x, y] <= MinHeight)
                    {
                        mp.Value[x, y] = 1 - ((MinHeight - InputMask[x, y]) / FalloffAmt);
                    }
                    else if (InputMask[x, y] >= MaxHeight && InputMask[x, y] <= MaxHeight + FalloffAmt)
                    {
                        mp.Value[x, y] = 1 - ((InputMask[x, y] - MaxHeight) / FalloffAmt);
                    }
                    else
                    {
                        mp.Value[x, y] = 0;
                    }
                }
            }

            return(true);
        }
Exemplo n.º 17
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;

            SplineInterpolator interpolator = new SplineInterpolator();

            for (int i = 0; i < ControlPointsKeys.Count; ++i)
            {
                interpolator.Add(ControlPointsKeys[i], ControlPointsValues[i]);
            }


            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    float v = mp.Value[x, y];

                    mp.Value[x, y] = (float)interpolator.Interpolate(v);
                }
            }


            interpolator.Clear();
            interpolator = null;
            return(true);
        }
Exemplo n.º 18
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            gatherInputAndParameters(parms);



            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(parms.Width, parms.Height);
            mp.Value.mConstraintMask = ConstraintMask;


            int xOffset = parms.Width >> 1;
            int yOffset = parms.Height >> 1;

            int radius    = (int)(Radius * parms.Width);
            int hotRadius = (int)(radius * HotSpot);
            int diff      = (int)(radius - hotRadius);
            int mnX       = Math.Max(0, xOffset - radius);
            int mnY       = Math.Max(0, yOffset - radius);
            int mxX       = Math.Min(parms.Width - 1, xOffset + radius);
            int mxY       = Math.Min(parms.Height - 1, yOffset + radius);

            for (int i = mnX; i < mxX; i++)
            {
                for (int j = mnY; j < mxY; j++)
                {
                    float gradVal = 0;

                    float dist = (float)Math.Sqrt((xOffset - i) * (xOffset - i) + (yOffset - j) * (yOffset - j));
                    if (dist < radius)
                    {
                        if (dist < hotRadius)
                        {
                            gradVal = 1.0f;
                        }
                        else
                        {
                            float gradDiff = 1 - ((dist - (hotRadius)) / (float)(diff));

                            gradVal = gradDiff;
                        }
                    }

                    if (gradVal == 0)
                    {
                        continue;
                    }


                    mp.Value[i, j] = Intensity * gradVal;
                }
            }


            return(true);
        }
Exemplo n.º 19
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }
            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(InputMask.Width, InputMask.Height);

            float tileScale = 1.0f;


            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    //CLM [02.18.08] this uses the calculation of the Gradiant for a given heightfield element
                    // That is, the partial derivitive of the element.
                    // taking the length approximates how much gradation exists in either the X or Y directions.

                    int px = (int)BMathLib.Clamp(x + 1, 0, parms.Width - 1);
                    int py = (int)BMathLib.Clamp(y + 1, 0, parms.Height - 1);

                    int nx = (int)BMathLib.Clamp(x - 1, 0, parms.Width - 1);
                    int ny = (int)BMathLib.Clamp(y - 1, 0, parms.Height - 1);

                    float vX = (InputMask[px, y] - InputMask[nx, y]) / (2 * tileScale);
                    float vY = (InputMask[x, py] - InputMask[x, ny]) / (2 * tileScale);

                    float vLen = (float)Math.Sqrt(vX * vX + vY * vY);

                    float slope = BMathLib.Saturate(vLen);



                    if (slope >= MinSlope && slope <= MaxSlope)
                    {
                        mp.Value[x, y] = 1.0f;
                    }
                    else if (slope >= MinSlope - FalloffAmt && slope <= MinSlope)
                    {
                        mp.Value[x, y] = 1 - ((MinSlope - slope) / FalloffAmt);
                    }
                    else if (slope >= MaxSlope && slope <= MaxSlope + FalloffAmt)
                    {
                        mp.Value[x, y] = 1 - ((slope - MaxSlope) / FalloffAmt);
                    }
                    else
                    {
                        mp.Value[x, y] = 0;
                    }
                }
            }

            return(true);
        }
Exemplo n.º 20
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(InputMaskA.Width, InputMaskA.Height);
            mp.Value.mConstraintMask = ConstraintMask;

            if (Method == (int)eMethod.eAverage) //AVERAGE
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = (InputMaskA[x, y] + InputMaskB[x, y]) * Strength[x, y];
                    }
                }
            }
            else if (Method == (int)eMethod.eAdd) //ADD
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = InputMaskA[x, y] + (InputMaskB[x, y] * Strength[x, y]);
                    }
                }
            }
            else if (Method == (int)eMethod.eSubtract) //SUBTRACT
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = InputMaskA[x, y] - (InputMaskB[x, y] * Strength[x, y]);
                    }
                }
            }
            else if (Method == (int)eMethod.eMultiply) //MULTIPLY
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = InputMaskA[x, y] * InputMaskB[x, y] * Strength[x, y];
                    }
                }
            }
            else if (Method == (int)eMethod.eMax) //MAX
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = Math.Max(InputMaskA[x, y], InputMaskB[x, y]);
                    }
                }
            }
            else if (Method == (int)eMethod.eMin) //MIN
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = Math.Min(InputMaskA[x, y], InputMaskB[x, y]);
                    }
                }
            }
            else if (Method == (int)eMethod.eLerp) //LERP
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = ((1.0f - Strength[x, y]) * InputMaskA[x, y]) + (Strength[x, y] * InputMaskB[x, y]);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 21
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;


            ConvMatrix filter = new ConvMatrix(1, 2, 1, 2, 4, 2, 1, 2, 1);

            filter.mFactor = 16;
            filter.mOffset = 0;

            for (int i = 0; i < SmoothPower; i++)
            {
                int[] neightbors = new int[] { -1, 1,     //top left
                                               0, 1,      //top center
                                               1, 1,      //top right

                                               -1, 0,     //mid left
                                               0, 0,      //mid center
                                               1, 0,      //mid right

                                               -1, -1,    //bot left
                                               0, -1,     //bot center
                                               1, -1,     //bot right
                };


                DAGMask tempImgArray = new DAGMask(parms.Width, parms.Height);

                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        float total = 0;
                        for (int k = 0; k < 9; k++)
                        {
                            int xIndex = x + neightbors[k * 2];
                            int zIndex = y + neightbors[k * 2 + 1];
                            if (xIndex < 0 || xIndex > parms.Width - 1 || zIndex < 0 || zIndex > parms.Height - 1)
                            {
                                continue;
                            }


                            total += filter.mFilterCoeffs[k] * mp.Value[xIndex, zIndex];
                        }
                        total = total / filter.mFactor + filter.mOffset;

                        if (total > 1.0f)
                        {
                            total = 1.0f;
                        }
                        if (total < 0)
                        {
                            total = 0;
                        }

                        tempImgArray[x, y] = total;
                    }
                }

                //send our mask back
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = BMathLib.Clamp(tempImgArray[x, y], 0, 1);
                    }
                }


                tempImgArray = null;
            }


            return(true);
        }
Exemplo n.º 22
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;

            float modStep = 1.0f / NumTerraces;

            if (Method == (int)eMethod.eSimple)
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        float dc = InputMask[x, y] % modStep;
                        mp.Value[x, y] = InputMask[x, y] - dc;
                    }
                }
            }
            else if (Method == (int)eMethod.eSharp)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    for (int x = 0; x < parms.Width; x++)
                    {
                        //find our low step
                        float val  = InputMask[x, y];
                        float low  = val - (val % modStep);
                        float high = low + modStep;

                        float posalpha = (val - low) / (high - low);
                        posalpha *= posalpha;
                        float posVal = ((1.0f - posalpha) * low) + (posalpha * high);

                        float negalpha = (val - low) / (high - low);
                        negalpha = 1.0f - negalpha;
                        {
                            float v = low;
                            low  = high;
                            high = v;
                        }
                        negalpha *= negalpha;
                        float negVal = ((1.0f - negalpha) * low) + (negalpha * high);

                        //lerp between neg and pos values
                        mp.Value[x, y] = ((1.0f - TerraceShape) * negVal) + (TerraceShape * posVal);
                    }
                }
            }
            //else if (Method == (int)eMethod.eSmooth)
            //{
            //}


            return(true);
        }
Exemplo n.º 23
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (SelectedMaskName == null || SelectedMaskName == "")
            {
                return(false);
            }

            gatherInputAndParameters(parms);

            ArrayBasedMask terrMask = null;

            IMask msk = CoreGlobals.getEditorMain().mIMaskPickerUI.GetMask(SelectedMaskName);

            if (msk == null)
            {
                return(false);
            }
            if (msk is ArrayBasedMask)
            {
                terrMask = msk as ArrayBasedMask;
            }
            else if (msk is GraphBasedMask)
            {
                //we have to generate this mask...
                if (((GraphBasedMask)msk).loadAndExecute())
                {
                    terrMask = ((GraphBasedMask)msk).getOutputMask();
                }
            }



            int numXVerts = CoreGlobals.getEditorMain().mITerrainShared.getNumXVerts();
            int numZVerts = CoreGlobals.getEditorMain().mITerrainShared.getNumXVerts();

            float[] fk = new float[numXVerts * numZVerts];
            for (int x = 0; x < numXVerts; x++)
            {
                for (int y = 0; y < numZVerts; y++)
                {
                    fk[x + numXVerts * y] = terrMask.GetValue(x * numXVerts + y);
                }
            }


            if (numXVerts != parms.Width || numZVerts != parms.Height)
            {
                float[] resizedHeights = ImageManipulation.resizeF32Img(fk, numXVerts, numZVerts, parms.Width, parms.Height, ImageManipulation.eFilterType.cFilter_Linear);
                fk = (float[])resizedHeights.Clone();
            }



            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = new DAGMask(parms.Width, parms.Height);

            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    float k = fk[x + parms.Width * y];
                    mp.Value[x, y] = k;
                }
            }

            terrMask = null;
            msk      = null;

            return(true);
        }
Exemplo n.º 24
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;



            int r = Radius;

            int[]   w       = CreateGaussianBlurRow(r);
            int     wlen    = w.Length;
            DAGMask tmpMask = new DAGMask(parms.Width, parms.Height);


            {
                float[] waSums = new float[wlen];
                float[] wcSums = new float[wlen];
                float[] aSums  = new float[wlen];


                for (int y = 0; y < parms.Height; ++y)
                {
                    float waSum = 0;
                    float wcSum = 0;
                    float aSum  = 0;


                    int dstx = 0;

                    for (int wx = 0; wx < wlen; ++wx)
                    {
                        int srcX = wx - r;
                        waSums[wx] = 0;
                        wcSums[wx] = 0;
                        aSums[wx]  = 0;


                        if (srcX >= 0 && srcX < parms.Width)
                        {
                            for (int wy = 0; wy < wlen; ++wy)
                            {
                                int srcY = y + wy - r;

                                if (srcY >= 0 && srcY < parms.Height)
                                {
                                    float c  = InputMask[srcX, srcY];
                                    float wp = w[wy];

                                    waSums[wx] += wp;
                                    wp         *= c;// +(c >> 7);
                                    wcSums[wx] += wp;
                                    //wp >>= 8;

                                    aSums[wx] += wp * c;
                                }
                            }

                            int wwx = w[wx];
                            waSum += wwx * waSums[wx];
                            wcSum += wwx * wcSums[wx];
                            aSum  += wwx * aSums[wx];
                        }
                    }

                    // wcSum >>= 8;

                    if (waSum == 0 || wcSum == 0)
                    {
                        tmpMask[dstx, y] = 0;
                    }
                    else
                    {
                        tmpMask[dstx, y] = aSum / waSum;
                    }

                    ++dstx;

                    for (int x = 1; x < parms.Width; ++x)
                    {
                        for (int i = 0; i < wlen - 1; ++i)
                        {
                            waSums[i] = waSums[i + 1];
                            wcSums[i] = wcSums[i + 1];
                            aSums[i]  = aSums[i + 1];
                        }

                        waSum = 0;
                        wcSum = 0;
                        aSum  = 0;


                        int wx;
                        for (wx = 0; wx < wlen - 1; ++wx)
                        {
                            float wwx = w[wx];
                            waSum += wwx * waSums[wx];
                            wcSum += wwx * wcSums[wx];
                            aSum  += wwx * aSums[wx];
                        }

                        wx = wlen - 1;

                        waSums[wx] = 0;
                        wcSums[wx] = 0;
                        aSums[wx]  = 0;


                        int srcX = x + wx - r;

                        if (srcX >= 0 && srcX < parms.Width)
                        {
                            for (int wy = 0; wy < wlen; ++wy)
                            {
                                int srcY = y + wy - r;

                                if (srcY >= 0 && srcY < parms.Height)
                                {
                                    float c  = InputMask[srcX, srcY];
                                    float wp = w[wy];

                                    waSums[wx] += wp;
                                    wp         *= c;// +(c >> 7);
                                    wcSums[wx] += wp;
                                    //wp >>= 8;

                                    aSums[wx] += wp * c;
                                }
                            }

                            int wr = w[wx];
                            waSum += wr * waSums[wx];
                            wcSum += wr * wcSums[wx];
                            aSum  += wr * aSums[wx];
                        }

                        // wcSum >>= 8;

                        if (waSum == 0 || wcSum == 0)
                        {
                            tmpMask[x, y] = 0;
                        }
                        else
                        {
                            tmpMask[x, y] = (aSum / waSum);
                        }

                        ++dstx;
                    }
                }
            }



            //copy back
            for (int x = 0; x < parms.Width; x++)
            {
                for (int y = 0; y < parms.Height; y++)
                {
                    mp.Value[x, y] = tmpMask[x, y];
                }
            }

            tmpMask = null;

            return(true);
        }
Exemplo n.º 25
0
        protected void generateConnectionPoints()
        {
            List <string> usedDescriptions = new List <string>();

            //try to do this dynamically...
            Type type = GetType();// Get object type

            System.Reflection.PropertyInfo[] pi = type.GetProperties();
            for (int i = 0; i < pi.Length; i++)
            {
                System.Reflection.PropertyInfo prop = pi[i];

                object[] custAttrib = prop.GetCustomAttributes(false);
                if (custAttrib == null)
                {
                    continue;
                }

                ParamType pt  = null;
                Type      ptt = prop.PropertyType;
                if (ptt == typeof(float))
                {
                    pt = new FloatParam();
                }
                else if (ptt == typeof(int))
                {
                    pt = new IntParam();
                }
                else if (ptt == typeof(bool))
                {
                    pt = new BoolParam();
                }
                else if (ptt == typeof(DAGMask))
                {
                    pt = new MaskParam();
                }

                for (int k = 0; k < custAttrib.Length; k++)
                {
                    if (custAttrib[k] is ConnectionType)
                    {
                        ConnectionType ct = custAttrib[k] as ConnectionType;

                        //make sure this connection is unique
                        for (int j = 0; j < usedDescriptions.Count; j++)
                        {
                            if (ct.Description == usedDescriptions[j])
                            {
                                MessageBox.Show(type.FullName + " has already defined a connection value with description " + ct.Description);
                                System.Diagnostics.Debug.Assert(false);
                                return;
                            }
                        }

                        if (ct.ConnType == "Param")
                        {
                            addParamConnectionPoint(pt, ct.Description);
                        }
                        else if (ct.ConnType == "Input")
                        {
                            addInputConnectionPoint(pt, ct.Description, ct.Required);
                        }
                        else if (ct.ConnType == "Output")
                        {
                            addOutputConnectionPoint(pt, ct.Description);
                        }
                        else if (ct.ConnType == "Constraint")
                        {
                            addConstraintConnectionPoint(pt, ct.Description);
                        }
                        else
                        {
                            System.Diagnostics.Debug.Assert(false, "Unrecognized connection type listed for object " + type.FullName);
                        }

                        usedDescriptions.Add(ct.Description);
                        break;
                    }
                }
            }
        }
Exemplo n.º 26
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;



            ///////////////////////////////////////////////////////////////

            int width  = parms.Width;
            int height = parms.Height;
            int rad    = Radius;

            int[] leadingEdgeX = new int[rad + 1];

            // approximately (rad + 0.5)^2
            int cutoff = ((rad * 2 + 1) * (rad * 2 + 1) + 2) / 4;

            for (int v = 0; v <= rad; ++v)
            {
                for (int u = 0; u <= rad; ++u)
                {
                    if (u * u + v * v <= cutoff)
                    {
                        leadingEdgeX[v] = u;
                    }
                }
            }

            const int hLength = 256;

            int[] ha = new int[hLength];

            for (int y = 0; y < parms.Height; y++)
            {
                //calculate our histogram..
                for (int k = 0; k < hLength; k++)
                {
                    ha[k] = 0;
                }

                int area    = 0;
                int maxArea = GetMaxAreaForRadius(rad);

                int top    = -Math.Min(rad, y);
                int bottom = Math.Min(rad, height - 1 - y);
                int left   = -Math.Min(rad, 0);
                int right  = Math.Min(rad, width - 1);


                for (int v = top; v <= bottom; ++v)
                {
                    for (int u = left; u <= right; ++u)
                    {
                        byte psamp = (byte)(InputMask[u, y + v] * 255);

                        if ((u * u + v * v) <= cutoff)
                        {
                            ++area;

                            ++ha[psamp];
                        }
                    }
                }



                for (int x = 0; x < parms.Width; x++)
                {
                    mp.Value[x, y] = GetPercentile(Percent, area, ref ha) / 255.0f;

                    left  = -Math.Min(rad, x);
                    right = Math.Min(rad + 1, width - 1 - x);

                    // Subtract trailing edge top half
                    int v = -1;

                    while (v >= top)
                    {
                        int u = leadingEdgeX[-v];

                        if (-u >= left)
                        {
                            break;
                        }

                        --v;
                    }

                    while (v >= top)
                    {
                        int  u = leadingEdgeX[-v];
                        byte p = (byte)(InputMask[x - u, y + v] * 255);


                        --ha[p];
                        --area;

                        --v;
                    }

                    // add leading edge top half
                    v = -1;
                    while (v >= top)
                    {
                        int u = leadingEdgeX[-v];

                        if (u + 1 <= right)
                        {
                            break;
                        }

                        --v;
                    }

                    while (v >= top)
                    {
                        int  u = leadingEdgeX[-v];
                        byte p = (byte)(InputMask[x + u + 1, y + v] * 255);

                        ++ha[p];
                        ++area;

                        --v;
                    }

                    // Subtract trailing edge bottom half
                    v = 0;

                    while (v <= bottom)
                    {
                        int u = leadingEdgeX[v];

                        if (-u >= left)
                        {
                            break;
                        }

                        ++v;
                    }

                    while (v <= bottom)
                    {
                        int  u = leadingEdgeX[v];
                        byte p = (byte)(InputMask[x - u, y + v] * 255);

                        --ha[p];
                        --area;

                        ++v;
                    }

                    // add leading edge bottom half
                    v = 0;

                    while (v <= bottom)
                    {
                        int u = leadingEdgeX[v];

                        if (u + 1 <= right)
                        {
                            break;
                        }


                        ++v;
                    }

                    while (v <= bottom)
                    {
                        int  u = leadingEdgeX[v];
                        byte p = (byte)(InputMask[x + u + 1, y + v] * 255);

                        ++ha[p];
                        ++area;

                        ++v;
                    }
                }
            }

            return(true);
        }
Exemplo n.º 27
0
        override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms)
        {
            if (!verifyInputConnections())
            {
                return(false);
            }

            if (!gatherInputAndParameters(parms))
            {
                return(false);
            }

            MaskParam mp = ((MaskParam)(connPoint.ParamType));

            mp.Value = InputMask.Clone();
            mp.Value.mConstraintMask = ConstraintMask;

            int workWidth  = parms.Width - 1;
            int workHeight = parms.Height - 1;

            int halfWid = parms.Width >> 1;
            int halfHei = parms.Height >> 1;

            if (Method == (int)eMethod.eLeftToRight)
            {
                for (int x = 0; x < halfWid; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[workWidth - x, y] = InputMask[x, y];
                    }
                }
            }
            else if (Method == (int)eMethod.eRightToLeft)
            {
                for (int x = 0; x < halfWid; x++)
                {
                    for (int y = 0; y < parms.Height; y++)
                    {
                        mp.Value[x, y] = InputMask[workWidth - x, y];
                    }
                }
            }
            else if (Method == (int)eMethod.eTopToBottom)
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < halfHei; y++)
                    {
                        mp.Value[x, y] = InputMask[x, workHeight - y];
                    }
                }
            }
            else if (Method == (int)eMethod.eBottomToTop)
            {
                for (int x = 0; x < parms.Width; x++)
                {
                    for (int y = 0; y < halfHei; y++)
                    {
                        mp.Value[x, workHeight - y] = InputMask[x, y];
                    }
                }
            }



            return(true);
        }