コード例 #1
0
        public override string getProperties(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string propStr = "threshold" + node.getNodeID() + "(\"threshold\", Float) = 0.0\n";

            return(propStr);
        }
コード例 #2
0
        public override string getInputs(BaseNode.NodeInput nodeInput)
        {
            var    node     = nodeInput.inputNode;
            string inputStr = "float threshold" + node.getNodeID() + ";\n";

            return(inputStr);
        }
コード例 #3
0
        public override string getPostEvaluation(BaseNode.NodeInput nodeInput)
        {
            var    node      = nodeInput.inputNode;
            string uvRestore = "uv = uv_store" + node.getNodeID() + ";\n";

            return(uvRestore);
        }
コード例 #4
0
        public override string getProperties(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string propStr = "multiplier" + node.getNodeID() + "(\"multiplier\", Float) = 1.0";

            return(propStr);
        }
コード例 #5
0
        public override string getFunctionName(BaseNode.NodeInput nodeInput)
        {
            var           node      = nodeInput.inputNode;
            StringBuilder signature = new StringBuilder();

            signature.Append("get" + node.GetType().Name + node.getNodeID());

            switch (nodeInput.outputIndex)
            {
            case 0:
                signature.Append("_R");
                break;

            case 1:
                signature.Append("_G");
                break;

            case 2:
                signature.Append("_B");
                break;

            case 3:
                signature.Append("_A");
                break;
            }
            return(signature.ToString());
        }
コード例 #6
0
        public override string getInputs(BaseNode.NodeInput nodeInput)
        {
            var    node     = nodeInput.inputNode;
            string inputStr = "sampler2D texture" + node.getNodeID() + ";\n";

            return(inputStr);
        }
コード例 #7
0
        public override string getInputs(BaseNode.NodeInput nodeInput)
        {
            var    node     = nodeInput.inputNode;
            string inputStr = "fixed4 color" + node.getNodeID() + ";\n";

            return(inputStr);
        }
コード例 #8
0
        public override string getFunctionBody(BaseNode.NodeInput nodeInput)
        {
            string funcBody = "   float t = input2.a;\n";

            funcBody += "   return (input1 * (1.0-t)) + (input2 * t);\n";
            return(funcBody);
        }
コード例 #9
0
        public override string getFunctionBody(BaseNode.NodeInput nodeInput)
        {
            var node = nodeInput.inputNode;

            return("   float s = snoise(float3(uv * noiseScale" + node.getNodeID() + ", noiseZ" + node.getNodeID() + "));\n" +
                   "   return float4(s,s,s,s);\n");
        }
コード例 #10
0
        public override string getProperties(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string propStr = "texture" + node.getNodeID() + "(\"texture\", 2D) = \"\" {}";

            return(propStr);
        }
コード例 #11
0
        public override string getProperties(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string propStr = "color" + node.getNodeID() + "(\"color\", Color) = (0,0,0,0)";

            return(propStr);
        }
コード例 #12
0
        public override string getFunctionBody(BaseNode.NodeInput nodeInput)
        {
            var node = nodeInput.inputNode;

            return("   float4 s = tex2D(texture" + node.getNodeID() + ",uv);\n" +
                   "   return s;\n");
        }
コード例 #13
0
        public override string getInputs(BaseNode.NodeInput nodeInput)
        {
            var    node   = nodeInput.inputNode;
            string inputs = "float noiseScale" + node.getNodeID() + ";\n";

            inputs += "float noiseZ" + node.getNodeID() + ";\n";
            return(inputs);
        }
コード例 #14
0
        public override string getProperties(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string propStr = "scaleU" + node.getNodeID() + "(\"scaleU\", Float) = 0.0\n";

            propStr += "scaleV" + node.getNodeID() + "(\"scaleV\", Float) = 0.0\n";
            return(propStr);
        }
コード例 #15
0
        public virtual string getFunctionName(BaseNode.NodeInput nodeInput)
        {
            var           node      = nodeInput.inputNode;
            StringBuilder signature = new StringBuilder();

            signature.Append("get" + node.GetType().Name + node.getNodeID());
            return(signature.ToString());
        }
コード例 #16
0
        public override string getInputs(BaseNode.NodeInput nodeInput)
        {
            var    node     = nodeInput.inputNode;
            string inputStr = "float weightOne" + node.getNodeID() + ";\n";

            inputStr += "float weightTwo" + node.getNodeID() + ";\n";
            return(inputStr);
        }
コード例 #17
0
        public override string getProperties(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string propStr = "weightOne" + node.getNodeID() + "(\"weightOne\", Float) = 0.0\n";

            propStr += "weightTwo" + node.getNodeID() + "(\"weightTwo\", Float) = 0.0\n";
            return(propStr);
        }
コード例 #18
0
        public override string getInputs(BaseNode.NodeInput nodeInput)
        {
            var    node     = nodeInput.inputNode;
            string inputStr = "float scaleU" + node.getNodeID() + ";\n";

            inputStr += "float scaleV" + node.getNodeID() + ";\n";
            return(inputStr);
        }
コード例 #19
0
        public override string getProperties(BaseNode.NodeInput nodeInput)
        {
            var    node       = nodeInput.inputNode;
            string properties = "noiseScale" + node.getNodeID() + "(\"noise scale\", Float) = 1.0";

            properties += "noiseZ" + node.getNodeID() + "(\"noise z\", Float) = 0.0";
            return(properties);
        }
コード例 #20
0
        public override string getPreEvaluation(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string uvStore = "float2 uv_store" + node.getNodeID() + " = uv;\n";

            uvStore += "float2 translateOffset" + node.getNodeID() + " = float2(translateU" + node.getNodeID() + ", translateV" + node.getNodeID() + ");\n";
            uvStore += "uv -= translateOffset" + node.getNodeID() + ";\n";
            return(uvStore);
        }
コード例 #21
0
        public TextureRecipeRenderer(TextureRecipe _recipe)
        {
            //We are performing a deep copy of the TextureRecipe asset hierarchy. This is so that changes made to the TextureRecipe asset at runtime in the editor
            //don't persist after exiting Play Mode. It also allows us to have multiple renderers using the same TextureRecipe as a source without writing over
            //each others settings. We need to traverse the layer and node hierarchies to clone each object individually and also to remap any references onto the
            //newly-instantiated objects.
            //TODO: move the layer copying logic into the layer classes to give better layer abstraction
            recipe           = GameObject.Instantiate(_recipe); //TODO: better naming here
            recipe.name      = _recipe.name;                    //TODO: necessary?
            recipe.unique_id = _recipe.unique_id;

            int numLayers = recipe.layerList.Count;

            for (int i = 0; i < numLayers; i++)
            {
                var originalLayer = recipe.layerList[i];
                var newLayer      = GameObject.Instantiate(originalLayer);
                recipe.layerList[i] = newLayer;

                //TODO: layer abstraction
                if (originalLayer is ShaderLayer)
                {
                    Dictionary <BaseNode, BaseNode> nodeRemap = new Dictionary <BaseNode, BaseNode>();
                    var shaderLayer = (ShaderLayer)recipe.layerList[i];
                    int numNodes    = shaderLayer.nodes.Count;
                    for (int j = 0; j < numNodes; j++)
                    {
                        var originalNode = shaderLayer.nodes[j];
                        var newNode      = GameObject.Instantiate(originalNode);
                        shaderLayer.nodes[j]    = newNode;
                        nodeRemap[originalNode] = newNode;
                    }

                    for (int j = 0; j < numNodes; j++)
                    {
                        var newNode = shaderLayer.nodes[j];
                        for (int k = 0; k < newNode.inputs.Count; k++)
                        {
                            var oldInputNode = newNode.inputs[k];
                            if (null != oldInputNode.inputNode)
                            {
                                // Debug.Assert(nodeRemap.ContainsKey(oldInputNode.inputNode));
                                if (nodeRemap.ContainsKey(oldInputNode.inputNode))
                                {
                                    BaseNode.NodeInput input = newNode.inputs[k];
                                    input.inputNode   = nodeRemap[oldInputNode.inputNode];
                                    newNode.inputs[k] = input;
                                    Debug.Assert(newNode.inputs[k].inputNode.name.Contains("Clone"));
                                }
                            }
                        }
                    }

                    shaderLayer.root = (RootNode)nodeRemap[shaderLayer.root];
                }
            }
        }
コード例 #22
0
        public override string getProperties(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string propStr = "rotateAmount" + node.getNodeID() + "(\"rotateAmount\", Float) = 0.0\n";

            propStr += "rotateCenterU" + node.getNodeID() + "(\"rotateCenterU\", Float) = 0.0\n";
            propStr += "rotateCenterV" + node.getNodeID() + "(\"rotateCenterV\", Float) = 0.0\n";
            return(propStr);
        }
コード例 #23
0
        public override string getInputs(BaseNode.NodeInput nodeInput)
        {
            var    node     = nodeInput.inputNode;
            string inputStr = "float rotateAmount" + node.getNodeID() + ";\n";

            inputStr += "float rotateCenterU" + node.getNodeID() + ";\n";
            inputStr += "float rotateCenterV" + node.getNodeID() + ";\n";
            return(inputStr);
        }
コード例 #24
0
        public override string getFunctionBody(BaseNode.NodeInput nodeInput)
        {
            var node = nodeInput.inputNode;

            return("   float g = dot(input1, float4(1,1,1,1));\n" +
                   "   if (g > threshold" + node.getNodeID() + ")\n" +
                   "      return input1;\n" +
                   "   else\n" +
                   "      return float4(0,0,0,1);\n");
        }
コード例 #25
0
        public override string getPreEvaluation(BaseNode.NodeInput nodeInput)
        {
            var    node    = nodeInput.inputNode;
            string uvStore = "float2 uv_store" + node.getNodeID() + " = uv;\n";

            uvStore += "float2 scaleFactor" + node.getNodeID() + " = float2(scaleU" + node.getNodeID() + ", scaleV" + node.getNodeID() + ");\n";
            uvStore += "uv -= float2(0.5, 0.5);\n";
            uvStore += "uv /= scaleFactor" + node.getNodeID() + ";\n";
            uvStore += "uv += float2(0.5, 0.5);\n";

            return(uvStore);
        }
コード例 #26
0
        public override string getFunctionBody(BaseNode.NodeInput nodeInput)
        {
            string    funcStr = "";
            SplitNode split   = (SplitNode)nodeInput.inputNode;

            if (split.ReplicateToAllChannels)
            {
                switch (nodeInput.outputIndex)
                {
                case 0:
                    funcStr = "   return input1.r;\n";
                    break;

                case 1:
                    funcStr = "   return input1.g;\n";
                    break;

                case 2:
                    funcStr = "   return input1.b;\n";
                    break;

                case 3:
                    funcStr = "   return input1.a;\n";
                    break;
                }
            }
            else
            {
                switch (nodeInput.outputIndex)
                {
                case 0:
                    funcStr = "   return float4(input1.r,0,0,1);\n";
                    break;

                case 1:
                    funcStr = "   return float4(0,input1.g,0,1);\n";
                    break;

                case 2:
                    funcStr = "   return float4(0,0,input1.b,1);\n";
                    break;

                case 3:
                    funcStr = "   return float4(0,0,0,input1.a);\n";
                    break;
                }
            }

            return(funcStr);
        }
コード例 #27
0
        public string getCallStr(BaseNode.NodeInput nodeInput, Dictionary <string, string> outputVariableNames)
        {
            var    node      = nodeInput.inputNode;
            int    numInputs = node.inputs.Count;
            string callStr   = "";

            //pre evaluation
            callStr += getPreEvaluation(nodeInput);

            for (int i = 0; i < numInputs; i++)
            {
                var input = node.inputs[i];
                if (null != input.inputNode)
                {
                    callStr += GeneratorFactory.getShaderGenerator(input.inputNode).getCallStr(input, outputVariableNames);
                }
            }

            string outputVariableName    = "out" + node.GetType().Name + node.getNodeID() + "_" + nodeInput.outputIndex;
            bool   declareOutputVariable = !outputVariableNames.ContainsKey(outputVariableName);

            if (declareOutputVariable)
            {
                outputVariableNames.Add(outputVariableName, outputVariableName);
                callStr += "fixed4 ";
            }

            callStr += outputVariableName + "= " + getFunctionName(nodeInput) + "( uv,0,0";

            for (int i = 0; i < numInputs; i++)
            {
                callStr += ", ";
                var input = node.inputs[i];
                if (null != input.inputNode)
                {
                    callStr += "out" + input.inputNode.GetType().Name + input.inputNode.getNodeID() + "_" + input.outputIndex;
                }
                else
                {
                    callStr += "float4(0,0,0,0)";
                }
            }

            callStr += " );\n";

            //post-evaluation
            callStr += getPostEvaluation(nodeInput);

            return(callStr);
        }
コード例 #28
0
        public override string getFunctionBody(BaseNode.NodeInput nodeInput)
        {
            string funcStr = "   return float4(";

            MergeNode merge  = (MergeNode)nodeInput.inputNode;
            var       inputR = merge.inputs[0].inputNode;
            var       inputG = merge.inputs[1].inputNode;
            var       inputB = merge.inputs[2].inputNode;
            var       inputA = merge.inputs[3].inputNode;

            if (null != inputR)
            {
                funcStr += "input1.r, ";
            }
            else
            {
                funcStr += "0.0f, ";
            }

            if (null != inputG)
            {
                funcStr += "input2.g, ";
            }
            else
            {
                funcStr += "0.0f, ";
            }

            if (null != inputB)
            {
                funcStr += "input3.b, ";
            }
            else
            {
                funcStr += "0.0f, ";
            }

            if (null != inputA)
            {
                funcStr += "input4.a";
            }
            else
            {
                funcStr += "1.0f";
            }

            funcStr += ");\n";
            return(funcStr);
        }
コード例 #29
0
        public override string getPreEvaluation(BaseNode.NodeInput nodeInput)
        {
            var    node      = nodeInput.inputNode;
            string uvStore   = "float2 uv_store" + node.getNodeID() + " = uv;\n";
            string rotateStr = "rotateAmount" + node.getNodeID();

            //TODO: all these variables need to be scoped or made unique using the node id
            uvStore += "float sinX = sin(" + rotateStr + ");\n";
            uvStore += "float cosX = cos(" + rotateStr + ");\n";
            uvStore += "float sinY = sin(" + rotateStr + ");\n";
            uvStore += "float2x2 rotationMatrix = float2x2(cosX, -sinX, sinY, cosX);\n";
            uvStore += "float2 rotOffset = float2(rotateCenterU" + node.getNodeID() + ", rotateCenterV" + node.getNodeID() + ");\n";
            uvStore += "uv = mul(uv - rotOffset, rotationMatrix) + rotOffset;\n";
            return(uvStore);
        }
コード例 #30
0
        public override string getFunctionBody(BaseNode.NodeInput nodeInput)
        {
            string funcStr = "";

            var    node       = nodeInput.inputNode;
            string selectName = "select" + node.getNodeID();

            funcStr += "   if (" + selectName + " == 0)\n";
            funcStr += "      return input1;\n";
            funcStr += "   else if (" + selectName + " == 1)\n";
            funcStr += "      return input2;\n";
            funcStr += "   else if (" + selectName + " == 2)\n";
            funcStr += "      return input3;\n";
            funcStr += "   return input4;\n";

            return(funcStr);
        }