Example #1
0
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            return(false);
        }
        if (m_Param == null)
        {
            m_Param = new TextureParam(m_TexWidth, m_TexHeight);
        }
        for (int x = 0; x < m_Param.m_Width; x++)
        {
            for (int z = 0; z < m_Param.m_Height; z++)
            {
                float px     = ((float)(x) / m_Param.m_Width) * m_ScaleX + m_OffsetX;
                float pz     = ((float)(z) / m_Param.m_Height) * m_ScaleY + m_OffsetY;
                float py     = 0;
                float mag    = 1.0f;
                float scaleh = 1.0f;
                for (int detail = 0; detail < m_Octaves; detail++)
                {
                    py     += (Mathf.PerlinNoise(px * mag, pz * mag)) * (float)scaleh * m_Noise;
                    mag    *= 2.0f;
                    scaleh *= 0.5f;
                }
                m_Param.Set(x, z, py, py, py, 1.0f);
            }
        }

        m_Cached = m_Param.CreateTexture();

        Outputs[0].SetValue <TextureParam> (m_Param);
        return(true);
    }
Example #2
0
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            return(false);
        }
        if (m_Param == null)
        {
            m_Param = new TextureParam(m_TexWidth, m_TexHeight);
        }
        float mx = m_Param.m_Width * (0.5f + m_OffsetX);
        float my = m_Param.m_Height * (0.5f + m_OffsetY);

        for (int x = 0; x < m_Param.m_Width; x++)
        {
            for (int y = 0; y < m_Param.m_Height; y++)
            {
                float dx   = (x - mx) / m_ScaleX;
                float dy   = (y - my) / m_ScaleY;
                float dist = 1.0f / Mathf.Pow(dx * dx + dy * dy, m_Power) - 1.0f;
                dist = Mathf.Clamp01(dist);
                m_Param.Set(x, y, dist, dist, dist, 1.0f);
            }
        }
        m_Cached = m_Param.CreateTexture();

        Outputs[0].SetValue <TextureParam> (m_Param);
        return(true);
    }
Example #3
0
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            return(false);
        }



        if (m_Input == null)
        {
            m_Input = new WebCamTexture(256, 256);
            m_Input.Play();
            Debug.Log("alloc new web cam");
        }

        if (!m_Input.isPlaying)
        {
            if (WebCamTexture.devices.Length > 0)
            {
                m_Input.deviceName = WebCamTexture.devices[0].name;
            }
            m_Input.Play();
            Debug.Log(" web cam not playing ");
            foreach (var x in WebCamTexture.devices)
            {
                Debug.Log(" device " + x.name);
            }
            return(false);
        }
        if (m_Param == null)
        {
            m_Param = new TextureParam(m_TexWidth, m_TexHeight);
        }
        try
        {
            for (int x = 0; x < m_Param.m_Width; x++)
            {
                for (int y = 0; y < m_Param.m_Height; y++)
                {
                    Color col = m_Input.GetPixel((int)(((float)x / (float)m_Param.m_Width) * m_Input.width), (int)(((float)y / (float)m_Param.m_Height) * m_Input.height));
                    m_Param.Set(x, y, col.r, col.g, col.b, 1.0f);
                    if (y == 0)
                    {
                        Debug.Log(" col " + x + " " + col);
                    }
                }
            }
        }
        catch (System.Exception _ex)
        {
            Debug.LogError("exception caught: " + _ex);
        }
        Debug.Log(" did something ");
        m_Cached = m_Param.CreateTexture();

        Outputs[0].SetValue <TextureParam> (m_Param);
        return(true);
    }
Example #4
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 #5
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);
    }
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            return(false);
        }

        if (m_Input == null)
        {
            return(false);
        }
        if (m_Param == null)
        {
            m_Param = new TextureParam(256, 1);
        }
        if (m_GradientCols.Count > 2)
        {
            try
            {
                for (float t = 0; t < 256.0; t += 1.0f)///256.0f)
                {
                    float along = (float)(m_GradientCols.Count - 2) / 256.0f;

                    int   index = (int)(t * along);
                    float blend = (t * along) - index;
                    Color lerp  = Color.Lerp(m_GradientCols[index], m_GradientCols[index + 1], blend);
                    data[(int)t] = lerp;
                }
            }

            catch (System.Exception _ex)
            {
                Debug.LogError("exception caught: " + _ex);
            }
        }

        m_Cached = m_Param.CreateTexture(data);

        Outputs[0].SetValue <TextureParam> (m_Param);
        return(true);
    }