Esempio 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);
        }
Esempio n. 2
0
        public override void Draw(DrawInfo info)
        {
            // Always pull the latest mode, checking if it's changed:
            Property pv = Distance as Property;

            if (pv != null)
            {
                // Update now if we can:
                pv.UpdateIfChanged(info);
            }

            int materialMode = (int)Distance.GetValue(0, 0);

            if (materialMode != MaterialID_)
            {
                // Change!
                MaterialID_ = materialMode;

                // Allocate shader now:
                SubMaterialChanged();
            }

            // Check for changes on jitter and frequency:
            bool updateData = false;

            pv = Jitter as Property;

            if (pv != null)
            {
                // Update now if we can:
                if (pv.UpdateIfChanged(info))
                {
                    updateData = true;
                }
            }

            pv = Frequency as Property;

            if (pv != null)
            {
                // Update now if we can:
                if (pv.UpdateIfChanged(info))
                {
                    updateData = true;
                }
            }

            if (updateData)
            {
                MaterialStackNode msn = DrawStore as MaterialStackNode;

                if (msn != null)
                {
                    msn.Material.SetVector("_Data", DataVector);
                }
            }

            // Draw now:
            base.Draw(info);
        }
Esempio n. 3
0
        public override void Draw(DrawInfo info)
        {
            // Always pull the latest method, checking if it's changed:
            Property pv = Method as Property;

            if (pv != null)
            {
                // Update now if we can:
                pv.UpdateIfChanged(info);
            }

            int method = (int)(Method.GetValue(0, 0));

            if (method != Method_)
            {
                // Change!
                Method_ = method;

                // Allocate shader now:
                SubMaterialChanged();
            }

            // Check for changes on radius:
            bool updateData = false;

            pv = RadiusX as Property;

            if (pv != null)
            {
                // Update now if we can:
                if (pv.UpdateIfChanged(info))
                {
                    updateData = true;
                }
            }

            pv = RadiusY as Property;

            if (pv != null)
            {
                // Update now if we can:
                if (pv.UpdateIfChanged(info))
                {
                    updateData = true;
                }
            }

            if (updateData)
            {
                MaterialStackNode msn = DrawStore as MaterialStackNode;

                if (msn != null)
                {
                    msn.Material.SetVector("_Data", GetDataVector(info));
                }
            }

            // Draw now:
            base.Draw(info);
        }
Esempio n. 4
0
        /// <summary>Called when this nodes SubMaterialID has changed.</summary>
        public void SubMaterialChanged()
        {
            // Get the stack node:
            MaterialStackNode matNode = DrawStore as MaterialStackNode;

            if (matNode != null)
            {
                // Update the shader now:
                matNode.Material.shader = GetShader(TypeID, SubMaterialID);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public void CollectMaterials(List <Material> into)
        {
            MaterialStackNode msn = (DrawStore as MaterialStackNode);

            if (msn != null)
            {
                // Add my material:
                into.Add(msn.Material);
            }

            if (Sources != null)
            {
                // For each source..
                for (int i = 0; i < Sources.Length; i++)
                {
                    // Collect its materials too:
                    Sources[i].CollectMaterials(into);
                }
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }