示例#1
0
        public virtual string GetDefaultValue(GenerationMode generationMode)
        {
            var matOwner = owner as AbstractMaterialNode;

            if (matOwner == null)
            {
                throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
            }

            if (generationMode.IsPreview() && matOwner.isActive)
            {
                return(matOwner.GetVariableNameForSlot(id));
            }

            return(ConcreteSlotValueAsVariable());
        }
        public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
        {
            if (!generationMode.IsPreview())
                return;

            if (owner == null)
                throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));

            var property = new BooleanShaderProperty()
            {
                overrideReferenceName = owner.GetVariableNameForSlot(id),
                generatePropertyBlock = false,
                value = isConnected
            };
            properties.AddShaderProperty(property);
        }
示例#3
0
        public void GenerateNodeCode(ShaderGenerator visitor, GraphContext graphContext, 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);
        }
示例#4
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);
        }
示例#5
0
        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()
                                       , color.r
                                       , color.g
                                       , color.b
                                       , color.a), true);
        }
        public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
        {
            if (!generationMode.IsPreview())
            {
                return;
            }

            properties.AddShaderProperty(new Vector1ShaderProperty()
            {
                overrideReferenceName = GetVariableNameForNode(),
                generatePropertyBlock = false,
                value       = value.x,
                rangeValues = new Vector2(value.y, value.z),
                floatType   = FloatType.Slider
            });
        }
        public override string GetDefaultValue(GenerationMode generationMode)
        {
            var matOwner = owner as AbstractMaterialNode;

            if (matOwner == null)
            {
                throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
            }

            if (generationMode.IsPreview())
            {
                return(GradientUtils.GetGradientForPreview(matOwner.GetVariableNameForSlot(id)));
            }

            return(ConcreteSlotValueAsVariable(matOwner.precision));
        }
示例#8
0
        public void GenerateNodeCode(ShaderGenerator visitor, GraphContext graphContext, GenerationMode generationMode)
        {
            var sb          = new ShaderStringBuilder();
            var inputValue  = GetSlotValue(InputSlotId, generationMode);
            var outputValue = GetSlotValue(OutputSlotId, generationMode);

            sb.AppendLine("{0} {1};", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot <MaterialSlot>(InputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId));
            if (!generationMode.IsPreview())
            {
                sb.AppendLine("{0}3 _{1}_Red = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(), channelMixer.outRed[0], channelMixer.outRed[1], channelMixer.outRed[2]);
                sb.AppendLine("{0}3 _{1}_Green = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(), channelMixer.outGreen[0], channelMixer.outGreen[1], channelMixer.outGreen[2]);
                sb.AppendLine("{0}3 _{1}_Blue = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(), channelMixer.outBlue[0], channelMixer.outBlue[1], channelMixer.outBlue[2]);
            }
            sb.AppendLine("{0}({1}, _{2}_Red, _{2}_Green, _{2}_Blue, {3});", GetFunctionName(), inputValue, GetVariableNameForNode(), outputValue);

            visitor.AddShaderChunk(sb.ToString(), false);
        }
示例#9
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);
        }
示例#10
0
        public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
        {
            if (!generationMode.IsPreview())
            {
                return;
            }

            base.CollectShaderProperties(properties, generationMode);

            properties.AddShaderProperty(new Vector1ShaderProperty()
            {
                overrideReferenceName = string.Format("_{0}_Type", GetVariableNameForNode()),
                generatePropertyBlock = false
            });

            properties.AddShaderProperty(new Vector1ShaderProperty()
            {
                overrideReferenceName = string.Format("_{0}_ColorsLength", GetVariableNameForNode()),
                generatePropertyBlock = false
            });

            properties.AddShaderProperty(new Vector1ShaderProperty()
            {
                overrideReferenceName = string.Format("_{0}_AlphasLength", GetVariableNameForNode()),
                generatePropertyBlock = false
            });

            for (int i = 0; i < 8; i++)
            {
                properties.AddShaderProperty(new Vector4ShaderProperty()
                {
                    overrideReferenceName = string.Format("_{0}_ColorKey{1}", GetVariableNameForNode(), i),
                    generatePropertyBlock = false
                });
            }

            for (int i = 0; i < 8; i++)
            {
                properties.AddShaderProperty(new Vector4ShaderProperty()
                {
                    overrideReferenceName = string.Format("_{0}_AlphaKey{1}", GetVariableNameForNode(), i),
                    generatePropertyBlock = false
                });
            }
        }
        public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
        {
            if (!generationMode.IsPreview())
            {
                return;
            }

            var matOwner = owner as AbstractMaterialNode;

            if (matOwner == null)
            {
                throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
            }

            AbstractShaderProperty property;

            switch (concreteValueType)
            {
            case ConcreteSlotValueType.Vector4:
                property = new Vector4ShaderProperty();
                break;

            case ConcreteSlotValueType.Vector3:
                property = new Vector3ShaderProperty();
                break;

            case ConcreteSlotValueType.Vector2:
                property = new Vector2ShaderProperty();
                break;

            case ConcreteSlotValueType.Vector1:
                property = new Vector1ShaderProperty();
                break;

            default:
                // This shouldn't happen due to edge validation. The generated shader will
                // have errors.
                Debug.LogError($"Invalid value type {concreteValueType} passed to Vector Slot {displayName}. Value will be ignored, please plug in an edge with a vector type.");
                return;
            }

            property.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
            property.generatePropertyBlock = false;
            properties.AddShaderProperty(property);
        }
示例#12
0
        public void GenerateNodeCode(ShaderGenerator visitor, GraphContext graphContext, GenerationMode generationMode)
        {
            var sb          = new ShaderStringBuilder();
            var uvValue     = GetSlotValue(UVSlotId, generationMode);
            var widthValue  = GetSlotValue(WidthSlotId, generationMode);
            var heightValue = GetSlotValue(HeightSlotId, generationMode);
            var tileValue   = GetSlotValue(TileSlotId, generationMode);
            var outputValue = GetSlotValue(OutputSlotId, generationMode);

            sb.AppendLine("{0} {1};", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot <MaterialSlot>(OutputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId));
            if (!generationMode.IsPreview())
            {
                sb.AppendLine("{0}2 _{1}_Invert = {0}2 ({2}, {3});", precision, GetVariableNameForNode(), invertX.isOn ? 1 : 0, invertY.isOn ? 1 : 0);
            }
            sb.AppendLine("{0}({1}, {2}, {3}, {4}, _{5}_Invert, {6});", GetFunctionName(), uvValue, widthValue, heightValue, tileValue, GetVariableNameForNode(), outputValue);

            visitor.AddShaderChunk(sb.ToString(), false);
        }
示例#13
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());
 }
        public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
        {
            if (!generationMode.IsPreview())
            {
                return;
            }

            var matOwner = owner as AbstractMaterialNode;

            if (matOwner == null)
            {
                throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
            }

            AbstractShaderProperty property;

            switch (concreteValueType)
            {
            case ConcreteSlotValueType.Vector4:
                property = new Vector4ShaderProperty();
                break;

            case ConcreteSlotValueType.Vector3:
                property = new Vector3ShaderProperty();
                break;

            case ConcreteSlotValueType.Vector2:
                property = new Vector2ShaderProperty();
                break;

            case ConcreteSlotValueType.Vector1:
                property = new Vector1ShaderProperty();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            property.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
            property.generatePropertyBlock = false;
            properties.AddShaderProperty(property);
        }
        public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
        {
            base.CollectShaderProperties(properties, generationMode);
            properties.AddShaderProperty(new TextureShaderProperty()
            {
                displayName           = "Main Texture",
                overrideReferenceName = inputTexture,
                generatePropertyBlock = false
            });

            if (generationMode.IsPreview() && !string.IsNullOrEmpty(previewInputTexture))
            {
                properties.AddShaderProperty(new TextureShaderProperty()
                {
                    displayName           = "Preview Texture",
                    overrideReferenceName = previewInputTexture,
                    generatePropertyBlock = false
                });
            }
        }
示例#16
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;
            }
        }
