bool IsCompatibleWithInputSlotType(SlotValueType inputType)
 {
     switch (valueType)
     {
         case SlotValueType.SamplerState:
             return inputType == SlotValueType.SamplerState;
         case SlotValueType.Matrix4:
             return inputType == SlotValueType.Matrix4
                 || inputType == SlotValueType.Matrix3
                 || inputType == SlotValueType.Matrix2;
         case SlotValueType.Matrix3:
             return inputType == SlotValueType.Matrix3
                 || inputType == SlotValueType.Matrix2;
         case SlotValueType.Matrix2:
             return inputType == SlotValueType.Matrix2;
         case SlotValueType.Texture2D:
             return inputType == SlotValueType.Texture2D;
         case SlotValueType.Cubemap:
             return inputType == SlotValueType.Cubemap;
         case SlotValueType.Dynamic:
         case SlotValueType.Vector4:
         case SlotValueType.Vector3:
         case SlotValueType.Vector2:
         case SlotValueType.Vector1:
             return inputType == SlotValueType.Vector4
                 || inputType == SlotValueType.Vector3
                 || inputType == SlotValueType.Vector2
                 || inputType == SlotValueType.Vector1
                 || inputType == SlotValueType.Dynamic;
     }
     return false;
 }
        public static MaterialSlot CreateMaterialSlot(SlotValueType type, int slotId, string displayName, string shaderOutputName, SlotType slotType, Vector4 defaultValue, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
        {
            switch (type)
            {
                case SlotValueType.SamplerState:
                    return new SamplerStateMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
                case SlotValueType.Matrix4:
                    return new Matrix4MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
                case SlotValueType.Matrix3:
                    return new Matrix3MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
                case SlotValueType.Matrix2:
                    return new Matrix2MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
                case SlotValueType.Texture2D:
                    return slotType == SlotType.Input
                        ? new Texture2DInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStage, hidden)
                        : new Texture2DMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
                case SlotValueType.Cubemap:
                    return slotType == SlotType.Input
                        ? new CubemapInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStage, hidden)
                        : new CubemapMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
                case SlotValueType.Dynamic:
                    return new DynamicVectorMaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
                case SlotValueType.Vector4:
                    return new Vector4MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
                case SlotValueType.Vector3:
                    return new Vector3MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
                case SlotValueType.Vector2:
                    return new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
                case SlotValueType.Vector1:
                    return new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStage, hidden);
            }

            throw new ArgumentOutOfRangeException("type", type, null);
        }
        public static MaterialSlot CreateMaterialSlot(SlotValueType type, int slotId, string displayName, string shaderOutputName, SlotType slotType, Vector4 defaultValue, ShaderStageCapability shaderStageCapability = ShaderStageCapability.All, bool hidden = false)
        {
            switch (type)
            {
            case SlotValueType.SamplerState:
                return(new SamplerStateMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden));

            case SlotValueType.DynamicMatrix:
                return(new DynamicMatrixMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden));

            case SlotValueType.Matrix4:
                return(new Matrix4MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden));

            case SlotValueType.Matrix3:
                return(new Matrix3MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden));

            case SlotValueType.Matrix2:
                return(new Matrix2MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden));

            case SlotValueType.Texture2D:
                return(slotType == SlotType.Input
                        ? new Texture2DInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
                        : new Texture2DMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden));

            case SlotValueType.Cubemap:
                return(slotType == SlotType.Input
                        ? new CubemapInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
                        : new CubemapMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden));

            case SlotValueType.Gradient:
                return(slotType == SlotType.Input
                        ? new GradientInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
                        : new GradientMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden));

            case SlotValueType.DynamicVector:
                return(new DynamicVectorMaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden));

            case SlotValueType.Vector4:
                return(new Vector4MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden));

            case SlotValueType.Vector3:
                return(new Vector3MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden));

            case SlotValueType.Vector2:
                return(new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden));

            case SlotValueType.Vector1:
                return(new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStageCapability, hidden: hidden));

            case SlotValueType.Dynamic:
                return(new DynamicValueMaterialSlot(slotId, displayName, shaderOutputName, slotType, new Matrix4x4(defaultValue, Vector4.zero, Vector4.zero, Vector4.zero), shaderStageCapability, hidden));

            case SlotValueType.Boolean:
                return(new BooleanMaterialSlot(slotId, displayName, shaderOutputName, slotType, false, shaderStageCapability, hidden));
            }

            throw new ArgumentOutOfRangeException("type", type, null);
        }
        public static ConcreteSlotValueType ToConcreteSlotValueType(this SlotValueType slotValueType)
        {
            switch (slotValueType)
            {
            case SlotValueType.SamplerState:
                return(ConcreteSlotValueType.SamplerState);

            case SlotValueType.Matrix2:
                return(ConcreteSlotValueType.Matrix2);

            case SlotValueType.Matrix3:
                return(ConcreteSlotValueType.Matrix3);

            case SlotValueType.Matrix4:
                return(ConcreteSlotValueType.Matrix4);

            case SlotValueType.Texture2D:
                return(ConcreteSlotValueType.Texture2D);

            case SlotValueType.Texture2DArray:
                return(ConcreteSlotValueType.Texture2DArray);

            case SlotValueType.Texture3D:
                return(ConcreteSlotValueType.Texture3D);

            case SlotValueType.Cubemap:
                return(ConcreteSlotValueType.Cubemap);

            case SlotValueType.Gradient:
                return(ConcreteSlotValueType.Gradient);

            case SlotValueType.Vector4:
                return(ConcreteSlotValueType.Vector4);

            case SlotValueType.Vector3:
                return(ConcreteSlotValueType.Vector3);

            case SlotValueType.Vector2:
                return(ConcreteSlotValueType.Vector2);

            case SlotValueType.Vector1:
                return(ConcreteSlotValueType.Vector1);

            case SlotValueType.Boolean:
                return(ConcreteSlotValueType.Boolean);

            case SlotValueType.VirtualTexture:
                return(ConcreteSlotValueType.VirtualTexture);

            case SlotValueType.PropertyConnectionState:
                return(ConcreteSlotValueType.PropertyConnectionState);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #5
0
        // Static version for testability
        public static RedirectNodeData Create(GraphData graph, SlotValueType edgeType, Vector2 absolutePosition, SlotReference inputRef, SlotReference outputRef, Guid groupGuid)
        {
            var nodeData = new RedirectNodeData();
            nodeData.AddSlots(edgeType);
            nodeData.SetPosition(absolutePosition);
            nodeData.groupGuid = groupGuid;

            // Hard-coded for single input-output. Changes would be needed for multi-input redirects
            var nodeInSlotRef = nodeData.GetSlotReference(RedirectNodeData.kInputSlotID);
            var nodeOutSlotRef = nodeData.GetSlotReference(RedirectNodeData.kOutputSlotID);

            graph.owner.RegisterCompleteObjectUndo("Add Redirect Node");
            graph.AddNode(nodeData);

            graph.Connect(outputRef, nodeInSlotRef);
            graph.Connect(nodeOutSlotRef, inputRef);

            return nodeData;
        }
Example #6
0
        public PortInputView(LogicSlot description)
        {
            this.LoadAndAddStyleSheet("Styles/PortInputView");
            pickingMode = PickingMode.Ignore;
            ClearClassList();
            _description = description;
            _valueType   = description.ValueType;
            AddToClassList("type" + _valueType);

            _edgeControl = new EdgeControl
            {
                @from       = new Vector2(212f - 21f, 11.5f),
                to          = new Vector2(212f, 11.5f),
                edgeWidth   = 2,
                pickingMode = PickingMode.Ignore
            };
            Add(_edgeControl);

            _container = new VisualElement {
                name = "container"
            };
            {
                _control = this.Description.InstantiateControl();
                if (_control != null)
                {
                    _container.Add(_control);
                }

                var slotElement = new VisualElement {
                    name = "slot"
                };
                {
                    slotElement.Add(new VisualElement {
                        name = "dot"
                    });
                }
                _container.Add(slotElement);
            }
            Add(_container);

            _container.visible = _edgeControl.visible = _control != null;
        }
Example #7
0
        bool IsCompatibleWithInputSlotType(SlotValueType inputType)
        {
            switch (valueType)
            {
            case SlotValueType.SamplerState:
                return(inputType == SlotValueType.SamplerState);

            case SlotValueType.Matrix4:
                return(inputType == SlotValueType.Matrix4 ||
                       inputType == SlotValueType.Matrix3 ||
                       inputType == SlotValueType.Matrix2);

            case SlotValueType.Matrix3:
                return(inputType == SlotValueType.Matrix3 ||
                       inputType == SlotValueType.Matrix2);

            case SlotValueType.Matrix2:
                return(inputType == SlotValueType.Matrix2);

            case SlotValueType.Texture2D:
                return(inputType == SlotValueType.Texture2D);

            case SlotValueType.Cubemap:
                return(inputType == SlotValueType.Cubemap);

            case SlotValueType.Dynamic:
            case SlotValueType.Vector4:
            case SlotValueType.Vector3:
            case SlotValueType.Vector2:
            case SlotValueType.Vector1:
                return(inputType == SlotValueType.Vector4 ||
                       inputType == SlotValueType.Vector3 ||
                       inputType == SlotValueType.Vector2 ||
                       inputType == SlotValueType.Vector1 ||
                       inputType == SlotValueType.Dynamic);

            case SlotValueType.Boolean:
                return(inputType == SlotValueType.Boolean);
            }
            return(false);
        }
Example #8
0
        void Recreate()
        {
            RemoveFromClassList("type" + _valueType);
            _valueType = Description.ValueType;
            AddToClassList("type" + _valueType);
            if (_control != null)
            {
                var disposable = _control as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
                _container.Remove(_control);
            }
            _control = Description.InstantiateControl();
            if (_control != null)
            {
                _container.Insert(0, _control);
            }

            _container.visible = _edgeControl.visible = _control != null;
        }
Example #9
0
 public static ConcreteSlotValueType ToConcreteSlotValueType(this SlotValueType slotValueType)
 {
     switch (slotValueType)
     {
         case SlotValueType.SamplerState:
             return ConcreteSlotValueType.SamplerState;
         case SlotValueType.Matrix2:
             return ConcreteSlotValueType.Matrix2;
         case SlotValueType.Matrix3:
             return ConcreteSlotValueType.Matrix3;
         case SlotValueType.Matrix4:
             return ConcreteSlotValueType.Matrix4;
         case SlotValueType.Texture2D:
             return ConcreteSlotValueType.Texture2D;
         case SlotValueType.Texture2DArray:
             return ConcreteSlotValueType.Texture2DArray;
         case SlotValueType.Texture3D:
             return ConcreteSlotValueType.Texture3D;
         case SlotValueType.Cubemap:
             return ConcreteSlotValueType.Cubemap;
         case SlotValueType.Gradient:
             return ConcreteSlotValueType.Gradient;
         case SlotValueType.Vector4:
             return ConcreteSlotValueType.Vector4;
         case SlotValueType.Vector3:
             return ConcreteSlotValueType.Vector3;
         case SlotValueType.Vector2:
             return ConcreteSlotValueType.Vector2;
         case SlotValueType.Vector1:
             return ConcreteSlotValueType.Vector1;
         case SlotValueType.Boolean:
             return ConcreteSlotValueType.Boolean;
         case SlotValueType.VirtualTexture:
             return ConcreteSlotValueType.VirtualTexture;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Example #10
0
        public virtual void UpdateSlots()
        {
            var validNames = new List <int>();

            if (asset == null)
            {
                return;
            }

            var props = asset.inputs;

            foreach (var prop in props)
            {
                SlotValueType valueType      = prop.concreteShaderValueType.ToSlotValueType();
                var           propertyString = prop.guid.ToString();
                var           propertyIndex  = m_PropertyGuids.IndexOf(propertyString);
                if (propertyIndex < 0)
                {
                    propertyIndex = m_PropertyGuids.Count;
                    m_PropertyGuids.Add(propertyString);
                    m_PropertyIds.Add(prop.guid.GetHashCode());
                }
                var          id   = m_PropertyIds[propertyIndex];
                MaterialSlot slot = MaterialSlot.CreateMaterialSlot(valueType, id, prop.displayName, prop.referenceName, SlotType.Input, Vector4.zero, ShaderStageCapability.All);

                // Copy defaults
                switch (prop.concreteShaderValueType)
                {
                case ConcreteSlotValueType.SamplerState:
                {
                    var tSlot = slot as SamplerStateMaterialSlot;
                    var tProp = prop as SamplerStateShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.defaultSamplerState = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Matrix4:
                {
                    var tSlot = slot as Matrix4MaterialSlot;
                    var tProp = prop as Matrix4ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Matrix3:
                {
                    var tSlot = slot as Matrix3MaterialSlot;
                    var tProp = prop as Matrix3ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Matrix2:
                {
                    var tSlot = slot as Matrix2MaterialSlot;
                    var tProp = prop as Matrix2ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Texture2D:
                {
                    var tSlot = slot as Texture2DInputMaterialSlot;
                    var tProp = prop as Texture2DShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.texture = tProp.value.texture;
                    }
                }
                break;

                case ConcreteSlotValueType.Texture2DArray:
                {
                    var tSlot = slot as Texture2DArrayInputMaterialSlot;
                    var tProp = prop as Texture2DArrayShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.textureArray = tProp.value.textureArray;
                    }
                }
                break;

                case ConcreteSlotValueType.Texture3D:
                {
                    var tSlot = slot as Texture3DInputMaterialSlot;
                    var tProp = prop as Texture3DShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.texture = tProp.value.texture;
                    }
                }
                break;

                case ConcreteSlotValueType.Cubemap:
                {
                    var tSlot = slot as CubemapInputMaterialSlot;
                    var tProp = prop as CubemapShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.cubemap = tProp.value.cubemap;
                    }
                }
                break;

                case ConcreteSlotValueType.Gradient:
                {
                    var tSlot = slot as GradientInputMaterialSlot;
                    var tProp = prop as GradientShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Vector4:
                {
                    var tSlot       = slot as Vector4MaterialSlot;
                    var vector4Prop = prop as Vector4ShaderProperty;
                    var colorProp   = prop as ColorShaderProperty;
                    if (tSlot != null && vector4Prop != null)
                    {
                        tSlot.value = vector4Prop.value;
                    }
                    else if (tSlot != null && colorProp != null)
                    {
                        tSlot.value = colorProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Vector3:
                {
                    var tSlot = slot as Vector3MaterialSlot;
                    var tProp = prop as Vector3ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Vector2:
                {
                    var tSlot = slot as Vector2MaterialSlot;
                    var tProp = prop as Vector2ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Vector1:
                {
                    var tSlot = slot as Vector1MaterialSlot;
                    var tProp = prop as Vector1ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Boolean:
                {
                    var tSlot = slot as BooleanMaterialSlot;
                    var tProp = prop as BooleanShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;
                }

                AddSlot(slot);
                validNames.Add(id);
            }

            var outputStage = asset.effectiveShaderStage;

            foreach (var slot in asset.outputs)
            {
                var newSlot = MaterialSlot.CreateMaterialSlot(slot.valueType, slot.id, slot.RawDisplayName(),
                                                              slot.shaderOutputName, SlotType.Output, Vector4.zero, outputStage, slot.hidden);
                AddSlot(newSlot);
                validNames.Add(slot.id);
            }

            RemoveSlotsNameNotMatching(validNames, true);

            // sort slot order to match subgraph property order
            SetSlotOrder(validNames);
        }
Example #11
0
        public static bool AreCompatible(SlotValueType inputType, ConcreteSlotValueType outputType)
        {
            if (s_ValidConversions == null)
            {
                var validVectors = new List <SlotValueType>()
                {
                    SlotValueType.Dynamic, SlotValueType.DynamicVector,
                    SlotValueType.Vector1, SlotValueType.Vector2, SlotValueType.Vector3, SlotValueType.Vector4
                };

                s_ValidConversions = new Dictionary <ConcreteSlotValueType, List <SlotValueType> >()
                {
                    { ConcreteSlotValueType.Boolean, new List <SlotValueType>()
                      {
                          SlotValueType.Boolean
                      } },
                    { ConcreteSlotValueType.Vector1, validVectors },
                    { ConcreteSlotValueType.Vector2, validVectors },
                    { ConcreteSlotValueType.Vector3, validVectors },
                    { ConcreteSlotValueType.Vector4, validVectors },
                    { ConcreteSlotValueType.Matrix2, new List <SlotValueType>()
                      {
                          SlotValueType.Dynamic, SlotValueType.DynamicMatrix, SlotValueType.Matrix2
                      } },
                    { ConcreteSlotValueType.Matrix3, new List <SlotValueType>()
                      {
                          SlotValueType.Dynamic, SlotValueType.DynamicMatrix, SlotValueType.Matrix2, SlotValueType.Matrix3
                      } },
                    { ConcreteSlotValueType.Matrix4, new List <SlotValueType>()
                      {
                          SlotValueType.Dynamic, SlotValueType.DynamicMatrix, SlotValueType.Matrix2, SlotValueType.Matrix3, SlotValueType.Matrix4
                      } },
                    { ConcreteSlotValueType.Texture2D, new List <SlotValueType>()
                      {
                          SlotValueType.Texture2D
                      } },
                    { ConcreteSlotValueType.Texture3D, new List <SlotValueType>()
                      {
                          SlotValueType.Texture3D
                      } },
                    { ConcreteSlotValueType.Texture2DArray, new List <SlotValueType>()
                      {
                          SlotValueType.Texture2DArray
                      } },
                    { ConcreteSlotValueType.Cubemap, new List <SlotValueType>()
                      {
                          SlotValueType.Cubemap
                      } },
                    { ConcreteSlotValueType.SamplerState, new List <SlotValueType>()
                      {
                          SlotValueType.SamplerState
                      } },
                    { ConcreteSlotValueType.Gradient, new List <SlotValueType>()
                      {
                          SlotValueType.Gradient
                      } },
                };
            }

            if (s_ValidConversions.TryGetValue(outputType, out s_ValidSlotTypes))
            {
                return(s_ValidSlotTypes.Contains(inputType));
            }
            throw new ArgumentOutOfRangeException("Unknown Concrete Slot Type: " + outputType);
        }
Example #12
0
        void AddSlots(SlotValueType edgeType)
        {
            // Valuetype gets the type should be the type for input and output
            switch (edgeType)
            {
            case SlotValueType.Boolean:
                AddSlot(new BooleanMaterialSlot(kInputSlotID, "", "", SlotType.Input, false));
                AddSlot(new BooleanMaterialSlot(kOutputSlotID, "", "", SlotType.Output, false));
                break;

            case SlotValueType.Vector1:
                AddSlot(new DynamicVectorMaterialSlot(kInputSlotID, "", "", SlotType.Input, Vector4.zero));
                AddSlot(new DynamicVectorMaterialSlot(kOutputSlotID, "", "", SlotType.Output, Vector4.zero));
                break;

            case SlotValueType.Vector2:
                AddSlot(new DynamicVectorMaterialSlot(kInputSlotID, "", "", SlotType.Input, Vector4.zero));
                AddSlot(new DynamicVectorMaterialSlot(kOutputSlotID, "", "", SlotType.Output, Vector4.zero));
                break;

            case SlotValueType.Vector3:
                AddSlot(new DynamicVectorMaterialSlot(kInputSlotID, "", "", SlotType.Input, Vector4.zero));
                AddSlot(new DynamicVectorMaterialSlot(kOutputSlotID, "", "", SlotType.Output, Vector4.zero));
                break;

            case SlotValueType.Vector4:
                AddSlot(new DynamicVectorMaterialSlot(kInputSlotID, "", "", SlotType.Input, Vector4.zero));
                AddSlot(new DynamicVectorMaterialSlot(kOutputSlotID, "", "", SlotType.Output, Vector4.zero));
                break;

            case SlotValueType.Matrix2:
                AddSlot(new DynamicMatrixMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new DynamicMatrixMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.Matrix3:
                AddSlot(new DynamicMatrixMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new DynamicMatrixMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.Matrix4:
                AddSlot(new DynamicMatrixMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new DynamicMatrixMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.Texture2D:
                AddSlot(new Texture2DMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new Texture2DMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.Texture2DArray:
                AddSlot(new Texture2DArrayMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new Texture2DArrayMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.Texture3D:
                AddSlot(new Texture3DMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new Texture3DMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.Cubemap:
                AddSlot(new CubemapMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new CubemapMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.SamplerState:
                AddSlot(new SamplerStateMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new SamplerStateMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.Gradient:
                AddSlot(new GradientMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new GradientMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.Dynamic:
                AddSlot(new DynamicValueMaterialSlot(kInputSlotID, "", "", SlotType.Input, Matrix4x4.zero));
                AddSlot(new DynamicValueMaterialSlot(kOutputSlotID, "", "", SlotType.Output, Matrix4x4.zero));
                break;

            case SlotValueType.DynamicMatrix:
                AddSlot(new DynamicMatrixMaterialSlot(kInputSlotID, "", "", SlotType.Input));
                AddSlot(new DynamicMatrixMaterialSlot(kOutputSlotID, "", "", SlotType.Output));
                break;

            case SlotValueType.DynamicVector:
                AddSlot(new DynamicVectorMaterialSlot(kInputSlotID, "", "", SlotType.Input, Vector4.zero));
                AddSlot(new DynamicVectorMaterialSlot(kOutputSlotID, "", "", SlotType.Output, Vector4.zero));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #13
0
 public abstract bool IsCompatibleWithInputSlotType(SlotValueType inputType);
 public override bool IsCompatibleWithInputSlotType(SlotValueType inputType)
 {
     return(inputType == SlotValueType.Vector3 ||
            inputType == SlotValueType.Vector1);
 }
Example #15
0
 public override bool IsCompatibleWithInputSlotType(SlotValueType inputType)
 {
     return(inputType == SlotValueType.Boolean);
 }
Example #16
0
        public virtual void UpdateSlots()
        {
            var validNames = new List <int>();

            if (asset == null)
            {
                return;
            }

            var props = asset.inputs;
            var toFix = new HashSet <(SlotReference from, SlotReference to)>();

            foreach (var prop in props)
            {
                SlotValueType valueType      = prop.concreteShaderValueType.ToSlotValueType();
                var           propertyString = prop.guid.ToString();
                var           propertyIndex  = m_PropertyGuids.IndexOf(propertyString);
                if (propertyIndex < 0)
                {
                    propertyIndex = m_PropertyGuids.Count;
                    m_PropertyGuids.Add(propertyString);
                    m_PropertyIds.Add(prop.guid.GetHashCode());
                }
                var id = m_PropertyIds[propertyIndex];

                //for whatever reason, it seems like shader property ids changed between 21.2a17 and 21.2b1
                //tried tracking it down, couldnt find any reason for it, so we gotta fix it in post (after we deserialize)
                List <MaterialSlot> inputs = new List <MaterialSlot>();
                MaterialSlot        found  = null;
                GetInputSlots(inputs);
                foreach (var input in inputs)
                {
                    if (input.shaderOutputName == prop.referenceName && input.id != id)
                    {
                        found = input;
                        break;
                    }
                }

                MaterialSlot slot = MaterialSlot.CreateMaterialSlot(valueType, id, prop.displayName, prop.referenceName, SlotType.Input, Vector4.zero, ShaderStageCapability.All);

                // Copy defaults
                switch (prop.concreteShaderValueType)
                {
                case ConcreteSlotValueType.SamplerState:
                {
                    var tSlot = slot as SamplerStateMaterialSlot;
                    var tProp = prop as SamplerStateShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.defaultSamplerState = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Matrix4:
                {
                    var tSlot = slot as Matrix4MaterialSlot;
                    var tProp = prop as Matrix4ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Matrix3:
                {
                    var tSlot = slot as Matrix3MaterialSlot;
                    var tProp = prop as Matrix3ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Matrix2:
                {
                    var tSlot = slot as Matrix2MaterialSlot;
                    var tProp = prop as Matrix2ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Texture2D:
                {
                    var tSlot = slot as Texture2DInputMaterialSlot;
                    var tProp = prop as Texture2DShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.texture = tProp.value.texture;
                    }
                }
                break;

                case ConcreteSlotValueType.Texture2DArray:
                {
                    var tSlot = slot as Texture2DArrayInputMaterialSlot;
                    var tProp = prop as Texture2DArrayShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.textureArray = tProp.value.textureArray;
                    }
                }
                break;

                case ConcreteSlotValueType.Texture3D:
                {
                    var tSlot = slot as Texture3DInputMaterialSlot;
                    var tProp = prop as Texture3DShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.texture = tProp.value.texture;
                    }
                }
                break;

                case ConcreteSlotValueType.Cubemap:
                {
                    var tSlot = slot as CubemapInputMaterialSlot;
                    var tProp = prop as CubemapShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.cubemap = tProp.value.cubemap;
                    }
                }
                break;

                case ConcreteSlotValueType.Gradient:
                {
                    var tSlot = slot as GradientInputMaterialSlot;
                    var tProp = prop as GradientShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Vector4:
                {
                    var tSlot       = slot as Vector4MaterialSlot;
                    var vector4Prop = prop as Vector4ShaderProperty;
                    var colorProp   = prop as ColorShaderProperty;
                    if (tSlot != null && vector4Prop != null)
                    {
                        tSlot.value = vector4Prop.value;
                    }
                    else if (tSlot != null && colorProp != null)
                    {
                        tSlot.value = colorProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Vector3:
                {
                    var tSlot = slot as Vector3MaterialSlot;
                    var tProp = prop as Vector3ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Vector2:
                {
                    var tSlot = slot as Vector2MaterialSlot;
                    var tProp = prop as Vector2ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Vector1:
                {
                    var tSlot = slot as Vector1MaterialSlot;
                    var tProp = prop as Vector1ShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;

                case ConcreteSlotValueType.Boolean:
                {
                    var tSlot = slot as BooleanMaterialSlot;
                    var tProp = prop as BooleanShaderProperty;
                    if (tSlot != null && tProp != null)
                    {
                        tSlot.value = tProp.value;
                    }
                }
                break;
                }

                AddSlot(slot);
                validNames.Add(id);

                if (found != null)
                {
                    List <IEdge> edges = new List <IEdge>();
                    owner.GetEdges(found.slotReference, edges);
                    foreach (var edge in edges)
                    {
                        toFix.Add((edge.outputSlot, slot.slotReference));
                    }
                }
            }

            foreach (var slot in asset.outputs)
            {
                var outputStage = GetSlotCapability(slot);
                var newSlot     = MaterialSlot.CreateMaterialSlot(slot.valueType, slot.id, slot.RawDisplayName(),
                                                                  slot.shaderOutputName, SlotType.Output, Vector4.zero, outputStage, slot.hidden);
                AddSlot(newSlot);
                validNames.Add(slot.id);
            }

            RemoveSlotsNameNotMatching(validNames, true);

            // sort slot order to match subgraph property order
            SetSlotOrder(validNames);

            foreach (var(from, to) in toFix)
            {
                //for whatever reason, in this particular error fix, GraphView will incorrectly either add two edgeViews or none
                //but it does work correctly if we dont notify GraphView of this added edge. Gross.
                owner.UnnotifyAddedEdge(owner.Connect(from, to));
            }
        }