private void WritePixel(float u, float v, int x, int y) { var noise = u * NoisePoints; var noiseIndex = (int)noise; var noiseFrac = noise % 1.0f; var noiseA = noisePoints[(noiseIndex + 0) % NoisePoints]; var noiseB = noisePoints[(noiseIndex + 1) % NoisePoints]; var noiseC = noisePoints[(noiseIndex + 2) % NoisePoints]; var noiseD = noisePoints[(noiseIndex + 3) % NoisePoints]; var color = MiddleColor; if (v < MiddlePoint) { color.a = SgtEase.Evaluate(BottomEase, SgtHelper.Sharpness(Mathf.InverseLerp(0.0f, MiddlePoint, v), BottomSharpness)); } else { color.a = SgtEase.Evaluate(TopEase, SgtHelper.Sharpness(Mathf.InverseLerp(1.0f, MiddlePoint, v), TopSharpness)); } var middle = SgtEase.Evaluate(MiddleEase, SgtHelper.Sharpness(1.0f - v, MiddleSharpness)); color.a *= SgtHelper.HermiteInterpolate(noiseA, noiseB, noiseC, noiseD, noiseFrac); color.r *= middle * color.a; color.g *= middle * color.a; color.b *= middle * color.a; color.a *= 1.0f - middle; generatedTexture.SetPixel(x, y, color); }
private void AddPath(ref Mesh mesh, ref int meshCount, ref int vertexCount) { var pathLength = Random.Range(PathLengthMin, PathLengthMax); var lineCount = 2 + (int)(pathLength * PathDetail); var quadCount = lineCount - 1; var vertices = quadCount * 2 + 2; if (vertexCount + vertices > 65000) { BakeMesh(mesh); mesh = GetMesh(meshCount); meshCount += 1; vertexCount = 0; } var angle = Random.Range(-Mathf.PI, Mathf.PI); var speed = 1.0f / PointDetail; var detailStep = 1.0f / PathDetail; var pointStep = detailStep * PointDetail; var pointFrac = 0.0f; var pointA = GetStart(angle + Mathf.PI); var pointB = GetNext(pointA, angle, speed); var pointC = GetNext(pointB, angle, speed); var pointD = GetNext(pointC, angle, speed); var coordFrac = 0.0f; var edgeFrac = -1.0f; var edgeStep = 2.0f / lineCount; var coordStep = detailStep * TrailTile; var angleA = angle; var angleB = GetNextAngle(angleA); var angleC = GetNextAngle(angleB); var angleD = GetNextAngle(angleC); var angleFrac = 0.0f; var angleStep = detailStep * AnimAngleDetail; var strengthA = 0.0f; var strengthB = GetNextStrength(); var strengthC = GetNextStrength(); var strengthD = GetNextStrength(); var strengthFrac = 0.0f; var strengthStep = detailStep * AnimStrengthDetail; var colorA = GetNextColor(); var colorB = GetNextColor(); var colorC = GetNextColor(); var colorD = GetNextColor(); var colorFrac = 0.0f; var colorStep = detailStep * ColorsDetail; var heightA = GetNextHeight(); var heightB = GetNextHeight(); var heightC = GetNextHeight(); var heightD = GetNextHeight(); var heightFrac = 0.0f; var heightStep = detailStep * TrailHeightsDetail; for (var i = 0; i < lineCount; i++) { while (pointFrac >= 1.0f) { Shift(ref pointA, ref pointB, ref pointC, pointD, ref pointFrac); pointD = GetNext(pointC, angle, speed); } while (angleFrac >= 1.0f) { Shift(ref angleA, ref angleB, ref angleC, angleD, ref angleFrac); angleD = GetNextAngle(angleC); } while (strengthFrac >= 1.0f) { Shift(ref strengthA, ref strengthB, ref strengthC, strengthD, ref strengthFrac); strengthD = GetNextStrength(); } while (colorFrac >= 1.0f) { Shift(ref colorA, ref colorB, ref colorC, colorD, ref colorFrac); colorD = GetNextColor(); } while (heightFrac >= 1.0f) { Shift(ref heightA, ref heightB, ref heightC, heightD, ref heightFrac); heightD = GetNextHeight(); } var point = SgtHelper.HermiteInterpolate3(pointA, pointB, pointC, pointD, pointFrac); var animAng = SgtHelper.HermiteInterpolate(angleA, angleB, angleC, angleD, angleFrac); var animStr = SgtHelper.HermiteInterpolate(strengthA, strengthB, strengthC, strengthD, strengthFrac); var color = SgtHelper.HermiteInterpolate(colorA, colorB, colorC, colorD, colorFrac); var height = SgtHelper.HermiteInterpolate(heightA, heightB, heightC, heightD, heightFrac); // Fade edges color.a *= Mathf.SmoothStep(1.0f, 0.0f, Mathf.Pow(Mathf.Abs(edgeFrac), TrailEdgeFade)); coords0.Add(new Vector4(coordFrac, 0.0f, animAng, animStr)); coords0.Add(new Vector4(coordFrac, height, animAng, animStr)); positions.Add(point); positions.Add(point); colors.Add(color); colors.Add(color); pointFrac += pointStep; edgeFrac += edgeStep; coordFrac += coordStep; angleFrac += angleStep; strengthFrac += strengthStep; colorFrac += colorStep; heightFrac += heightStep; } var vector = positions[1] - positions[0]; normals.Add(GetNormal(vector, vector)); normals.Add(GetNormal(vector, vector)); for (var i = 2; i < lineCount; i++) { var nextVector = positions[i] - positions[i - 1]; normals.Add(GetNormal(vector, nextVector)); normals.Add(GetNormal(vector, nextVector)); vector = nextVector; } normals.Add(GetNormal(vector, vector)); normals.Add(GetNormal(vector, vector)); for (var i = 0; i < quadCount; i++) { var offset = vertexCount + i * 2; indices.Add(offset + 0); indices.Add(offset + 1); indices.Add(offset + 2); indices.Add(offset + 3); indices.Add(offset + 2); indices.Add(offset + 1); } vertexCount += vertices; }