protected virtual void Update() { if (thruster != null) { if (Application.isPlaying == true) { flickerOffset += flickerSpeed * Time.deltaTime; } if (points == null) { points = new float[128]; for (var i = points.Length - 1; i >= 0; i--) { points[i] = Random.value; } } var noise = Mathf.Repeat(flickerOffset, points.Length); var index = (int)noise; var frac = noise % 1.0f; var pointA = points[index]; var pointB = points[(index + 1) % points.Length]; var pointC = points[(index + 2) % points.Length]; var pointD = points[(index + 3) % points.Length]; var f = 1.0f - SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac) * flicker; var factor = SgtHelper.DampenFactor(damping, Time.deltaTime); throttle = Mathf.Lerp(throttle, thruster.Throttle, factor); transform.localScale = baseScale + throttleScale * throttle * f; } }
private float Sample() { var noise = Mathf.Repeat(offset, points.Length); var index = (int)noise; var frac = noise % 1.0f; var pointA = points[index]; var pointB = points[(index + 1) % points.Length]; var pointC = points[(index + 2) % points.Length]; var pointD = points[(index + 3) % points.Length]; return(SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac)); }
public void UpdateMesh() { if (Detail > 2) { if (generatedMesh == null) { generatedMesh = SgtHelper.CreateTempMesh("Mesh (Generated)"); ApplyMesh(); } var total = Detail + 1; var positions = new Vector3[total]; var coords1 = new Vector2[total]; var indices = new int[Detail * 3]; var angleStep = (Mathf.PI * 2.0f) / Detail; var noiseStep = 0.0f; if (Noise == true && NoisePoints > 0) { SgtHelper.BeginRandomSeed(NoiseSeed); { points.Clear(); for (var i = 0; i < NoisePoints; i++) { points.Add(Random.value); } noiseStep = NoisePoints / (float)Detail; } SgtHelper.EndRandomSeed(); } // Write center vertices positions[0] = Vector3.zero; coords1[0] = Vector2.zero; // Write outer vertices for (var point = 0; point < Detail; point++) { var angle = angleStep * point; var x = Mathf.Sin(angle); var y = Mathf.Cos(angle); var r = Radius; if (Wave == true) { var waveAngle = (angle + WavePhase * Mathf.Deg2Rad) * WavePoints; r += Mathf.Pow(Mathf.Cos(waveAngle) * 0.5f + 0.5f, WavePower * WavePower) * WaveStrength; } if (Noise == true && NoisePoints > 0) { var noise = Mathf.Repeat(noiseStep * point + NoisePhase, NoisePoints); //var noise = point * noiseStep + NoisePhase; var index = (int)noise; var frac = noise % 1.0f; var pointA = points[(index + 0) % NoisePoints]; var pointB = points[(index + 1) % NoisePoints]; var pointC = points[(index + 2) % NoisePoints]; var pointD = points[(index + 3) % NoisePoints]; r += SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac) * NoiseStrength; } // Write outer vertices var v = point + 1; positions[v] = new Vector3(x * r, y * r, 0.0f); coords1[v] = new Vector2(1.0f, 0.0f); } for (var tri = 0; tri < Detail; tri++) { var i = tri * 3; var v0 = tri + 1; var v1 = tri + 2; if (v1 >= total) { v1 = 1; } indices[i + 0] = 0; indices[i + 1] = v0; indices[i + 2] = v1; } generatedMesh.Clear(false); generatedMesh.vertices = positions; generatedMesh.uv = coords1; generatedMesh.triangles = indices; generatedMesh.RecalculateNormals(); generatedMesh.RecalculateBounds(); } }