Exemplo n.º 1
0
        public override DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // Stack required.

            // Get a material:
            UnityEngine.Material material = GetMaterial(TypeID, SubMaterialID);

            // Allocate a target stack now:
            int       targetStack = stackID;
            DrawStack stack       = tex.GetStack(targetStack, info);

            stackID++;

            // Allocate sources:
            AllocateSources(material, info, tex, targetStack, 1);

            // Create our node:
            MaterialStackNode matNode = DrawStore as MaterialStackNode;

            if (matNode == null)
            {
                matNode   = new MaterialStackNodeCleared();
                DrawStore = matNode;
                // This is where the magic happens! Set mesh to being our custom one:
                matNode.Mesh = Mesh_;
            }

            matNode.Material = material;
            matNode.Stack    = stack;

            return(matNode);
        }
Exemplo n.º 2
0
        public override DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // Stack required.

            // Allocate a target stack now:
            int       targetStack = stackID;
            DrawStack stack       = tex.GetStack(targetStack, info);

            stackID++;

            float curAmplitude = 1f;
            float curFrequency = (float)Frequency.GetValue(0, 0);
            float lacunarity   = (float)Lacunarity.GetValue(0, 0);
            float persistence  = (float)Persistence.GetValue(0, 0);
            int   mOctaveCount = (int)OctaveCount.GetValue(0, 0);

            Material[] materials = new Material[mOctaveCount];

            // Stack up "OctaveCount" quads.
            for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++)
            {
                // Update seed:
                long seed = (Seed + currentOctave) & 0xffffffff;

                // And a material.
                UnityEngine.Material material = GetMaterial(TypeID, SubMaterialID);

                // _Data (Seed, Frequency, Amplitude, Jitter):
                material.SetVector("_Data", new Vector4(seed, curFrequency, curAmplitude, 0f));

                // Add to set:
                materials[currentOctave] = material;

                curFrequency *= lacunarity;
                curAmplitude *= persistence;
            }

            // Create our node:
            BlockStackNode bsn = new BlockStackNode();

            DrawStore     = bsn;
            bsn.Mesh      = info.Mesh;
            bsn.Materials = materials;
            bsn.Stack     = stack;

            return(bsn);
        }
Exemplo n.º 3
0
        public override DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // Stack required.

            // Allocate a target stack now:
            int       targetStack = stackID;
            DrawStack stack       = tex.GetStack(targetStack, info);

            stackID++;

            int subID = SubMaterialID;

            // Create the material:
            Material material = GetMaterial(TypeID, subID);

            // _Data (Seed, Frequency, Amplitude, Jitter):
            material.SetVector(
                "_Data",
                DataVector
                );

            if (subID == 3)
            {
                // Minkowski number required.

                // Get the input node:
                TextureNode input = MinkowskiNumber;

                // Allocate it now (must not allocate targetStack in the direct kids):
                int           inputStacks = (targetStack == 0)?1:0;
                DrawStackNode drawNode    = input.Allocate(info, tex, ref inputStacks);

                // Apply it to our material:
                material.SetTexture("_Src0", drawNode.Texture);
            }

            // Create our node:
            MaterialStackNode matNode = new MaterialStackNode();

            DrawStore        = matNode;
            matNode.Mesh     = info.Mesh;
            matNode.Material = material;
            matNode.Stack    = stack;

            return(matNode);
        }
Exemplo n.º 4
0
        public override DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // RandomVectors required.
            if (RandomVectors == null)
            {
                RandomVectors = Resources.Load("Loonim-Random-Vectors") as Texture2D;
            }

            // Stack required.

            // Get a material:
            UnityEngine.Material material = GetMaterial(TypeID, SubMaterialID);

            // _Data:
            material.SetVector(
                "_Data",
                DataVector
                );

            // Allocate a target stack now:
            int       targetStack = stackID;
            DrawStack stack       = tex.GetStack(targetStack, info);

            stackID++;

            // Allocate sources:
            AllocateSources(material, info, tex, targetStack, 2);

            // Random vectors are always SRC2:
            material.SetTexture("_Src2", RandomVectors);

            // Create our node:
            MaterialStackNode matNode = DrawStore as MaterialStackNode;

            if (matNode == null)
            {
                matNode      = new MaterialStackNode();
                DrawStore    = matNode;
                matNode.Mesh = info.Mesh;
            }

            matNode.Material = material;
            matNode.Stack    = stack;

            return(matNode);
        }
