Exemple #1
0
    public override bool Calculate()
    {
        allInputsReady();

        if (m_Loops == 0 && (Inputs[0].connection == null || Inputs[0].connection.IsValueNull))//!allInputsReady())
        {
            Debug.LogError(" m_LoopCount set to 0 input 0 is null");
            m_Loops = 0;
            return(false);
        }
        if (m_Loops > 0 && (Inputs[1].connection == null || Inputs[1].connection.IsValueNull))//!allInputsReady())
        {
            Debug.LogError(" m_LoopCount set to 1 input 1 is null");
            m_Loops = 1;
            return(false);
        }
        if (m_Loops == 0)
        {
            Outputs[0].SetValue <TextureParam>(Inputs[0].GetValue <TextureParam>());
        }
        else
        {
            //check if any of our connects to Output Looped, output straight back to us
            //if so that creates a render case where the same renderTexture is the input and the output, so make a copy
            bool inputIsOutput = false;
            foreach (var c in Outputs[0].connections)
            {
                foreach (var o in c.body.Outputs)
                {
                    foreach (var c2 in o.connections)
                    {
                        if (c2.body == this)
                        {
//                            inputIsOutput = true;
                            Debug.LogError("found an in out is the same from " + o.body);
                        }
                    }
                }
            }
            if (inputIsOutput)
            {
                if (m_Temp == null)
                {
                    m_Temp = new TextureParam(Inputs[1].GetValue <TextureParam>());
                }
                Material m = TextureNode.GetMaterial("TextureOps");
                Graphics.Blit(Inputs[1].GetValue <TextureParam>().GetHWSourceTexture(), m_Temp.m_Destination, m,
                              (int)ShaderOp.CopyColorAndAlpha);

                Outputs[0].SetValue <TextureParam>(m_Temp);
            }
            else
            {
                Outputs[0].SetValue <TextureParam>(Inputs[1].GetValue <TextureParam>());
            }
        }
        Outputs[2].SetValue <float>((float)m_Loops / (float)m_LoopCount);
        m_Loops++;
//        Debug.LogError("Loop Count Inc" + m_Loops + " / " + m_LoopCount);
        if (m_Loops >= m_LoopCount)
        {
            Outputs[1].SetValue <TextureParam>(Inputs[1].GetValue <TextureParam>());
        }
        else
        {
            if (Outputs[2] != null)
            {
                Node.ms_GlobalDirtyID++;
                SetDirty(this);
                calculated = true; //so the descendant can calculate that uses output 0
                foreach (var c in Outputs[2].connections)
                {
                    if (c != null)
                    {
                        NodeEditor.ContinueCalculation(c.body);
                    }
                }
                calculated = false;
            }
            if (Outputs[0] != null)
            {
                Node.ms_GlobalDirtyID++;
                SetDirty(this);
                calculated = true; //so the descendant can calculate that uses output 0
                foreach (var c in Outputs[0].connections)
                {
                    if (c != null)
                    {
                        NodeEditor.ContinueCalculation(c.body);
                    }
                }
                calculated = false;
            }
        }
        return(m_Loops >= m_LoopCount);
    }