I’m trying to recreate the solar system with Processing using somewhat realistic proportions (at scale) and real astronomical data. My goal is to instill a feeling of vastness; users should get an approximate idea of how big is our solar system.
You can find the project source code in this github repository: PocketPlanetarium
I apologize in advance for the ugly code, this project started as a college assignment and I consider it a proof of concept. I’m aware it could use a bit of refactoring love and decoupling as well. I plan to overhaul and expand it in the future, I’m also looking forward to port it to P5.js.
The main entity is the AstronomicalBody, which represents any physical body that could be found in a solar system: be it a star, a planet, a comet, etc. Right now it can only be either the Sun, one of the 8 main planets, or a moon of some planet. This entity has a bunch of properties, such as the radius, mass and parameters that define its orbit. It also contains a 3D mesh, and a list of orbitating bodies, which are AstronomicalBodies too.
When an AstronomicalBody is told to be displayed, it first computes its axial rotation and orbit rotation for the current time using Kepler laws of orbitation, draws itself in the correct position, and tells its orbitating bodies to display themselves too. This way we can draw the whole Solar system by telling the Sun to display itself, which in turn propagate to all planets and their respective moons.
SolarSystem is another entity whose main role is to load the Sun and all planets, and render the whole system and lightning. There are more components involved, but they’re mostly controls, camera and stuff.
The problem, or question to be more precise, is the following: when I try to execute it using an iGPU, such as Intel UHD 630 (which is the one I’m using), it takes quite a while to show something. Using a discrete GPU solves the problem, but I would like to understand why is happening, and if there’s a solution for a iGPU or a low spec GPU.
I have some sort of loading screen, to ease that UX itch, and I wanted to code a simple animation tweaking the “LOADING…” text opacity. I noticed that loading all data from files and creating all the data structures takes a breeze, but as soon as it reaches the “drawing time” it takes ages. However, it only happens at the initial render, after that the app runs smoothly. I fail to understand why the performance is so bad just at the first render.
This is a problem, because I would like to show the loading screen animation while all the slow stuff is running in the background. But this is impossible, as the main loop freezes at that single iteration, when the loading finishes and the
sun.display() takes place, leaving the screen blocked in the last loading animation frame as it cannot clear the screen buffer. It is not possible to throw a thread for carrying out that initial render while the main loop shows the animation, because
thread() doesn’t have drawing capabilities.
In my first versions it was a complete no-go, as it took +30min to load with an iGPU. I was able to solve it though when I noticed I was forcing a gigantic scale →
perspective(PI/3.0,(float)width/height,1, 10000000); and
Managed to reduce it to just 1min by tuning it down to something more reasonable →
perspective(PI/3.0,(float)width/height,1, 900); and
However, it doesn’t matter if I tweak the size nor the distance scales to accomodate an even smaller perspective, I cannot surpass that 50s - 1min wall. Any ideas?