Here comes the sun!

posted in Orden Drakona
Published June 10, 2019
Advertisement

It’s been a while since my last update. Part of the reason was because I was sitting in a Russian hospital for two months. But I’ll leave that story for another time…… However I did manage to make quite a bit of progress.  I had some adventures in threading….. I had to rewrite my thread code like four times, but eventually I got it under control so things are running a LOT faster now. I’ll try to cover that in my next update.   Also I added the makings of lighting system, which brings me to today’s topic.

Since I wanted to start shading my planet, I of course needed a light. But I didn’t want some non-descript photons coming invisibly in from outer space.  A proper planet should orbit a sun!  So before doing the lighting I decided to make one. No problem, I had my trusty voxel sphere engine! ….

But wait!.... A voxel built sphere seemed like a waste of computing resources for just doing a sun.  I mean a sun doesn’t have overhangs and underground caverns. It’s just really a ball in space.  That being the case, I decided to add simple terrain mesh capability to my library.  On the other hand, to make it useful for other things, such as space games where a ship might get close to the sun, I decided to incorporate LOD, chunking and a few bells and whistles.  

The implementation parallels the voxel code pretty closely, except everything is scaled down to 2D from 3D. For instance instead of organizing my mesh into an octree, I use a quadtree.  The bounding shape is a pill instead of a sphere. This is because with height-mapped terrain, triangles can stretch a lot in the vertical direction and so spheres are really sub-optimal as they don’t enclose the geometry very tightly. For the sun it doesn’t matter, but I like to make stuff reusable. For example I could use this terrain code to build a simple moon. Like the voxel library it accepts functions that can generate terrain…..but back to the sun…..

For shading the sun, I’m using 5D noise, 3D for the object itself and 2D for time.  For the purposes of my noise function, time kind of sweeps around in a circle so I don’t run into precision problems on the GPU.  I could probably have done this with 4D noise and some tiling features, but there are some issues with that and I decided it was less of a headache to just go with 5D noise.

To do this you basically you take the modulus of linear time with your desired repetition interval, convert the result to radians such that 2XPi radians maps to your interval.  Then you take the sin and cos of that, and multiply both by some scaling factor, and feed that into two dimensions of your noise function.  The bigger the scaling factor, the faster your noise changes.

Right now it looks kind of basic, but later I’ll try to make it look more sun like by applying some other functions to the raw noise and maybe adding a few more octaves.  Also I was reading about god ray shaders and I think that might look good in combination with the noise functions.   

Here’s the video:

Hopefully for my next update I’ll have the planet orbiting the sun. And after that I plan on grabbing the JIT collision code from my old project and we’ll be down on the surface!

4 likes 1 comments

Comments

Green_Baron

Very nice ?

Of course Rayleigh Bénard convection comes to mind ?

June 10, 2019 08:24 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Advertisement