Example #1
0
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            //Debug.LogError(" input no ready");
            return(false);
        }
        TextureParam input = null;

        if (Inputs[0].connection != null)
        {
            input = Inputs[0].connection.GetValue <TextureParam>();
        }
        if (m_Param == null)
        {
            m_Param = new TextureParam(m_TexWidth, m_TexHeight);
        }
        if (input == null)
        {
            Debug.LogError(" input null");
        }
        float[] values = { m_Value1, m_Value2, m_Value3 };
        float[] gauss  = { 0.0585f, 0.0965f, 0.0585f, 0.0965f, 0.1591f, 0.0965f, 0.0585f, 0.0965f, 0.0585f };

        if (input != null && m_Param != null)
        {
            Random.seed = 0x127365;
            for (int x = 0; x < m_Param.m_Width; x++)
            {
                for (int y = 0; y < m_Param.m_Height; y++)
                {
                    m_Param.SetCol(x, y, Color.black);
                }
            }
            for (int i = 0; i < m_Value1; i++)
            {
                float dx = Random.Range(-m_Value2, m_Value2);
                float dy = Random.Range(-m_Value2, m_Value2);


                for (float x = 0; x < m_Param.m_Width; x += 1.0f / m_Value3)
                {
                    for (float y = 0; y < m_Param.m_Height; y += 1.0f / m_Value3)
                    {
                        Color col = input.GetCol((int)(x), (int)y);

                        Color d = m_Param.GetCol((int)(x * m_Value3 + dx), (int)(y * m_Value3 + dy));
                        d += col;
                        m_Param.SetCol((int)(x * m_Value3 + dx), (int)(y * m_Value3 + dy), d);
                    }
                }
            }
        }
        m_Cached = m_Param.CreateTexture();
        Outputs[0].SetValue <TextureParam> (m_Param);
        return(true);
    }
Example #2
0
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            //Debug.LogError(" input no ready");
            return(false);
        }
        TextureParam input = null;

        if (Inputs[0].connection != null)
        {
            input = Inputs[0].connection.GetValue <TextureParam>();
        }
        if (m_Param == null)
        {
            m_Param = new TextureParam(m_TexWidth, m_TexHeight);
        }
        if (input == null)
        {
            Debug.LogError(" input null");
        }
        if (input != null && m_Param != null)
        {
            float[] heights = new float[m_Param.m_Width * m_Param.m_Height];

            for (int x = 0; x < m_Param.m_Width; x++)
            {
                for (int y = 0; y < m_Param.m_Height; y++)
                {
                    Color col = input.GetCol(x, y);
                    float h   = col.r * col.r + col.g * col.g + col.b * col.b;
                    h = Mathf.Sqrt(h);
                    heights[x + y * m_Param.m_Width] = h;
                }
            }

            for (int x = 0; x < m_Param.m_Width - 1; x++)
            {
                for (int y = 0; y < m_Param.m_Height - 1; y++)
                {
                    float h0     = heights[x + y * m_Param.m_Width];
                    float hright = heights[x + 1 + y * m_Param.m_Width];
                    float hdown  = heights[x + (y + 1) * m_Param.m_Width];

                    Vector3 right = new Vector3(1, (hright - h0) * m_Value1, 0);
                    Vector3 down  = new Vector3(0, (hdown - h0) * m_Value1, 1);
                    Vector3 norm  = Vector3.Cross(down, right);
                    norm.Normalize();
                    m_Param.SetCol(x, y, new Color(norm.x * 0.5f + 0.5f, norm.z * 0.5f + 0.5f, norm.y * 0.5f + 0.5f));
                }
            }
        }
        m_Cached = m_Param.CreateTexture();
        Outputs[0].SetValue <TextureParam> (m_Param);
        return(true);
    }