Skybox rotation Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75
Contact:

Skybox rotation

Post by TaaTT4 »

To render the skybox, I use the same technique that OGRE uses in its sample Sample_TutorialSky_Postprocess. As the title says, I'm wondering if there's an easy way to apply a rotation (to make things simpler: just a yaw around the world y axis) to the skybox.
I know I can simply apply a counter-rotation to the objects, but doing this creates a mess with the AABB visualization.

Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Skybox rotation

Post by xrgo »

should be something like this (SkyPostprocess_vs.glsl):

Code: Select all

    outVs.cameraDir.xyz = normal.xyz;

    float radian = 3.14; //whatever, maybe pass through uniform
    float s = sin(radian);
    float c = cos(radian);
    mat2 m = mat2(c, -s, s, c);

    outVs.cameraDir.xz = m * outVs.cameraDir.xz;
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Skybox rotation

Post by dark_sylinc »

If you want an arbitrary rotation, convert the quaternion to a Matrix3 and then send it to the shader:

Code: Select all

uniform float3x3 rotation;
....
//GLSL
outVs.cameraDir.xyz = (rotation * normal.xyz);
//HLSL
outVs.cameraDir.xyz = mul(rotation, normal.xyz);
I don't know if you need to swap the multiplication order though (i.e. try float3 * float3x3 if float3x3 * float3 doesn't work as intended or rotates in the opposite direction).

xrgo's answer works on rotating with 2 axes by using a float2x2, instead of 3 axis; but is basically the same concept.
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75
Contact:

Re: Skybox rotation

Post by TaaTT4 »

dark_sylinc wrote: Mon Mar 04, 2019 8:43 pm If you want an arbitrary rotation, convert the quaternion to a Matrix3 and then send it to the shader:

Code: Select all

uniform float3x3 rotation;
....
//GLSL
outVs.cameraDir.xyz = (rotation * normal.xyz);
//HLSL
outVs.cameraDir.xyz = mul(rotation, normal.xyz);
I don't know if you need to swap the multiplication order though (i.e. try float3 * float3x3 if float3x3 * float3 doesn't work as intended or rotates in the opposite direction).
Yep, I had thought about using a rotation matrix in the vertex shader. Correct multiplication order is float3x3 * float3.

Thanks guys!

Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

Post Reply