Esempio n. 1
0
        public string GetFunc(NoiseTypes type, int nDimensions, bool wraps)
        {
            switch (type)
            {
            case NoiseTypes.White: return("hashTo1");

            case NoiseTypes.Blocky: return("GridNoise");

            case NoiseTypes.Linear: return("LinearNoise");

            case NoiseTypes.Smooth: return("SmoothNoise");

            case NoiseTypes.Smoother: return("SmootherNoise");

            case NoiseTypes.Perlin: return("PerlinNoise");

            case NoiseTypes.Worley:
                if (IsWorleyDefault)
                {
                    return("WorleyNoise");
                }
                else
                {
                    return("Worley_" + UID);
                }

            default: throw new NotImplementedException(type.ToString());
            }
        }
Esempio n. 2
0
        private static List <string> GetInputNames(NoiseTypes t, int nDimensions)
        {
            List <string> n = new List <string>();

            //Seeds.
            n.Add("x");
            if (nDimensions > 1)
            {
                n.Add("y");
            }
            if (nDimensions > 2)
            {
                n.Add("z");
            }
            if (nDimensions > 3)
            {
                n.Add("w");
            }

            //Scale and weight.
            n.Add("Scale");
            n.Add("Weight");

            //Noise-specific extras.
            switch (t)
            {
            case NoiseTypes.White:
            case NoiseTypes.Blocky:
            case NoiseTypes.Linear:
            case NoiseTypes.Smooth:
            case NoiseTypes.Smoother:
            case NoiseTypes.Perlin:
                break;

            case NoiseTypes.Worley:
                n.Add("Cell Variance X");
                if (nDimensions > 1)
                {
                    n.Add("Cell Variance Y");
                }
                if (nDimensions > 2)
                {
                    n.Add("Cell Variance Z");
                }
                if (nDimensions > 3)
                {
                    n.Add("Cell Variance W");
                }
                break;

            default: throw new NotImplementedException(t.ToString());
            }
            return(n);
        }
Esempio n. 3
0
        public override void EmitCode(StringBuilder outCode)
        {
            outCode.Append("float ");
            outCode.Append(OutputName);
            outCode.Append(" = ");
            outCode.Append(Inputs[NDimensions + 1].GetExpression(Owner));
            outCode.Append(" * ");
            outCode.Append(GetFunc(NoiseType, NDimensions));
            outCode.Append("(");
            outCode.Append(Inputs[NDimensions].GetExpression(Owner));
            outCode.Append(" * float");
            outCode.Append(NDimensions);
            outCode.Append("(");
            for (int i = 0; i < NDimensions; ++i)
            {
                outCode.Append(Inputs[i].GetExpression(Owner));
                if (i < NDimensions - 1)
                {
                    outCode.Append(", ");
                }
            }
            outCode.Append(")");
            switch (NoiseType)
            {
            case NoiseTypes.White:
            case NoiseTypes.Blocky:
            case NoiseTypes.Linear:
            case NoiseTypes.Smooth:
            case NoiseTypes.Smoother:
            case NoiseTypes.Perlin:
                break;

            case NoiseTypes.Worley:
                outCode.Append(", float");
                outCode.Append(NDimensions);
                outCode.Append("(");
                for (int i = 0; i < NDimensions; ++i)
                {
                    if (i > 0)
                    {
                        outCode.Append(", ");
                    }

                    int index = NDimensions + 2 + i;
                    outCode.Append(Inputs[index].GetExpression(Owner));
                }
                outCode.Append(")");
                break;

            default: throw new NotImplementedException(NoiseType.ToString());
            }
            outCode.AppendLine(");");
        }
Esempio n. 4
0
        private static List <float> GetInputDefaultVals(NoiseTypes t, int nDimensions)
        {
            List <float> n = new List <float>();

            //Seeds.
            for (int i = 0; i < nDimensions; ++i)
            {
                n.Add(0.0f);
            }

            //Scale and weight.
            n.Add(1.0f);
            n.Add(1.0f);

            //Noise-specific extras.
            switch (t)
            {
            case NoiseTypes.White:
            case NoiseTypes.Blocky:
            case NoiseTypes.Linear:
            case NoiseTypes.Smooth:
            case NoiseTypes.Smoother:
            case NoiseTypes.Perlin:
                break;

            case NoiseTypes.Worley:
                n.Add(0.5f);
                if (nDimensions > 1)
                {
                    n.Add(0.5f);
                }
                if (nDimensions > 2)
                {
                    n.Add(0.5f);
                }
                if (nDimensions > 3)
                {
                    n.Add(0.5f);
                }
                break;

            default: throw new NotImplementedException(t.ToString());
            }
            return(n);
        }
Esempio n. 5
0
        private static List<string> GetInputNames(NoiseTypes t, int nDimensions)
        {
            List<string> n = new List<string>();

            //Seeds.
            n.Add("x");
            if (nDimensions > 1)
                n.Add("y");
            if (nDimensions > 2)
                n.Add("z");

            //Scale and weight.
            n.Add("Scale");
            n.Add("Weight");

            //Noise-specific extras.
            switch (t)
            {
                case NoiseTypes.White:
                case NoiseTypes.Blocky:
                case NoiseTypes.Linear:
                case NoiseTypes.Smooth:
                case NoiseTypes.Smoother:
                case NoiseTypes.Perlin:
                    break;
                case NoiseTypes.Worley:
                    n.Add("Cell Variance X");
                    if (nDimensions > 1)
                        n.Add("Cell Variance Y");
                    if (nDimensions > 2)
                        n.Add("Cell Variance Z");
                    break;
                default: throw new NotImplementedException(t.ToString());
            }
            return n;
        }
