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)
}