jme3 dynamic skydome

Hi,

I’ve looked for dynamic sky domes but only found some for jme2 or 1, but not 3. I hope this doesn’t already exists, but in the meantime I’ve found an implementation that I liked a lot. Here is a link to the tutorial with sources:

http://csc.lsu.edu/~kooima/misc/cs594/final/index.html





So I’ve started to implement it in jme3. At first I had the good surprise to setup the basic shader pipeline without much pain. But I’m finally hitting an issue. This is visible on the sky shader. I suspect it has something to do with either some scaling or some matrix transformation in the shader. (i believe that the DirectionalLight is pointing at the right direction and the sun billboard is on the right position)

So, if you don’t move the camera this is almost fine ( some issue though ). If you start to move the camera the sky color begin to have a lot of errors.





You can access the source code here: GitHub - idflood/jmeDayNight: A dynamig sky system for jme3 (jmonkey engine)





Here some relevant code part:

DynamicSun.java


void updateTime() {
skyGeom.setLocalTranslation(viewPort.getCamera().getLocation());
sunSystem.updateSunPosition(0, 0, 30); // increment by 30 seconds
lightDir = sunSystem.getPosition();
sunLight.setDirection(lightDir.normalize());
updateLightPosition();
sunDiscGeom.setLocalTranslation(lightPosition.mult(0.95f));
}
protected void updateLightPosition(){
lightPosition = getLightPosition();
getClipCoordinates(lightPosition, screenLightPos, viewPort.getCamera());
viewPort.getCamera().getViewMatrix().mult(lightPosition, viewLightPos);
skyMaterial.setVector3("lightPosition", screenLightPos);
}
protected Vector3f getLightPosition(){
return lightDir.multLocal(scaling * -1);
}

dynamic_sky.frag

uniform sampler2D m_glow_texture;
uniform sampler2D m_color_texture;
uniform vec3 m_lightPosition;
varying vec3 vertex;
void main()
{
vec3 V = normalize(vertex);
vec3 L = normalize(m_lightPosition.xyz);
// Compute the proximity of this fragment to the sun.
float vl = dot(V, L);
// Look up the sky color and glow colors.
vec4 Kc = texture2D(m_color_texture, vec2((L.y + 1.0) / 2.0, V.y));
vec4 Kg = texture2D(m_glow_texture, vec2((L.y + 1.0) / 2.0, vl));
// Combine the color and glow giving the pixel value.
gl_FragColor = vec4(Kc.rgb + Kg.rgb * Kg.a / 2.0, Kc.a);
}

dynamic_sky.vert

uniform mat4 g_ViewMatrix;
uniform mat4 g_ProjectionMatrix;
uniform mat4 g_WorldMatrix;
attribute vec3 inPosition;
varying vec3 vertex;
void main()
{
vertex = inPosition.xyz;
vec4 pos = vec4(inPosition, 0.0);
pos = g_ViewMatrix * pos;
pos.w = 1.0;
gl_Position = g_ProjectionMatrix * pos;
//gl_Position = ftransform(); (this was in the sample)
}
3 Likes

Cool! It would be nice if you could make it a pluggable library for jMP so people can find and install this via the update center:

development :: jMonkeyEngine Docs

Creating an extension library plugin :: jMonkeyEngine Docs

normen said:
Cool! It would be nice if you could make it a pluggable library for jMP so people can find and install this via the update center:
https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:development
https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:development:extension_library

That would be great. However I'm just beginning with jmonkey so this may take some time. But anybody can join in for the development, just ask for commit access or fork. The more help, the fastest/better it will be ; )

oh this is nice, hope you dont mind if i steal it :stuck_out_tongue: i was thinking of just having a large cube set on the zbuffer, but this makes it a whoie lot easier :smiley: thank you

Yes, I fixed the sky issue this morning. Now comes the fun part of adding features/refactoring : )

So, on the refactoring topic, any recommendation of the global class structure for this? I’ve some ideas but I’m not that familiar with game engine coding, so any advice would be great.





edit:

ryuu said:
oh this is nice, hope you dont mind if i steal it :P i was thinking of just having a large cube set on the zbuffer, but this makes it a whoie lot easier :D thank you

Sure, no problem :)


edit2: I've started to add stars (still buggy). I will not touch the sources for the week-end, so feel free to fork the repository.