Esempio n. 6
0
        private static List<float> GetInputDefaultVals(NoiseTypes t, int nDimensions)
        {
            List<float> n = new List<float>();

            //Seeds.
            for (int i = 0; i < nDimensions; ++i)
                n.Add(0.0f);

            //Scale and weight.
            n.Add(1.0f);
            n.Add(1.0f);

            //Noise-specific extras.
            switch (t)
            {
                case NoiseTypes.White:
                case NoiseTypes.Blocky:
                case NoiseTypes.Linear:
                case NoiseTypes.Smooth:
                case NoiseTypes.Smoother:
                case NoiseTypes.Perlin:
                    break;
                case NoiseTypes.Worley:
                    n.Add(0.5f);
                    if (nDimensions > 1)
                        n.Add(0.5f);
                    if (nDimensions > 2)
                        n.Add(0.5f);
                    break;
                default: throw new NotImplementedException(t.ToString());
            }
            return n;
        }
Esempio n. 7
0
        private static List<NodeInput> GenerateInputs(NoiseTypes t, int nDimensions,
													  List<NodeInput> currentInputs = null)
        {
            List<NodeInput> ni = new List<NodeInput>();

            //Seed.
            for (int i = 0; i < nDimensions; ++i)
            {
                if (currentInputs != null && currentInputs.Count > i)
                    ni.Add(currentInputs[i]);
                else
                    ni.Add(new NodeInput(0.0f));
            }

            //Scale.
            if (currentInputs != null && currentInputs.Count > nDimensions)
                ni.Add(currentInputs[nDimensions]);
            else
                ni.Add(new NodeInput(1.0f));
            //Weight.
            if (currentInputs != null && currentInputs.Count > nDimensions + 1)
                ni.Add(currentInputs[nDimensions + 1]);
            else
                ni.Add(new NodeInput(1.0f));

            //Noise-specific extras.
            switch (t)
            {
                case NoiseTypes.White:
                case NoiseTypes.Blocky:
                case NoiseTypes.Linear:
                case NoiseTypes.Smooth:
                case NoiseTypes.Smoother:
                case NoiseTypes.Perlin:
                    break;
                case NoiseTypes.Worley:
                    for (int i = 0; i < nDimensions; ++i)
                    {
                        int index = nDimensions + 2 + i;
                        if (currentInputs == null || currentInputs.Count <= index)
                            ni.Add(new NodeInput(0.5f));
                        else
                            ni.Add(currentInputs[index]);
                    }
                    break;
                default: throw new NotImplementedException(t.ToString());
            }

            return ni;
        }
Esempio n. 8
0
 public string GetFunc(NoiseTypes type, int nDimensions)
 {
     switch (type)
     {
         case NoiseTypes.White: return "hashValue" + nDimensions;
         case NoiseTypes.Blocky: return "GridNoise" + nDimensions;
         case NoiseTypes.Linear: return "LinearNoise" + nDimensions;
         case NoiseTypes.Smooth: return "SmoothNoise" + nDimensions;
         case NoiseTypes.Smoother: return "SmootherNoise" + nDimensions;
         case NoiseTypes.Perlin: return "PerlinNoise" + nDimensions;
         case NoiseTypes.Worley:
             if (IsWorleyDefault)
                 return "WorleyNoise" + NDimensions;
             else
                 return "Worley_" + UID;
         default: throw new NotImplementedException(type.ToString());
     }
 }
Esempio n. 9
0
        private static List <NodeInput> GenerateInputs(NoiseTypes t, int nDimensions,
                                                       List <NodeInput> currentInputs = null)
        {
            List <NodeInput> ni = new List <NodeInput>();

            //Seed.
            for (int i = 0; i < nDimensions; ++i)
            {
                if (currentInputs != null && currentInputs.Count > i)
                {
                    ni.Add(currentInputs[i]);
                }
                else
                {
                    ni.Add(new NodeInput(0.0f));
                }
            }

            //Scale.
            if (currentInputs != null && currentInputs.Count > nDimensions)
            {
                ni.Add(currentInputs[nDimensions]);
            }
            else
            {
                ni.Add(new NodeInput(1.0f));
            }
            //Weight.
            if (currentInputs != null && currentInputs.Count > nDimensions + 1)
            {
                ni.Add(currentInputs[nDimensions + 1]);
            }
            else
            {
                ni.Add(new NodeInput(1.0f));
            }

            //Noise-specific extras.
            switch (t)
            {
            case NoiseTypes.White:
            case NoiseTypes.Blocky:
            case NoiseTypes.Linear:
            case NoiseTypes.Smooth:
            case NoiseTypes.Smoother:
            case NoiseTypes.Perlin:
                break;

            case NoiseTypes.Worley:
                for (int i = 0; i < nDimensions; ++i)
                {
                    int index = nDimensions + 2 + i;
                    if (currentInputs == null || currentInputs.Count <= index)
                    {
                        ni.Add(new NodeInput(0.5f));
                    }
                    else
                    {
                        ni.Add(currentInputs[index]);
                    }
                }
                break;

            default: throw new NotImplementedException(t.ToString());
            }

            return(ni);
        }