Пример #1
0
        public T GetParameterValue <T>(string id, string parameter)
        {
            string cid = id + "." + parameter;

            GraphParameterValue p = null;

            if (Parameters.TryGetValue(cid, out p))
            {
                if (p.IsFunction())
                {
                    FunctionGraph g = p.Value as FunctionGraph;

                    g.TryAndProcess();

                    if (g.Result == null)
                    {
                        return(default(T));
                    }

                    return((T)g.Result);
                }
                else
                {
                    return((T)p.Value);
                }
            }

            return(default(T));
        }
Пример #2
0
        protected void BuildShaderFunctionValue(GraphParameterValue param, StringBuilder builder)
        {
            FunctionGraph fn = param.Value as FunctionGraph;

            fn.TryAndProcess();
            object value = fn.Result;

            if (param.Type == NodeType.Bool)
            {
                builder.Append(Convert.ToBoolean(param.Value).ToString().ToLower() + ";\r\n");
            }
            else if (param.Type == NodeType.Float)
            {
                builder.Append(Convert.ToSingle(value).ToString() + ";\r\n");
            }
            else if (param.Type == NodeType.Float4 || param.Type == NodeType.Gray || param.Type == NodeType.Color)
            {
                MVector vec = new MVector();

                if (value is MVector)
                {
                    vec = (MVector)value;
                }

                builder.Append("vec4(" + vec.X + "," + vec.Y + "," + vec.Z + "," + vec.W + ");\r\n");
            }
            else if (param.Type == NodeType.Float2)
            {
                MVector vec = new MVector();

                if (value is MVector)
                {
                    vec = (MVector)value;
                }

                builder.Append("vec2(" + vec.X + "," + vec.Y + ");\r\n");
            }
            else if (param.Type == NodeType.Float3)
            {
                MVector vec = new MVector();

                if (value is MVector)
                {
                    vec = (MVector)value;
                }

                builder.Append("vec3(" + vec.X + "," + vec.Y + "," + vec.Z + ");\r\n");
            }
            else if (param.Type == NodeType.Matrix && value is Matrix4)
            {
                Matrix4 m4 = (Matrix4)value;
                //glsl matrices are column major order
                builder.Append("mat3(" + m4.Column0.X + ", " + m4.Column0.Y + ", " + m4.Column0.Z + ", " + m4.Column0.W + ", "
                               + m4.Column1.X + ", " + m4.Column1.Y + ", " + m4.Column1.Z + ", " + m4.Column1.W + ", "
                               + m4.Column2.X + ", " + m4.Column2.Y + ", " + m4.Column2.Z + ", " + m4.Column2.W + ","
                               + m4.Column3.X + ", " + m4.Column3.Y + ", " + m4.Column3.Z + ", " + m4.Column3.W + ");\r\n");
            }
        }
Пример #3
0
        public object GetParameterValue(string id, string parameter)
        {
            string cid = id + "." + parameter;

            GraphParameterValue p = null;

            if (Parameters.TryGetValue(cid, out p))
            {
                if (p.IsFunction())
                {
                    FunctionGraph g = p.Value as FunctionGraph;

                    g.TryAndProcess();

                    return(g.Result);
                }
                else
                {
                    return(p.Value);
                }
            }

            return(null);
        }
Пример #4
0
        protected void BuildShaderFunctionValue(GraphParameterValue param, StringBuilder builder)
        {
            FunctionGraph fn = param.Value as FunctionGraph;

            fn.TryAndProcess();
            object value = fn.Result;

            if (param.Type == NodeType.Bool)
            {
                try
                {
                    builder.Append(Convert.ToBoolean(value).ToString().ToLower() + ";\r\n");
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    Log.Info("Defaulting to false for value of parameter " + param.Name);
                    builder.Append("false;\r\n");
                }
            }
            else if (param.Type == NodeType.Float)
            {
                try
                {
                    builder.Append(Convert.ToSingle(value).ToCodeString() + ";\r\n");
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    Log.Info("Defaulting to 0 for value of parameter " + param.Name);
                    builder.Append("0;\r\n");
                }
            }
            else if (param.Type == NodeType.Float4 || param.Type == NodeType.Gray || param.Type == NodeType.Color)
            {
                MVector vec = new MVector();

                if (value is MVector)
                {
                    vec = (MVector)value;
                }

                builder.Append("vec4(" + vec.X.ToCodeString() + "," + vec.Y.ToCodeString() + "," + vec.Z.ToCodeString() + "," + vec.W.ToCodeString() + ");\r\n");
            }
            else if (param.Type == NodeType.Float2)
            {
                MVector vec = new MVector();

                if (value is MVector)
                {
                    vec = (MVector)value;
                }

                builder.Append("vec2(" + vec.X.ToCodeString() + "," + vec.Y.ToCodeString() + ");\r\n");
            }
            else if (param.Type == NodeType.Float3)
            {
                MVector vec = new MVector();

                if (value is MVector)
                {
                    vec = (MVector)value;
                }

                builder.Append("vec3(" + vec.X.ToCodeString() + "," + vec.Y.ToCodeString() + "," + vec.Z.ToCodeString() + ");\r\n");
            }
            else if (param.Type == NodeType.Matrix && value is Matrix4)
            {
                Matrix4 m4 = (Matrix4)value;
                //glsl matrices are column major order
                builder.Append("mat3(" + m4.Column0.X.ToCodeString() + ", " + m4.Column0.Y.ToCodeString() + ", " + m4.Column0.Z.ToCodeString() + ", " + m4.Column0.W.ToCodeString() + ", "
                               + m4.Column1.X.ToCodeString() + ", " + m4.Column1.Y.ToCodeString() + ", " + m4.Column1.Z.ToCodeString() + ", " + m4.Column1.W.ToCodeString() + ", "
                               + m4.Column2.X.ToCodeString() + ", " + m4.Column2.Y.ToCodeString() + ", " + m4.Column2.Z.ToCodeString() + ", " + m4.Column2.W.ToCodeString() + ","
                               + m4.Column3.X.ToCodeString() + ", " + m4.Column3.Y.ToCodeString() + ", " + m4.Column3.Z.ToCodeString() + ", " + m4.Column3.W.ToCodeString() + ");\r\n");
            }
        }