示例#17
0
        public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
        {
            if (!generationMode.IsPreview())
            {
                return;
            }

            properties.AddShaderProperty(new Vector2ShaderProperty()
            {
                overrideReferenceName = string.Format("_{0}_m0", GetVariableNameForNode()),
                generatePropertyBlock = false,
                value = m_Row0
            });

            properties.AddShaderProperty(new Vector2ShaderProperty()
            {
                overrideReferenceName = string.Format("_{0}_m1", GetVariableNameForNode()),
                generatePropertyBlock = false,
                value = m_Row1
            });
        }
        public void GenerateNodeCode(ShaderStringBuilder sb, GraphContext graphContext, GenerationMode generationMode)
        {
            var colorValue          = GetSlotValue(kEmissionColorInputSlotId, generationMode);
            var intensityValue      = GetSlotValue(kEmissionIntensityInputSlotId, generationMode);
            var exposureWeightValue = GetSlotValue(kEmissionExposureWeightInputSlotId, generationMode);
            var outputValue         = GetSlotValue(kEmissionOutputSlotId, generationMode);

            if (intensityUnit == EmissiveIntensityUnit.EV100)
            {
                intensityValue = "ConvertEvToLuminance(" + intensityValue + ")";
            }

            string inverseExposureMultiplier = (generationMode.IsPreview()) ? "1.0" : "GetInverseCurrentExposureMultiplier()";

            sb.AppendLine(@"$precision3 {0} = {1}({2}.xyz, {3}, {4}, {5});",
                          outputValue,
                          GetFunctionName(),
                          colorValue,
                          intensityValue,
                          exposureWeightValue,
                          inverseExposureMultiplier
                          );
        }
示例#19
0
        public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
        {
            if (!generationMode.IsPreview())
            {
                return;
            }

            var matOwner = owner as AbstractMaterialNode;

            if (matOwner == null)
            {
                throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
            }

            var property = new ColorShaderProperty()
            {
                overrideReferenceName = matOwner.GetVariableNameForSlot(id),
                generatePropertyBlock = false,
                value = new Color(value.x, value.y, value.z)
            };

            properties.AddShaderProperty(property);
        }
示例#20
0
        public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
        {
            string uv = GetSlotValue(kUvInputSlotId, generationMode);

            string depthValue = $"SampleCustomDepth({uv}.xy)";

            if (depthSamplingMode == DepthSamplingMode.Eye)
            {
                depthValue = $"LinearEyeDepth({depthValue}, _ZBufferParams)";
            }
            if (depthSamplingMode == DepthSamplingMode.Linear01)
            {
                depthValue = $"Linear01Depth({depthValue}, _ZBufferParams)";
            }

            if (generationMode.IsPreview())
            {
                sb.AppendLine($"$precision {GetVariableNameForSlot(kDepthOutputSlotId)} = 0;");
            }
            else
            {
                sb.AppendLine($"$precision {GetVariableNameForSlot(kDepthOutputSlotId)} = {depthValue};");
            }
        }
示例#21
0
        public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
        {
            var sb = new ShaderStringBuilder();

            if (!generationMode.IsPreview())
            {
                switch (material.type)
                {
                case DielectricMaterialType.Custom:
                    sb.AppendLine("{0} _{1}_IOR = {2};", precision, GetVariableNameForNode(), material.indexOfRefraction);
                    break;

                case DielectricMaterialType.Common:
                    sb.AppendLine("{0} _{1}_Range = {2};", precision, GetVariableNameForNode(), material.range);
                    break;

                default:
                    break;
                }
            }
            switch (material.type)
            {
            case DielectricMaterialType.Common:
                sb.AppendLine("{0}3 {1} = lerp(0.034, 0.048, _{2}_Range);", precision, GetVariableNameForSlot(kOutputSlotId), GetVariableNameForNode());
                break;

            case DielectricMaterialType.Custom:
                sb.AppendLine("{0}3 {1} = pow(_{2}_IOR - 1, 2) / pow(_{2}_IOR + 1, 2);", precision, GetVariableNameForSlot(kOutputSlotId), GetVariableNameForNode());
                break;

            default:
                sb.AppendLine("{0}3 {1} = {0}3{2};", precision, GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material.type].ToString(CultureInfo.InvariantCulture));
                break;
            }
            visitor.AddShaderChunk(sb.ToString(), false);
        }