Exemple #1
0
        public int GetCompCount()
        {
            if (conType == ConType.cInput)
            {
                if (IsConnected())
                {
                    return(inputCon.GetCompCount());
                }
                else
                {
                    int cc = 0;
                    if (SF_Tools.CompCountOf(valueType, out cc))
                    {
                        return(cc);
                    }
                    else
                    {
                        Debug.LogWarning("[Shader Forge] - invalid component count in [" + label + "] of " + node.name + "");
                        return(node.texture.CompCount);                        // This is super weird, shouldn't read from the max comp count, read from the connection type instead
                    }
                }
            }



            OutChannel oc = outputChannel;

            if (oc == OutChannel.All)
            {
                int cc = 0;
                if (SF_Tools.CompCountOf(valueType, out cc))
                {
                    return(cc);
                }
                else
                {
                    Debug.LogWarning("[Shader Forge] - invalid component count in [" + label + "] of " + node.name + "");
                    return(node.texture.CompCount);                    // This is super weird, shouldn't read from the max comp count, read from the connection type instead
                }
            }
            else if (oc == OutChannel.RGB)
            {
                return(3);
            }
            if (oc == OutChannel.RG)
            {
                return(2);
            }

            int custCount = SF_Tools.ComponentCountOf(customValueType);

            if (custCount != 0)
            {
                return(custCount);
            }

            return(1);
        }
        public void Draw()
        {
            if (aboutToBeDeleted && !connector.IsConnected())             // It's disconnected, don't mark it anymore
            {
                aboutToBeDeleted = false;
            }

            if (!connector.IsConnected())
            {
                return;
            }

#if UNITY_2018
            if (Event.current.rawType != EventType.Repaint)
#else
            if (Event.current.rawType != EventType.repaint)
#endif
            { return; }

            //Vector2 a = connector.GetConnectionPoint();
            //Vector2 b = connector.inputCon.GetConnectionPoint();
            int  cc          = connector.GetCompCount();
            bool isMatrix4x4 = (cc == 16);
            if (isMatrix4x4)
            {
                cc = 1;
            }

            Color color = DeleteImminent() ? new Color(1f, 0f, 0f, 0.7f) : connector.GetConnectionLineColor();

            // TEMP:
            ReconstructShapes();

            //GUILines.DrawStyledConnection( editor, a, b, cc,  color);


            //switch(SF_Settings.ConnectionLineStyle){
            //case ConnectionLineStyle.Bezier:
            if (isMatrix4x4)
            {
                //GUILines.DrawMatrixConnection( editor, connector.GetConnectionPoint(), connector.inputCon.GetConnectionPoint(), color );
                GUILines.DrawLines(editor, this[ConnectionLineStyle.Bezier, 0], color, GetConnectionWidth(), true);
                GUILines.DrawLines(editor, this[ConnectionLineStyle.Bezier, 1], color, GetConnectionWidth(), true, true);
                GUILines.DrawLines(editor, this[ConnectionLineStyle.Bezier, 2], color, GetConnectionWidth(), true);
            }
            else
            {
                for (int i = 0; i < cc; i++)
                {
                    GUILines.DrawLines(editor, this[ConnectionLineStyle.Bezier, i], color, GetConnectionWidth(), true);
                }
            }

            //break;
            //}
        }
        public void UpdateInputLabels()
        {
            string rgba = "RGBA";

            int conCount = 4;
            int cSub     = 0;

            for (int i = 0; i < conCount; i++)
            {
                SF_NodeConnector con = connectors[i + 1];
                if (GetInputIsConnected(con.strID))
                {
                    int cc = con.GetCompCount();
                    con.label = rgba.Substring(cSub, cc);
                    if (cc == 1)
                    {
                        con.color = channelColors[cSub];
                    }
                    cSub += cc;
                }
                else
                {
                    con.label = "";
                    con.color = SF_NodeConnector.colorEnabledDefault;
                    cSub++;
                }
            }
        }
        public override void PrepareRendering(Material mat)
        {
            Vector4[] masks = new Vector4[] {
                Vector4.zero,
                Vector4.zero,
                Vector4.zero,
                Vector4.zero
            };
            Vector4 offsets = Vector4.zero;
            int     head    = 0;

            for (int i = 0; i < GetAmountOfConnectedInputs(); i++)
            {
                SF_NodeConnector con = connectors[i + 1];
                if (GetInputIsConnected(con.strID))
                {
                    int cc = con.GetCompCount();
                    for (int j = head; j < cc + head; j++)
                    {
                        masks[i][j] = 1f;
                    }
                    offsets[i] = head;
                    head      += cc;
                }
            }

            //for( int i = 0; i < 4; i++ ) {
            //	Debug.Log("Masks: " + masks[i]);
            //}

            mat.SetVector("_A_mask", masks[0]);
            mat.SetVector("_B_mask", masks[1]);
            mat.SetVector("_C_mask", masks[2]);
            mat.SetVector("_D_mask", masks[3]);
            mat.SetVector("_offsets", offsets);
        }