I got a new idea for the ocean rendering, so I figured I'd post it here.
Basically from a lot of messing around with commenting and profiling and different libraries, I figured out that:
- Rendering is cheap. Specially 2D rendering. Let's face it, the game refreshes the whole screen every tick (probably a lot more effort than it actually needs) and it still achieves hundreds of fps most of the time.
- Simulating 3D is expensive. All the polygons, the iterations, the calculations, the conversions, it's all a heavy load for the game to redo every tick, specially on low-end devices.
With that in mind, I thought of taking your approach in this thread - rendering the lighting on the ocean all at once - but from a 2D perspective. After all, the land needs polygons because it needs to draw out a detailed textured world, all with varying regions and terrains and lighting and stuff (and even that is a lot faster than the ocean currently is). The ocean doesn't, it's purely a visual aid, so there's no need for polygons, storing or calculating anything fancy.
With that in mind, here's the approach I thought up:
1. Draw the flat circle, either in the brighest or darkest shade (whatever's more convenient).
2. Calculate the "separator line" between the brightest/darkest shade and draw it out.
3. Go left-to-right top-to-bottom filling the circle area up to the "separator line", like a bucket fill.
4. TA-DA!
You could add more lines to get the smoother shading effect on the light edge. This is similar to your approach, but without using polygons, therefore:
- Polar-to-Cartesian calculations are kept to a minimum, as they're only needed for the "separator lines" which would have at most 10-20 points depending on how smooth you want them to be.
- No need to worry about the effect looking smooth on the circle edges, since the "bucket fill" approach would fill it all up with no issue.
- All the colouring is done at once at the pixel level, with no need for tons of iterating and rendering.
Thoughts?