public Material Update(Parameters parms, IScaler scaler, Vector2 range, List <float> entries = null) { if (m_ScaleMaterial == null) { var circularGraduationMaterial = Resources.Load <Material>("Materials/CircularGraduation"); Assert.IsNotNull(circularGraduationMaterial); m_ScaleMaterial = new Material(circularGraduationMaterial); m_ScaleMaterial.hideFlags = HideFlags.DontSave; } UpdateShaderUniforms(m_ScaleMaterial, parms); if (m_ScaleTexture == null) { // TODO: have buffer size match its circular projection in screen space. m_ScaleTexture = new Texture2D(k_ScaleResolution, 1, TextureFormat.Alpha8, false); // TODO use Alpha8 m_ScaleTexture.filterMode = FilterMode.Bilinear; m_ScaleTexture.hideFlags = HideFlags.HideAndDontSave; } for (var i = 0; i < k_ScaleResolution; ++i) { s_ScalePixels[i] = 0; } if (entries != null) { foreach (var val in entries) { var angle = scaler.ValueToAngle(range.x, range.y, parms.angularRange, val); var normalized = (parms.angularRange - angle) / (parms.angularRange * 2); RenderPoint(s_ScalePixels, normalized, parms.entryLineWidth, 1); } } if (Math.Abs(parms.scaleDensityHint) > Mathf.Epsilon) { RenderScale(s_ScalePixels, parms, scaler, range, 0.5f); } m_ScaleTexture.LoadRawTextureData(s_ScalePixels); m_ScaleTexture.Apply(); m_ScaleMaterial.SetTexture(k_ShaderScaleTex, m_ScaleTexture); return(m_ScaleMaterial); }
static void RenderScale(byte[] target, Parameters parms, IScaler scaler, Vector2 range, float intensity) { var delta = Math.Abs(range.y - range.x) / Mathf.Max(1, parms.scaleDensityHint); // value delta between two points. // Find power of 10 above ptValDelta. var gradDelta = Mathf.Pow(10, Mathf.Ceil(Mathf.Log(delta) / Mathf.Log(10))); // Subdivide that power of 10 to get closer to target. while (gradDelta > 2 * delta) { gradDelta *= 0.5f; } var pos = Mathf.Ceil(range.x / gradDelta) * gradDelta; do { var angle = scaler.ValueToAngle(range.x, range.y, parms.angularRange, pos); var normalized = (parms.angularRange - angle) / (parms.angularRange * 2); RenderPoint(target, normalized, parms.lineWidth, intensity); pos += gradDelta; }while (pos < range.y); }