I’m trying to animate ocean waves using the Gerstner wave function with a grid on an editablemesh where the vertices are positioned more closely together near the camera and spread further apart in the distance for performance, but I’ve been struggling to get the logic behind that LOD system. Any help to get this effect?

```
local WaterMeshPart = workspace.Water.MeshPart
local EditableMesh = Instance.new("EditableMesh")
EditableMesh.Parent = WaterMeshPart
local CameraPosition = workspace.Camera.CFrame.Position
local Size, Padding = 100, 10
for y = 1, Size do
local Raw = {}
for x = 1, Size do
Raw[x] = EditableMesh:AddVertex(Vector3.new((Padding * (x - 1)) - (Padding * (Size - 1)) / 2, 0, (Padding * (y - 1)) - (Padding * (Size - 1)) / 2))
end
Vertices[y] = Raw
end
for y = 1, Size - 1 do
for x = 1, Size - 1 do
local Vertex1, Vertex2 = Vertices[y + 1][x], Vertices[y][x + 1]
local Vertex3, Vertex4 = Vertices[y][x], Vertices[y + 1][x + 1]
EditableMesh:AddTriangle(Vertex3, Vertex1, Vertex2)
EditableMesh:AddTriangle(Vertex1, Vertex4, Vertex2)
end
end
```