コード例 #1
0
 public void GenerateNodeCode(ShaderGenerator visitor, GraphContext graphContext, GenerationMode generationMode)
 {
     if (generationMode.IsPreview())
     {
         visitor.AddShaderChunk(string.Format("Gradient {0} = {1};",
                                              GetVariableNameForSlot(outputSlotId),
                                              GradientUtils.GetGradientForPreview(GetVariableNameForNode())));
     }
     else
     {
         visitor.AddShaderChunk(string.Format("Gradient {0} = {1}",
                                              GetVariableNameForSlot(outputSlotId),
                                              GradientUtils.GetGradientValue(gradient, precision, true, ";")));
     }
 }
コード例 #2
0
        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());
        }
コード例 #3
0
        public void GenerateNodeCode(ShaderStringBuilder sb, GraphContext graphContext, GenerationMode generationMode)
        {
            var graph    = owner as GraphData;
            var property = graph.properties.FirstOrDefault(x => x.guid == propertyGuid);

            if (property == null)
            {
                return;
            }

            if (property is Vector1ShaderProperty)
            {
                var result = string.Format("$precision {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is Vector2ShaderProperty)
            {
                var result = string.Format("$precision2 {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is Vector3ShaderProperty)
            {
                var result = string.Format("$precision3 {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is Vector4ShaderProperty)
            {
                var result = string.Format("$precision4 {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is ColorShaderProperty)
            {
                var result = string.Format("$precision4 {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is BooleanShaderProperty)
            {
                var result = string.Format("$precision {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is Matrix2ShaderProperty)
            {
                var result = string.Format("$precision2x2 {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is Matrix3ShaderProperty)
            {
                var result = string.Format("$precision3x3 {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is Matrix4ShaderProperty)
            {
                var result = string.Format("$precision4x4 {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                sb.AppendLine(result);
            }
            else if (property is SamplerStateShaderProperty)
            {
                SamplerStateShaderProperty samplerStateProperty = property as SamplerStateShaderProperty;
                var result = string.Format("SamplerState {0} = {1};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , samplerStateProperty.referenceName);
                sb.AppendLine(result);
            }
            else if (property is GradientShaderProperty)
            {
                if (generationMode == GenerationMode.Preview)
                {
                    var result = string.Format("Gradient {0} = {1};"
                                               , GetVariableNameForSlot(OutputSlotId)
                                               , GradientUtils.GetGradientForPreview(property.referenceName));
                    sb.AppendLine(result);
                }
                else
                {
                    var result = string.Format("Gradient {0} = {1};"
                                               , GetVariableNameForSlot(OutputSlotId)
                                               , property.referenceName);
                    sb.AppendLine(result);
                }
            }
        }
コード例 #4
0
        public void GenerateNodeCode(ShaderGenerator visitor, GraphContext graphContext, GenerationMode generationMode)
        {
            var graph    = owner as GraphData;
            var property = graph.properties.FirstOrDefault(x => x.guid == propertyGuid);

            if (property == null)
            {
                return;
            }

            if (property is Vector1ShaderProperty)
            {
                var result = string.Format("{0} {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is Vector2ShaderProperty)
            {
                var result = string.Format("{0}2 {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is Vector3ShaderProperty)
            {
                var result = string.Format("{0}3 {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is Vector4ShaderProperty)
            {
                var result = string.Format("{0}4 {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is ColorShaderProperty)
            {
                var result = string.Format("{0}4 {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is BooleanShaderProperty)
            {
                var result = string.Format("{0} {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is Matrix2ShaderProperty)
            {
                var result = string.Format("{0}2x2 {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is Matrix3ShaderProperty)
            {
                var result = string.Format("{0}3x3 {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is Matrix4ShaderProperty)
            {
                var result = string.Format("{0}4x4 {1} = {2};"
                                           , precision
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , property.referenceName);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is SamplerStateShaderProperty)
            {
                SamplerStateShaderProperty samplerStateProperty = property as SamplerStateShaderProperty;
                var result = string.Format("SamplerState {0} = {1}_{2}_{3};"
                                           , GetVariableNameForSlot(OutputSlotId)
                                           , samplerStateProperty.referenceName
                                           , samplerStateProperty.value.filter
                                           , samplerStateProperty.value.wrap);
                visitor.AddShaderChunk(result, true);
            }
            else if (property is GradientShaderProperty)
            {
                if (generationMode == GenerationMode.Preview)
                {
                    var result = string.Format("Gradient {0} = {1};"
                                               , GetVariableNameForSlot(OutputSlotId)
                                               , GradientUtils.GetGradientForPreview(property.referenceName));
                    visitor.AddShaderChunk(result, true);
                }
                else
                {
                    var result = string.Format("Gradient {0} = {1};"
                                               , GetVariableNameForSlot(OutputSlotId)
                                               , property.referenceName);
                    visitor.AddShaderChunk(result, true);
                }
            }
        }
コード例 #5
0
 public void GenerateNodeCode(ShaderStringBuilder sb, GraphContext graphContext, GenerationMode generationMode)
 {
     if (generationMode.IsPreview())
     {
         sb.AppendLine("Gradient {0} = {1};", GetVariableNameForSlot(outputSlotId), GradientUtils.GetGradientForPreview(GetVariableNameForNode()));
     }
     else
     {
         sb.AppendLine("Gradient {0} = {1}", GetVariableNameForSlot(outputSlotId), GradientUtils.GetGradientValue(gradient, true, ";"));
     }
 }