Rotate the sky

I’m trying to rotate the sky box. Unfortunately, setLocalRotation on spatial returned by SkyFactor seems to have no effect. This is probably because the Sky shader is not taking model transform into account ?



Is there anyway to rotate the sky around the scene with current shader, or should I write my own based on that ?

1 Like

Appriciate the solution.

Will use it too later :slight_smile:

1 Like

Have you figure out how to do this?(I’m a noob)

1 Like

Humm…

Im also intrested in the answer on this.



I think that it might be possible, if you made a texture for a sphere. The sphere can be 1m in radius, doesnt have to even be able to contain your character/world.

Then attach the sphere to the guinode and do:

sphere.setQueueBucket(Bucket.Sky);



I havn’t tried it directly, but as I was fixing some stuff I noticed that method.

Think it might work…

1 Like

Seems that following change is enough to get it rotating properly

[patch]

Index: src/core-data/Common/MatDefs/Misc/Sky.vert

===================================================================

— src/core-data/Common/MatDefs/Misc/Sky.vert (revision 7640)

+++ src/core-data/Common/MatDefs/Misc/Sky.vert (working copy)

@@ -20,5 +20,5 @@

pos.w = 1.0;

gl_Position = g_ProjectionMatrix * pos;

  • direction = normalize(inNormal * m_NormalScale);
  • direction = normalize(inNormal * m_NormalScale * g_NormalMatrix);

    }

    [/patch]

    You can replace middle of TestSkyLoading.java with following code to see it in action

    [java]

    private Spatial sky;

    public void simpleInitApp() {

    Texture west = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_west.jpg”);

    Texture east = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_east.jpg”);

    Texture north = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_north.jpg”);

    Texture south = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_south.jpg”);

    Texture up = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_up.jpg”);

    Texture down = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_down.jpg”);

    this.sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down);

    rootNode.attachChild(sky);

    }

    float counter = 0;

    @Override

    public void simpleUpdate(float tpf) {

    counter += tpf/10;

    sky.setLocalRotation(new Quaternion(new float[]{0,counter,0}));

    }

    [/java]



    Edit: Scratch that, while sky is rotating nicely, it gets crazy when you start to look around. I’m probably missing another element somewhere.
1 Like

The normal matrix is both the world and view matrices combined … While you want only the world matrix

1 Like

Thanks Momoko - this solved the strange rotation problem when the camera was not straight ahead. I never really internalized all those view/projection matrices - I prefer fragment shaders and playing with colors/textures…



Anyway, new ‘solution’ is



[patch]

Index: src/core-data/Common/MatDefs/Misc/Sky.j3md

===================================================================

— src/core-data/Common/MatDefs/Misc/Sky.j3md (revision 7640)

+++ src/core-data/Common/MatDefs/Misc/Sky.j3md (working copy)

@@ -16,6 +16,7 @@

NormalMatrix

ViewMatrix

ProjectionMatrix

  •        WorldMatrix<br />
    

}



Defines {

Index: src/core-data/Common/MatDefs/Misc/Sky.vert

===================================================================

— src/core-data/Common/MatDefs/Misc/Sky.vert (revision 7640)

+++ src/core-data/Common/MatDefs/Misc/Sky.vert (working copy)

@@ -1,6 +1,7 @@

uniform mat4 g_ViewMatrix;

uniform mat4 g_ProjectionMatrix;

uniform mat3 g_NormalMatrix;

+uniform mat4 g_WorldMatrix;



uniform vec3 m_NormalScale;



@@ -20,5 +21,6 @@

pos.w = 1.0;

gl_Position = g_ProjectionMatrix * pos;


  • direction = normalize(inNormal * m_NormalScale);
  • vec4 normal = vec4(inNormal * m_NormalScale, 0.0);
  • direction = normalize((normal*g_WorldMatrix).xyz);

    }

    [/patch]



    BTW, What normal scale is used for? I was able to flip some coordinates around by changing it to -1 for xyz, but what was the original idea behind?
1 Like

Would it be possible to see that fix included in an ulterior nightly build?

I mentioned my problem is another thread:

It so happens that changed the axis system and I now I need to rotate the skydome by 90 degree around the x-axis.
(The ‘top’ of the sky is currently at the horizon)

Unfortunately, using the normalScale seems to only allow me to reflect across axises.
1 Like