Planet shader and atmosphere scattering

I would really like to test how it looks ingame even if it still has some artifacts :slight_smile:

Can’t wait untill you publish it :wink:

Yep, you’re trusted now jiyarza, there’s no way out of this one! And with good reason; it’s getting so much better every time.

jiyarza said:@sbook, I read you about showing the clouds moving. Really, its not worth the bandwith at least just yet. All the shader is doing is rotating two textures in opposite directions (surface & clouds). I mean, it's not clouds evolving and changing shape or something like that.


I was more joking than anything ;) This is beyond cool already!

The last picture looks very cool! Keep on going!

Cool stuff, very exciting, very realistic!

It should work well with a bigger planet radius, currently it is set at the Earth radius (considering 1 unit = 1 Km). However the illusion of a real scale planet seems to work better by multiplying this amount x10 or even x100. I have seen rendering problems when using 10^6 order radius (when 1 unit = 1 meter). Anyway, you can try yourself changing these values in the Main class.



Another ingredient to create the real scale illusion is the camera relative speed. Currently you can traverse the whole atmosphere in a fraction of a second so it feels small. Maybe it can be improved by setting the starting position closer to the outer atmosphere and decreasing the relative speed in the setupCamera() method, to a point it takes several seconds to land.



The last ingredient I think will be LOD, with dynamic ground LOD the planet should become believable at low altitude.



I am not sure about the atmosphere covering the starfield tho. A posible way to do it is fading out the skybox altogether as you get to a certain altitude.



The params that are bound to keys are safe to mess with. The scale params (those with the word ‘scale’ in their name) are fixed because the depth function used by the shader was approximated using these values.



I have seen that some values work better than others in some situations, so maybe the xxxFromAtmosphere materials might use different values for Kr, Km or ESun (both scattering constants and the sun light intensity) to get a more dense atmosphere.



The current code is somewhat aimed to make the Earth look nice. However my actual intention is to use initially procedural textures with heightmaps so you don’t lose detail as you get close. And if I get to learn how to do it I would also like to use a dynamic LOD terrain mesh (perhaps with TerraMonkey?).



My pleasure :).

Wow, this is fantastic! i have got it running on my macbook and it runs really well now you have made the update, thank you so much for all your hard work and sharing your results.

Just a reminder and compromise for myself. I have not had much time lately for this, and there are still a couple of minor issues (compared to the hell freezing and the like which I had earlier) but by all means I’m posting the code this week. The remaining issues are:


  • Entering the atmosphere is not very smooth (you don’t get disintegrated, but if you like beautiful things like I do, it will make you chuckle).


  • Atmosphere gradient looks rough (probably there is a jargon for this effect) under certain circumstances at low altitude.


  • The ground/clouds rotation effect produces a sewing effect along the texture seams (but since this is not part of the atmosphere scattering itself I prefer to share it and ask the pros why, oh why on earth this happens :)).


  • The ground lighting is rather crude and might be improved (using phong or similar). I have not dared yet, as the shaders are already pretty complex for me and I tend to break them too easily.





    Overall, these things need improvement and I will focus on them this week.



    The thing consists of:


  • Four jme3 material definitions (for both sky and ground seen from both space and inside the atmosphere).


  • Their respective vertex and fragment shaders.


  • An example jme3 material for the Earth model, with static textures from NASA.


  • A Planet class with planetary properties (logic layer).


  • A PlanetRenderer class (view layer), which sets up the materials according to the planet properties and performs the update each frame. The update method also needs to swap materials according to camera position (outer space or inside atmosphere)).



    I’ll post a couple pics with the latest when I get home later. Also will illustrate the mentioned issues. Thank you guys for your encouraging comments.





    Cheers.

I’m really looking forward to test that :smiley:

good work so far

Sewing effect? not sure if this is what you mean, but did you tried setting the minimize and miximize filters to higher quality ones (in texture obejct)

The sewing effect I think he means texture seams. It’s due to the sphere shape not having good UV coordinates for this sort of thing. When you map a square texture onto a sphere the poles will stretch the texture by a lot.

One way to solve it is by using cubemaps.

I have that too Momoko, though with the sewing effect I mean the following:









I am rotating the textures from inside the shader by increasing the tex coordinates each frame with this function:





// Offset the x texture coordinate delta units

vec2 rotate(vec2 coord, float delta)

{

coord.x -= delta;

if(coord.x < 0.0) coord.x = coord.x + 1.0; if(coord.x >= 1.0) coord.x = coord.x - 1.0;

return coord;

}




And then somewhere in the shader I do the following:





// Rotate surface textures in opposite directions



texCoord = rotate(inTexCoord, m_Time * m_Speed);

texCoord2 = rotate(inTexCoord, m_Time * -m_Speed);







Which results in the ground and the clouds (or whatever 2 diffuse textures you want to blend) rotating in opposite directions.



It is a very basic idea that I will probably drop sooner than later. I am leaning more and more on using some fractal terrain generation with DLOD, height maps and such. Some people here seems to be working on that field which may be a great help.





Anyway, current status and a dawn somewhere:

















Very neat!



By the way, how do you achieve the glowing effect of the sun?

The glow is the result of the atmospheric scattering equations implemented in the shader. These equations are approximations made by Sean O’Neil based on a physically accurate mathematical model (so that the resulting algorithm can be used in real time CG, otherwise it would be computationally too expensive).

oh ok! i thought there was another effect for the sun.

very good, keep up the good work.

looking freaking amazing. Just out of curiosity, the ground of the planet, is it being by the light? i would assume it is by the day/night side pictures, but on the day side it does seem kind of dark still for being morning/noon



altogether though this is an amazing project and i am loving it.

Yes I know what you mean. The ground scattering should reflect more light. The shaders have some tweakable parameters that may improve the result. I will add key inputs to the prototype to adjust these in runtime, the good thing is that you can get alienish atmospheres by playing with them.



Besides that, the lighting model is a bit custom, so to speak. The lighting resulting from the scattering effect is multiplied by an intensity factor based only on the vertex - eye - lightsource angle, which gives the final light/dark.



Maybe all it needs is to add specular lighting which is currently out of the picture.

You can checkout the JMP project:





svn checkout https://jme3-atmosphere-scattering.googlecode.com/svn/trunk/



Finally used that fantastic tool called Spacescape to setup a cubemap. Many thanks for the link.



There is a texture rotation effect in the shaders that may be removed easily (since it is not part of the atmosphere scattering itself, and more an addition of my own). This effect is particularly useless if you plan to generate terrain proceduraly with DLOD and heightmaps and such.



Let me know any suggestions or improvements. Enjoy :).





PS: Looking forward procedural terrain and texture generation.

thanks very much for this. i checked it out of the repository. in the future i will be using/adding to this idea extensively

Somehow I have problems checking this out via svn, it stalls when downloading the world.topo.bathy jpg file :confused:



Edit: Got it to work via https… and its great :slight_smile: