Software launches and lands rockets. You think JPL just had a couple of rocket scientists writing some python scripts on the side for the perseverance mission?
But I agree Facebook has a ridiculous amount of engineering potential wasted on a pretty useless problem (serving ads even better!)
Once you are an experienced programmer in a software company, you are earning a lot, and moving out of the software industry, where the prima-donna employees are physicists or engineers, you generally take a pay cut. A fusion company isn't going to hire an entry level programmer who hasn't proven himself.
So, to answer the question more explicitly, you need to be willing to follow your interests and not maximize the bottom line. This is my 28th year as a software engineer, and I've seen this pattern countless times. I've done the follow my interests, and also follow the money jobs, and prefer the respective good aspect of each approach over the other.
I'm happy to elaborate on a more private channel, email/twitter is in the profile.
Source: Cofounded a startup in comp.bio space ~3.5 years ago, been busy supercharging our scientists and increasing pace of innovation and haven't really ran out of ideas yet.