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); }
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); }
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); }