Exemplo n.º 5
0
        /// <summary>Gets the stack with the given index, or creates it.</summary>
        public DrawStack GetStack(int id, DrawInfo info)
        {
            // Need to create it? Note that ID will only ever be equal to stack count.
            if (Stacks.Count == id)
            {
                // Create it:
                DrawStack ds = new DrawStack(info);

                // Add it:
                Stacks.Add(ds);

                return(ds);
            }

            // Get it:
            return(Stacks[id]);
        }
Exemplo n.º 6
0
        public override DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // Stack required.

            // Allocate a target stack now:
            int       targetStack = stackID;
            DrawStack stack       = tex.GetStack(targetStack, info);

            stackID++;

            // Allocate sources all to use the exact same stack for their output:

            for (int i = 0; i < Sources.Length; i++)
            {
                // Get the input node:
                TextureNode input = Sources[i];

                // Allocate it now, always allocating the same one as our target:
                int           inputStacks = targetStack;
                DrawStackNode dsn         = input.Allocate(info, tex, ref inputStacks);

                // If it's cleared, set cleared to false for anything but i=0:
                if (i != 0)
                {
                    dsn.Clear = false;
                }
            }

            // Create our node:
            StackerStackNode matNode = DrawStore as StackerStackNode;

            if (matNode == null)
            {
                matNode   = new StackerStackNode();
                DrawStore = matNode;
            }

            matNode.Stack = stack;

            return(matNode);
        }
Exemplo n.º 7
0
        public override DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // Stack required.

            // Allocate a target stack now:
            int       targetStack = stackID;
            DrawStack stack       = tex.GetStack(targetStack, info);

            stackID++;

            int subID = SubMaterialID;

            // Create the material:
            Material material = GetMaterial(TypeID, subID);

            // Allocate Src0:
            TextureNode   input       = Sources[0];
            int           inputStacks = (targetStack == 0)?1:0;
            DrawStackNode drawNode    = input.Allocate(info, tex, ref inputStacks);

            // Apply it to our material:
            material.SetTexture("_Src0", drawNode.Texture);

            // _Data (Rx,Ry,Rx,-Ry):
            material.SetVector(
                "_Data",
                GetDataVector(info)
                );

            // Create our node:
            MaterialStackNode matNode = new MaterialStackNode();

            DrawStore        = matNode;
            matNode.Mesh     = info.Mesh;
            matNode.Material = material;
            matNode.Stack    = stack;

            return(matNode);
        }
Exemplo n.º 8
0
        /// <summary>Allocates GPU drawing meta now.</summary>
        public virtual DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // If the source is a constant or a graph
            // then we don't allocate a material for it.
            // We do, however, create a texture:

            // CONSTANT: 1 * 1 (Texture)
            // GRAPH   : info.ImageX * 1 (Texture)
            // ELSE    : info.ImageX * info.ImageY (Stack)

            int dimensions = OutputDimensions;

            if (dimensions == 2)
            {
                // Stack required.

                // Allocate a target stack now:
                int       targetStack = stackID;
                DrawStack stack       = tex.GetStack(targetStack, info);
                stackID++;

                // Create the material:
                Material material = GetMaterial(MaterialID, SubMaterialID);

                if (Sources != null)
                {
                    int inputStacks = (targetStack == 0)?1:0;

                    for (int i = 0; i < Sources.Length; i++)
                    {
                        // Get the input node:
                        TextureNode input = Sources[i];

                        // Allocate it now (must not allocate targetStack in the direct kids):

                        DrawStackNode drawNode = input.Allocate(info, tex, ref inputStacks);

                        if (inputStacks == targetStack)
                        {
                            // Skip:
                            inputStacks++;
                        }

                        // Apply it to our material:
                        material.SetTexture("_Src" + i, drawNode.Texture);
                    }
                }

                // Create our node:
                MaterialStackNode matNode = DrawStore as MaterialStackNode;

                if (matNode == null)
                {
                    matNode      = new MaterialStackNode();
                    DrawStore    = matNode;
                    matNode.Mesh = info.Mesh;
                }

                matNode.Material = material;
                matNode.Stack    = stack;

                return(matNode);
            }

            // It'll be baked/ drawn by the CPU.

            // Get the width of the texture:
            int width = (dimensions == 1)?info.ImageX : 1;

            TextureStackNode constNode = DrawStore as TextureStackNode;

            if (constNode == null)
            {
                constNode = new TextureStackNode(this, info.HDR, width);
                DrawStore = constNode;
            }

            // Ok:
            return(constNode);
        }