Skybox rotation Topic is solved

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 165
Joined: Wed Apr 23, 2014 3:49 pm
x 16

Skybox rotation

Post by TaaTT4 » Mon Mar 04, 2019 7:03 pm

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.
0 x
Senior game programmer at Vae Victis
Working on Racecraft

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

Re: Skybox rotation

Post by xrgo » Mon Mar 04, 2019 8:04 pm

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;
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4077
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 231
Contact:

Re: Skybox rotation

Post by dark_sylinc » 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).

xrgo's answer works on rotating with 2 axes by using a float2x2, instead of 3 axis; but is basically the same concept.
0 x

User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 165
Joined: Wed Apr 23, 2014 3:49 pm
x 16

Re: Skybox rotation

Post by TaaTT4 » Tue Mar 05, 2019 11:01 am

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!
0 x
Senior game programmer at Vae Victis
Working on Racecraft

Post Reply