Page 1 of 1

How to render realistic planets in love2d

Posted: Sun Feb 12, 2017 8:53 pm
by appleide
screenshot.png
screenshot.png (427.08 KiB) Viewed 4536 times
It rotates, and has a shadow, atmosphere, cloud layer. The above screenshot runs at 1024 * 768, with highdpi = true on 2016 Macbook.

I stumbled across a Russian article on how to render realistic 2D planets (https://habrahabr.ru/post/248381/). I couldn't find an english version of the article and had to read the google translated version and it took some time to understand, so I thought I might implement it and share it with you all. I hope you will find this useful.
renderplanet.love
(2.1 MiB) Downloaded 191 times
Github URL:
https://github.com/meric/renderplanet/

Please ask any questions you might have!

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 3:36 am
by MicroMacro
This is awesome! Great work!

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 5:41 am
by Jack5500
absolutly great. I don't know the impact on the performance though. How hard, performance wise, would it be to render more than 10 of those?

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 7:35 am
by raidho36
It's a very simple shader so I imagine very little. It creates a matrix in runtime instead of using one through a uniform, so that can be optimized.

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 2:19 pm
by appleide
Thanks!

raidho36 wrote:
Mon Feb 13, 2017 7:35 am
It's a very simple shader so I imagine very little. It creates a matrix in runtime instead of using one through a uniform, so that can be optimized.
Your suggestion led me to cache the atmosphere in the canvas to greatly improve performance - it was capped at 30 fps for 12 planets with highdpi = false, now performance is more than doubled.
Jack5500 wrote:
Mon Feb 13, 2017 5:41 am
absolutly great. I don't know the impact on the performance though. How hard, performance wise, would it be to render more than 10 of those?
With the atmosphere caching optimisation, on a 2016 MacBook it can do 80-90 frames per second for 12 earths, highdpi=false, and 60-70 frames per second for 12 earths, highdpi=true, each earth with its own shader.

After these optimisations I think rendering 10 or 12 is fine, but before, there was no more room performance-wise for rendering other assets. Thanks to raidho36 for his suggestion. :cool:

I updated the attachments in the first post.

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 2:59 pm
by DIEHARD25
Wow! Nice stuff! Great work!

p.s. here is a similar solution with more precise colours, author use 16-bit adresses to code colour grades, not sure is it suitable for LOVE 2D, but provide more variety in colour grades (up to 512 in total number of grades, if i not mistake)
sorry, still from Habr and in Russian, but with lots of code
link

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 3:46 pm
by Ref
23 fps on 10 year old pc.
Earth still rotating the wrong direction.

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 3:58 pm
by raidho36
Also I think you can compute planet coordinates programmatically, that would reduce texture bandwidth. May be more expensive though. Texture maps to flattened sphere by sine and cosine, reverse would be arcsine and arccosine.

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 6:22 pm
by appleide
Ref wrote:
Mon Feb 13, 2017 3:46 pm
23 fps on 10 year old pc.
Earth still rotating the wrong direction.
Not very realistic, is it?! I've updated the github repository so it rotates correctly. Thanks!

Re: How to render realistic planets in love2d

Posted: Mon Feb 13, 2017 8:22 pm
by Tanner
raidho36 wrote:
Mon Feb 13, 2017 3:58 pm
Also I think you can compute planet coordinates programmatically, that would reduce texture bandwidth. May be more expensive though. Texture maps to flattened sphere by sine and cosine, reverse would be arcsine and arccosine.
Yep! If you save them in a mesh it's probably faster for initial load and per render. I haven't benchmarked but I have created a 2d mesh with spherish uvs. https://gist.github.com/TannerRogalsky/ ... 01aa646d29