public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
 {
     if (!generationMode.IsPreview())
     {
         sb.AppendLine("$precision4 _{0}_m0 = $precision4 ({1}, {2}, {3}, {4});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row0.x),
                       NodeUtils.FloatToShaderValue(m_Row0.y),
                       NodeUtils.FloatToShaderValue(m_Row0.z),
                       NodeUtils.FloatToShaderValue(m_Row0.w));
         sb.AppendLine("$precision4 _{0}_m1 = $precision4 ({1}, {2}, {3}, {4});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row1.x),
                       NodeUtils.FloatToShaderValue(m_Row1.y),
                       NodeUtils.FloatToShaderValue(m_Row1.z),
                       NodeUtils.FloatToShaderValue(m_Row1.w));
         sb.AppendLine("$precision4 _{0}_m2 = $precision4 ({1}, {2}, {3}, {4});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row2.x),
                       NodeUtils.FloatToShaderValue(m_Row2.y),
                       NodeUtils.FloatToShaderValue(m_Row2.z),
                       NodeUtils.FloatToShaderValue(m_Row2.w));
         sb.AppendLine("$precision4 _{0}_m3 = $precision4 ({1}, {2}, {3}, {4});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row3.x),
                       NodeUtils.FloatToShaderValue(m_Row3.y),
                       NodeUtils.FloatToShaderValue(m_Row3.z),
                       NodeUtils.FloatToShaderValue(m_Row3.w));
     }
     sb.AppendLine("$precision4x4 {0} = $precision4x4 (_{0}_m0.x, _{0}_m0.y, _{0}_m0.z, _{0}_m0.w, _{0}_m1.x, _{0}_m1.y, _{0}_m1.z, _{0}_m1.w, _{0}_m2.x, _{0}_m2.y, _{0}_m2.z, _{0}_m2.w, _{0}_m3.x, _{0}_m3.y, _{0}_m3.z, _{0}_m3.w);",
                   GetVariableNameForNode());
 }
 protected override string ConcreteSlotValueAsVariable()
 {
     return(string.Format(m_ColorMode == ColorMode.Default ? "IsGammaSpace() ? $precision3({0}, {1}, {2}) : SRGBToLinear($precision3({0}, {1}, {2}))" : "$precision3({0}, {1}, {2})"
                          , NodeUtils.FloatToShaderValue(value.x)
                          , NodeUtils.FloatToShaderValue(value.y)
                          , NodeUtils.FloatToShaderValue(value.z)));
 }
Esempio n. 3
0
 protected override string ConcreteSlotValueAsVariable()
 {
     return(string.Format("$precision3 ({0}, {1}, {2})"
                          , NodeUtils.FloatToShaderValue(value.x)
                          , NodeUtils.FloatToShaderValue(value.y)
                          , NodeUtils.FloatToShaderValue(value.z)));
 }
Esempio n. 4
0
        public override string GetPropertyBlockString()
        {
            var result = new StringBuilder();

            result.Append(referenceName);
            result.Append("(\"");
            result.Append(displayName);
            switch (floatType)
            {
            case FloatType.Slider:
                result.Append("\", Range(");
                result.Append(m_RangeValues.x + ", " + m_RangeValues.y);
                result.Append(")) = ");
                break;

            case FloatType.Integer:
                result.Append("\", Int) = ");
                break;

            default:
                result.Append("\", Float) = ");
                break;
            }
            result.Append(NodeUtils.FloatToShaderValue(value));
            return(result.ToString());
        }
Esempio n. 5
0
        internal override string GetPropertyDeclarationString(string delimiter = ";")
        {
            ShaderStringBuilder s = new ShaderStringBuilder();

            s.AppendLine("Gradient {0}_Definition()", referenceName);
            using (s.BlockScope())
            {
                string[] colors = new string[8];
                for (int i = 0; i < colors.Length; i++)
                {
                    colors[i] = string.Format("g.colors[{0}] = {1}4(0, 0, 0, 0);", i, concretePrecision.ToShaderString());
                }
                for (int i = 0; i < value.colorKeys.Length; i++)
                {
                    colors[i] = string.Format("g.colors[{0}] = {1}4({2}, {3}, {4}, {5});"
                                              , i
                                              , concretePrecision.ToShaderString()
                                              , NodeUtils.FloatToShaderValue(value.colorKeys[i].color.r)
                                              , NodeUtils.FloatToShaderValue(value.colorKeys[i].color.g)
                                              , NodeUtils.FloatToShaderValue(value.colorKeys[i].color.b)
                                              , NodeUtils.FloatToShaderValue(value.colorKeys[i].time));
                }

                string[] alphas = new string[8];
                for (int i = 0; i < alphas.Length; i++)
                {
                    alphas[i] = string.Format("g.alphas[{0}] = {1}2(0, 0);", i, concretePrecision.ToShaderString());
                }
                for (int i = 0; i < value.alphaKeys.Length; i++)
                {
                    alphas[i] = string.Format("g.alphas[{0}] = {1}2({2}, {3});"
                                              , i
                                              , concretePrecision.ToShaderString()
                                              , NodeUtils.FloatToShaderValue(value.alphaKeys[i].alpha)
                                              , NodeUtils.FloatToShaderValue(value.alphaKeys[i].time));
                }

                s.AppendLine("Gradient g;");
                s.AppendLine("g.type = {0};",
                             (int)value.mode);
                s.AppendLine("g.colorsLength = {0};",
                             value.colorKeys.Length);
                s.AppendLine("g.alphasLength = {0};",
                             value.alphaKeys.Length);

                for (int i = 0; i < colors.Length; i++)
                {
                    s.AppendLine(colors[i]);
                }

                for (int i = 0; i < alphas.Length; i++)
                {
                    s.AppendLine(alphas[i]);
                }
                s.AppendLine("return g;", true);
            }
            s.AppendIndentation();
            s.Append("#define {0} {0}_Definition()", referenceName);
            return(s.ToString());
        }
Esempio n. 6
0
        public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
        {
            var sb = new ShaderStringBuilder();

            if (!generationMode.IsPreview())
            {
                sb.AppendLine("{0}4 _{1}_m0 = {0}4 ({2}, {3}, {4}, {5});", precision, GetVariableNameForNode(),
                              NodeUtils.FloatToShaderValue(m_Row0.x),
                              NodeUtils.FloatToShaderValue(m_Row0.y),
                              NodeUtils.FloatToShaderValue(m_Row0.z),
                              NodeUtils.FloatToShaderValue(m_Row0.w));
                sb.AppendLine("{0}4 _{1}_m1 = {0}4 ({2}, {3}, {4}, {5});", precision, GetVariableNameForNode(),
                              NodeUtils.FloatToShaderValue(m_Row1.x),
                              NodeUtils.FloatToShaderValue(m_Row1.y),
                              NodeUtils.FloatToShaderValue(m_Row1.z),
                              NodeUtils.FloatToShaderValue(m_Row1.w));
                sb.AppendLine("{0}4 _{1}_m2 = {0}4 ({2}, {3}, {4}, {5});", precision, GetVariableNameForNode(),
                              NodeUtils.FloatToShaderValue(m_Row2.x),
                              NodeUtils.FloatToShaderValue(m_Row2.y),
                              NodeUtils.FloatToShaderValue(m_Row2.z),
                              NodeUtils.FloatToShaderValue(m_Row2.w));
                sb.AppendLine("{0}4 _{1}_m3 = {0}4 ({2}, {3}, {4}, {5});", precision, GetVariableNameForNode(),
                              NodeUtils.FloatToShaderValue(m_Row3.x),
                              NodeUtils.FloatToShaderValue(m_Row3.y),
                              NodeUtils.FloatToShaderValue(m_Row3.z),
                              NodeUtils.FloatToShaderValue(m_Row3.w));
            }
            sb.AppendLine("{0}4x4 {1} = {0}4x4 (_{1}_m0.x, _{1}_m0.y, _{1}_m0.z, _{1}_m0.w, _{1}_m1.x, _{1}_m1.y, _{1}_m1.z, _{1}_m1.w, _{1}_m2.x, _{1}_m2.y, _{1}_m2.z, _{1}_m2.w, _{1}_m3.x, _{1}_m3.y, _{1}_m3.z, _{1}_m3.w);",
                          precision, GetVariableNameForNode());
            visitor.AddShaderChunk(sb.ToString(), false);
        }
Esempio n. 7
0
        public override string GetPropertyBlockString()
        {
            if (!generatePropertyBlock)
            {
                return(string.Empty);
            }

            var result = new StringBuilder();

            if (colorMode == ColorMode.HDR)
            {
                result.Append("[HDR]");
            }
            if (m_Hidden)
            {
                result.Append("[HideInInspector] ");
            }
            result.Append(referenceName);
            result.Append("(\"");
            result.Append(displayName);
            result.Append("\", Color) = (");
            result.Append(NodeUtils.FloatToShaderValue(value.r));
            result.Append(",");
            result.Append(NodeUtils.FloatToShaderValue(value.g));
            result.Append(",");
            result.Append(NodeUtils.FloatToShaderValue(value.b));
            result.Append(",");
            result.Append(NodeUtils.FloatToShaderValue(value.a));
            result.Append(")");
            return(result.ToString());
        }
Esempio n. 8
0
 protected override string ConcreteSlotValueAsVariable()
 {
     return(string.Format("IsGammaSpace() ? $precision4({0}, {1}, {2}, {3}) : $precision4 (SRGBToLinear($precision3({0}, {1}, {2})), {3})"
                          , NodeUtils.FloatToShaderValue(value.x)
                          , NodeUtils.FloatToShaderValue(value.y)
                          , NodeUtils.FloatToShaderValue(value.z)
                          , NodeUtils.FloatToShaderValue(value.w)));
 }
Esempio n. 9
0
 protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
 {
     return(string.Format(m_ColorMode == ColorMode.Default ? "IsGammaSpace() ? {0}3({1}, {2}, {3}) : SRGBToLinear({0}3({1}, {2}, {3}))" : "{0}3({1}, {2}, {3})"
                          , precision
                          , NodeUtils.FloatToShaderValue(value.x)
                          , NodeUtils.FloatToShaderValue(value.y)
                          , NodeUtils.FloatToShaderValue(value.z)));
 }
Esempio n. 10
0
 protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
 {
     return(string.Format("IsGammaSpace() ? {0}4({1}, {2}, {3}, {4}) : {0}4 (SRGBToLinear({0}3({1}, {2}, {3})), {4})"
                          , precision
                          , NodeUtils.FloatToShaderValue(value.x)
                          , NodeUtils.FloatToShaderValue(value.y)
                          , NodeUtils.FloatToShaderValue(value.z)
                          , NodeUtils.FloatToShaderValue(value.w)));
 }
 protected override string ConcreteSlotValueAsVariable()
 {
     var channelCount = SlotValueHelper.GetChannelCount(concreteValueType);
     string values = NodeUtils.FloatToShaderValue(value.m00);
     if (channelCount == 1)
         return values;
     for (var i = 1; i < channelCount; i++)
         values += ", " + NodeUtils.FloatToShaderValue(value.GetRow(0)[i]);
     return string.Format("$precision{0}({1})", channelCount, values);
 }
 public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
 {
     if (!generationMode.IsPreview())
     {
         sb.AppendLine("$precision2 _{0}_m0 = $precision2 ({1}, {2});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row0.x),
                       NodeUtils.FloatToShaderValue(m_Row0.y));
         sb.AppendLine("$precision2 _{0}_m1 = $precision2 ({1}, {2});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row1.x),
                       NodeUtils.FloatToShaderValue(m_Row1.y));
     }
     sb.AppendLine("$precision2x2 {0} = $precision2x2 (_{0}_m0.x, _{0}_m0.y, _{0}_m1.x, _{0}_m1.y);", GetVariableNameForNode());
 }
        public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
        {
            if (generationMode.IsPreview())
            {
                return;
            }

            sb.AppendLine(@"$precision4 {0} = IsGammaSpace() ? $precision4({1}, {2}, {3}, {4}) : $precision4(SRGBToLinear($precision3({1}, {2}, {3})), {4});"
                          , GetVariableNameForNode()
                          , NodeUtils.FloatToShaderValue(color.color.r)
                          , NodeUtils.FloatToShaderValue(color.color.g)
                          , NodeUtils.FloatToShaderValue(color.color.b)
                          , NodeUtils.FloatToShaderValue(color.color.a));
        }
Esempio n. 14
0
        protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
        {
            var    channelCount = SlotValueHelper.GetChannelCount(concreteValueType);
            string values       = NodeUtils.FloatToShaderValue(value.x);

            if (channelCount == 1)
            {
                return(values);
            }
            for (var i = 1; i < channelCount; i++)
            {
                values += ", " + value[i];
            }
            return(string.Format("{0}{1}({2})", precision, channelCount, values));
        }
        public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
        {
            if (generationMode.IsPreview())
            {
                return;
            }

            visitor.AddShaderChunk(string.Format(
                                       @"{0}4 {1} = IsGammaSpace() ? {0}4({2}, {3}, {4}, {5}) : {0}4(SRGBToLinear({0}3({2}, {3}, {4})), {5});"
                                       , precision
                                       , GetVariableNameForNode()
                                       , NodeUtils.FloatToShaderValue(color.color.r)
                                       , NodeUtils.FloatToShaderValue(color.color.g)
                                       , NodeUtils.FloatToShaderValue(color.color.b)
                                       , NodeUtils.FloatToShaderValue(color.color.a)), true);
        }
Esempio n. 16
0
        public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
        {
            if (generationMode.IsPreview())
            {
                return;
            }

            var s = string.Format("{0}3 {1} = {0}3({2},{3},{4});",
                                  precision,
                                  GetVariableNameForNode(),
                                  NodeUtils.FloatToShaderValue(m_Value.x),
                                  NodeUtils.FloatToShaderValue(m_Value.y),
                                  NodeUtils.FloatToShaderValue(m_Value.z));

            visitor.AddShaderChunk(s, true);
        }
Esempio n. 17
0
        public override string GetPropertyBlockString()
        {
            switch (floatType)
            {
            case FloatType.Slider:
                return($"{hideTagString}{referenceName}(\"{displayName}\", Range({NodeUtils.FloatToShaderValue(m_RangeValues.x)}, {NodeUtils.FloatToShaderValue(m_RangeValues.y)})) = {NodeUtils.FloatToShaderValue(value)}");

            case FloatType.Integer:
                return($"{hideTagString}{referenceName}(\"{displayName}\", Int) = {NodeUtils.FloatToShaderValue(value)}");

            case FloatType.Enum:
                return($"{hideTagString}{enumTagString}{referenceName}(\"{displayName}\", Float) = {NodeUtils.FloatToShaderValue(value)}");

            default:
                return($"{hideTagString}{referenceName}(\"{displayName}\", Float) = {NodeUtils.FloatToShaderValue(value)}");
            }
        }
Esempio n. 18
0
        public void GenerateNodeCode(ShaderGenerator visitor, GraphContext graphContext, GenerationMode generationMode)
        {
            var sb = new ShaderStringBuilder();

            if (!generationMode.IsPreview())
            {
                sb.AppendLine("{0}2 _{1}_m0 = {0}2 ({2}, {3});", precision, GetVariableNameForNode(),
                              NodeUtils.FloatToShaderValue(m_Row0.x),
                              NodeUtils.FloatToShaderValue(m_Row0.y));
                sb.AppendLine("{0}2 _{1}_m1 = {0}2 ({2}, {3});", precision, GetVariableNameForNode(),
                              NodeUtils.FloatToShaderValue(m_Row1.x),
                              NodeUtils.FloatToShaderValue(m_Row1.y));
            }
            sb.AppendLine("{0}2x2 {1} = {0}2x2 (_{1}_m0.x, _{1}_m0.y, _{1}_m1.x, _{1}_m1.y);",
                          precision, GetVariableNameForNode());
            visitor.AddShaderChunk(sb.ToString(), false);
        }
        public override string GetPropertyBlockString()
        {
            var result = new StringBuilder();

            result.Append(referenceName);
            result.Append("(\"");
            result.Append(displayName);
            result.Append("\", Vector) = (");
            result.Append(NodeUtils.FloatToShaderValue(value.x));
            result.Append(",");
            result.Append(NodeUtils.FloatToShaderValue(value.y));
            result.Append(",");
            result.Append(NodeUtils.FloatToShaderValue(value.z));
            result.Append(",");
            result.Append(NodeUtils.FloatToShaderValue(value.w));
            result.Append(")");
            return(result.ToString());
        }
Esempio n. 20
0
        internal override string GetPropertyBlockString()
        {
            string valueString = NodeUtils.FloatToShaderValueShaderLabSafe(value);

            switch (floatType)
            {
            case FloatType.Slider:
                return($"{hideTagString}{referenceName}(\"{displayName}\", Range({NodeUtils.FloatToShaderValue(m_RangeValues.x)}, {NodeUtils.FloatToShaderValue(m_RangeValues.y)})) = {valueString}");

            case FloatType.Integer:
                return($"{hideTagString}{referenceName}(\"{displayName}\", Int) = {((int)value).ToString(CultureInfo.InvariantCulture)}");

            case FloatType.Enum:
                return($"{hideTagString}{enumTagString}{referenceName}(\"{displayName}\", Float) = {valueString}");

            default:
                return($"{hideTagString}{referenceName}(\"{displayName}\", Float) = {valueString}");
            }
        }
Esempio n. 21
0
        public static string GetGradientValue(Gradient gradient, string delimiter = ";")
        {
            string colorKeys = "";

            for (int i = 0; i < 8; i++)
            {
                if (i < gradient.colorKeys.Length)
                {
                    colorKeys += $"$precision4({NodeUtils.FloatToShaderValue(gradient.colorKeys[i].color.r)}, " +
                                 $"{NodeUtils.FloatToShaderValue(gradient.colorKeys[i].color.g)}, " +
                                 $"{NodeUtils.FloatToShaderValue(gradient.colorKeys[i].color.b)}, " +
                                 $"{NodeUtils.FloatToShaderValue(gradient.colorKeys[i].time)})";
                }
                else
                {
                    colorKeys += "$precision4(0, 0, 0, 0)";
                }
                if (i < 7)
                {
                    colorKeys += ",";
                }
            }

            string alphaKeys = "";

            for (int i = 0; i < 8; i++)
            {
                if (i < gradient.alphaKeys.Length)
                {
                    alphaKeys += $"$precision2({NodeUtils.FloatToShaderValue(gradient.alphaKeys[i].alpha)}, {NodeUtils.FloatToShaderValue(gradient.alphaKeys[i].time)})";
                }
                else
                {
                    alphaKeys += "$precision2(0, 0)";
                }
                if (i < 7)
                {
                    alphaKeys += ",";
                }
            }

            return($"NewGradient({(int)gradient.mode}, {gradient.colorKeys.Length}, {gradient.alphaKeys.Length}, {colorKeys}, {alphaKeys}){delimiter}");
        }
Esempio n. 22
0
 public void GenerateNodeCode(ShaderStringBuilder sb, GraphContext graphContext, GenerationMode generationMode)
 {
     if (!generationMode.IsPreview())
     {
         sb.AppendLine("$precision3 _{0}_m0 = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row0.x),
                       NodeUtils.FloatToShaderValue(m_Row0.y),
                       NodeUtils.FloatToShaderValue(m_Row0.z));
         sb.AppendLine("$precision3 _{0}_m1 = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row1.x),
                       NodeUtils.FloatToShaderValue(m_Row1.y),
                       NodeUtils.FloatToShaderValue(m_Row1.z));
         sb.AppendLine("$precision3 _{0}_m2 = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(),
                       NodeUtils.FloatToShaderValue(m_Row2.x),
                       NodeUtils.FloatToShaderValue(m_Row2.y),
                       NodeUtils.FloatToShaderValue(m_Row2.z));
     }
     sb.AppendLine("$precision3x3 {0} = $precision3x3 (_{0}_m0.x, _{0}_m0.y, _{0}_m0.z, _{0}_m1.x, _{0}_m1.y, _{0}_m1.z, _{0}_m2.x, _{0}_m2.y, _{0}_m2.z);", GetVariableNameForNode());
 }
Esempio n. 23
0
        public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
        {
            if (generationMode.IsPreview())
            {
                return;
            }

            switch (sgVersion)
            {
            case 0:
                sb.AppendLine(@"$precision4 {0} = IsGammaSpace() ? $precision4({1}, {2}, {3}, {4}) : $precision4(SRGBToLinear($precision3({1}, {2}, {3})), {4});"
                              , GetVariableNameForNode()
                              , NodeUtils.FloatToShaderValue(color.color.r)
                              , NodeUtils.FloatToShaderValue(color.color.g)
                              , NodeUtils.FloatToShaderValue(color.color.b)
                              , NodeUtils.FloatToShaderValue(color.color.a));
                break;

            case 1:
                //HDR color picker assumes Linear space, regular color picker assumes SRGB. Handle both cases
                if (color.mode == ColorMode.Default)
                {
                    sb.AppendLine(@"$precision4 {0} = IsGammaSpace() ? $precision4({1}, {2}, {3}, {4}) : $precision4(SRGBToLinear($precision3({1}, {2}, {3})), {4});"
                                  , GetVariableNameForNode()
                                  , NodeUtils.FloatToShaderValue(color.color.r)
                                  , NodeUtils.FloatToShaderValue(color.color.g)
                                  , NodeUtils.FloatToShaderValue(color.color.b)
                                  , NodeUtils.FloatToShaderValue(color.color.a));
                }
                else
                {
                    sb.AppendLine(@"$precision4 {0} = IsGammaSpace() ? LinearToSRGB($precision4({1}, {2}, {3}, {4})) : $precision4({1}, {2}, {3}, {4});"
                                  , GetVariableNameForNode()
                                  , NodeUtils.FloatToShaderValue(color.color.r)
                                  , NodeUtils.FloatToShaderValue(color.color.g)
                                  , NodeUtils.FloatToShaderValue(color.color.b)
                                  , NodeUtils.FloatToShaderValue(color.color.a));
                }
                break;
            }
        }
        internal override bool AllowHLSLDeclaration(HLSLDeclaration decl) => false; // disable UI, nothing to choose

        internal override void ForeachHLSLProperty(Action <HLSLProperty> action)
        {
            Action <ShaderStringBuilder> customDecl = (builder) =>
            {
                builder.AppendLine("Gradient {0}_Definition()", referenceName);
                using (builder.BlockScope())
                {
                    string[] colors = new string[8];
                    for (int i = 0; i < colors.Length; i++)
                    {
                        colors[i] = string.Format("g.colors[{0}] = {1}4(0, 0, 0, 0);", i, concretePrecision.ToShaderString());
                    }
                    for (int i = 0; i < value.colorKeys.Length; i++)
                    {
                        colors[i] = string.Format("g.colors[{0}] = {1}4({2}, {3}, {4}, {5});"
                                                  , i
                                                  , concretePrecision.ToShaderString()
                                                  , NodeUtils.FloatToShaderValue(value.colorKeys[i].color.r)
                                                  , NodeUtils.FloatToShaderValue(value.colorKeys[i].color.g)
                                                  , NodeUtils.FloatToShaderValue(value.colorKeys[i].color.b)
                                                  , NodeUtils.FloatToShaderValue(value.colorKeys[i].time));
                    }

                    string[] alphas = new string[8];
                    for (int i = 0; i < alphas.Length; i++)
                    {
                        alphas[i] = string.Format("g.alphas[{0}] = {1}2(0, 0);", i, concretePrecision.ToShaderString());
                    }
                    for (int i = 0; i < value.alphaKeys.Length; i++)
                    {
                        alphas[i] = string.Format("g.alphas[{0}] = {1}2({2}, {3});"
                                                  , i
                                                  , concretePrecision.ToShaderString()
                                                  , NodeUtils.FloatToShaderValue(value.alphaKeys[i].alpha)
                                                  , NodeUtils.FloatToShaderValue(value.alphaKeys[i].time));
                    }

                    builder.AppendLine("Gradient g;");
                    builder.AppendLine("g.type = {0};",
                                       (int)value.mode);
                    builder.AppendLine("g.colorsLength = {0};",
                                       value.colorKeys.Length);
                    builder.AppendLine("g.alphasLength = {0};",
                                       value.alphaKeys.Length);

                    for (int i = 0; i < colors.Length; i++)
                    {
                        builder.AppendLine(colors[i]);
                    }

                    for (int i = 0; i < alphas.Length; i++)
                    {
                        builder.AppendLine(alphas[i]);
                    }
                    builder.AppendLine("return g;", true);
                }
                builder.AppendIndentation();
                builder.Append("#define {0} {0}_Definition()", referenceName);
            };

            action(
                new HLSLProperty(HLSLType._CUSTOM, referenceName, HLSLDeclaration.Global, concretePrecision)
            {
                customDeclaration = customDecl
            });
        }
 public override string GetPropertyBlockString()
 {
     return($"{hideTagString}{referenceName}(\"{displayName}\", Vector) = ({NodeUtils.FloatToShaderValue(value.x)}, {NodeUtils.FloatToShaderValue(value.y)}, {NodeUtils.FloatToShaderValue(value.z)}, {NodeUtils.FloatToShaderValue(value.w)})");
 }
Esempio n. 26
0
        public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
        {
            if (generationMode.IsPreview())
            {
                return;
            }

            visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + NodeUtils.FloatToShaderValue(m_Value) + ";", true);
        }
 protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
 {
     return(NodeUtils.FloatToShaderValue(value));
 }
Esempio n. 28
0
 internal override string GetPropertyBlockString()
 {
     return($"{hideTagString}{hdrTagString}{referenceName}(\"{displayName}\", Color) = ({NodeUtils.FloatToShaderValue(value.r)}, {NodeUtils.FloatToShaderValue(value.g)}, {NodeUtils.FloatToShaderValue(value.b)}, {NodeUtils.FloatToShaderValue(value.a)})");
 }
Esempio n. 29
0
 protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
 {
     return(precision + "4 (" + NodeUtils.FloatToShaderValue(value.x) + "," + NodeUtils.FloatToShaderValue(value.y) + "," + NodeUtils.FloatToShaderValue(value.z) + "," + NodeUtils.FloatToShaderValue(value.w) + ")");
 }
Esempio n. 30
0
 protected override string ConcreteSlotValueAsVariable()
 {
     return(NodeUtils.FloatToShaderValue(value));
 }