i tried to implement Sean Oneils Atmospheric Scattering from GPUGems 2 by porting the c-code to JME / Java Code.
It works suboptimal, there are different problems.
I think the biggest problem is that there are some uniforms not found in the shaders:
SCHWERWIEGEND: Shader uniform [fInnerRadius2] could not be located in shader
24.07.2008 19:44:46 com.jme.scene.state.lwjgl.shader.LWJGLShaderUtil updateUniformLocation
SCHWERWIEGEND: Shader uniform [fCameraHeight] could not be located in shader
But these vars are defined in the shaders.
Also the shaders create heavy artefacts. Dont know where they come from. ONeil wrote in a gamasutra that his shaders are for HDR Rendering, he renders in his source to a texture of a cameraaligned quad and does some HDR-Magic in another shader. But i dont think that this solves such artifacts....
Also there are artifacts resulting from the geometries.
If you run the provided code, press "8" to set all uniforms - then the rendering "works". Without hitting 8 only the uniforms which can be found are send to the shaders - but then they arent working.
Some Links:
http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html
http://sponeil.net/index.htm
http://www.gamedev.net/reference/articles/article2093.asp
These two shaders are quite different. For one, the above mentioned doesn't look nearly as good as the one in this thread (except for the artefacts ;)) and it can render the atmosphere from the inside too :D. Unfortunately, I'm not that familiar with shaders and cant help you here, but be assured that i will come back and take the finished shader and use the hell out of it. :evil:
EDIT: I did have quite the same artefacts with the other shader (link above) at first because i forgot the CullStates (front and backside were rendered into each other and resulted in those ugly lines). so that may be it.
Thanks for the tip, now a part of the artefacts are gone.
Inserted an CullState.setFace(Face.Back); at line 321 at above code.
Now it looks better:
Old:
New:
But the artefacts inside the atmosphere are the same. ONeil mentioned that Nvidia Cards produce more artefacts than ATI cards because of accuracy…
I’ll try to implement his HDR shader, perhaps this will help.
The biggest negative point of these shaders is, that the radius of the ground and the atmosphere have to be 1:1.025 because of the functions are optimized for this in the shaders.
The reason why there were the artefacts is my nvidida card.
In the atmopshere vertex shader, the colors of the vertices arent calculated in range of [0-1]. And Nvidia cards clamp the gl_FrontColor, which is later used in the fragmentshader, to [0-1] so there is an information loss. Now i am passing the new colors through my own vectors to the fragmentshader.
I have no clue, if this is bad, e.g. for performance or compatibility for older cards or ATI… but the artefacts are gone.
I read the mentioned pages in the thread already before i found the thread, searched the internet for hours for shader implementations. Didn’t find anything, so tried to implement Oneal’s shaders. But these shaders are a mess. Variables in the source which aren’t used in the shaders, different implementations from gpu gems and his hompage…
@Mr Coder: Did you write the shaders yourself? Are u thinking about sharing your code?
Maybe he could not locate the shaders. They are loaded by class.getClassLoader().getResource(string), the shaders have to be located (if you dont change the source) in the same directory like the ONeilPlanetgame class in a subfolder called “homepage”, like “homepage/Shader.name”.
My structure is:
| - bin / OneilPlanetGame.class
| bin / homepage / GroundFromAtmosphereFrag.glsl
| bin / homepage / The.Other.Shaders…
| bin / earth.jpg
|
| - src / OneilPlanetGame.class
| src / homepage / GroundFromAtmosphereFrag.glsl
| src / homepage / The.Other.Shaders…
| src / earth.jpg
I made a package where you can click run.bat for windows and a run.sh for linux (linux not tested)
Got it to run on my other comp which has an NVidia card.
However I did notice some ripping across the top part of the screen when in full screen mode… It did not happen when I was running at native resolution… when I set the resolution lower, then it happened occasionally. No ripping was noticed in windowed mode… I guess its a driver problem as I could not resize the image correctly?
In general it run very smoothly, there were only some artifacts when I mouse-looked around… it could not render the planet fast enough I guess… as I could see squares out of alignment with the rest of the planet… (could not screenshot it… looked fine on the images) Nothing like this when moving though.
not that when you have performance problems with that kind of shader, you can always try to create the geometry that the shader is applied to with less details. in this case that means that the performance greatly increases when you create the planet sphere with less samples.
i just tried it and it looks great on my nvidia geforce go 7900 gs (despite the artifacts around the sun when seen from space).
however, there are two things that make it useless the way it is now:
the atmosphere is drawn over everything else in the scene, even the black parts. so when i add a moon, for instance, it is not visible when seen through the atmosphere.
the shaders seem to depend on the translation, scale and rotation of the planet and its atmosphere, so when i change any of these, it looks ugly.