How to render realistic planets in love2d

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

How to render realistic planets in love2d

Post by appleide »

screenshot.png
screenshot.png (427.08 KiB) Viewed 16750 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 460 times
Github URL:
https://github.com/meric/renderplanet/

Please ask any questions you might have!
Last edited by appleide on Mon Feb 13, 2017 2:37 pm, edited 4 times in total.
User avatar
MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

Re: How to render realistic planets in love2d

Post by MicroMacro »

This is awesome! Great work!
https://github.com/ebernerd- where you can find all my work.
User avatar
Jack5500
Party member
Posts: 149
Joined: Wed Dec 07, 2011 8:38 pm
Location: Hamburg, Germany

Re: How to render realistic planets in love2d

Post 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?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How to render realistic planets in love2d

Post 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.
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: How to render realistic planets in love2d

Post 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.
DIEHARD25
Prole
Posts: 6
Joined: Wed Jul 27, 2016 7:53 am

Re: How to render realistic planets in love2d

Post 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
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: How to render realistic planets in love2d

Post by Ref »

23 fps on 10 year old pc.
Earth still rotating the wrong direction.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How to render realistic planets in love2d

Post 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.
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: How to render realistic planets in love2d

Post 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!
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: How to render realistic planets in love2d

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests