public void Render(WorldCamera camera, int elapsedMs, Vector3 target) { // Increasing the line segment length here will essentially increase the frequency, // which leads to a better look compared to vanilla. We can't replicate the original 1:1 // because we actually draw the lightning in screen space CalculateLineJitter(elapsedMs, LineSegments, LineSegmentLength * 1.5f, 0); // Call lightning ramps alpha from 1->0 in 127 millisecond intervals using cosine to create quick // "flashes" of lightning. // You can visualize the ramp in Wolfram Alpha: // https://www.wolframalpha.com/input/?i=plot+cos%28%28x+mod+127%29+%2F+254+*+PI%29+from+x%3D0+to+768 var alphaRamp = MathF.Cos(elapsedMs % 127 / 127f * 0.5f * MathF.PI); var alpha = (byte)(alphaRamp * 255); var color = new PackedLinearColorA(alpha, alpha, alpha, alpha); // These are normals for screen-space pixels var(right, up) = camera.GetBillboardNormals(); // Vector used to extrude the line to it's intended screen-space width var extrudeVec = ArcWidth / 2 * right; for (var i = 0; i < LineSegments; i++) { ref var leftVertex = ref Vertices[i * 2]; ref var rightVertex = ref Vertices[i * 2 + 1];