- Home /
Easiest way to rotate a cubemap?
Unity's automatic texture importer cubemap generation is quite handy, but it produces cubemaps that are 90 degrees off of the direction I need them to face.
I used an editorscript to apply to cubemaps to a skybox, create a rotated camera, and render the skybox to a new cubemap, but the new cubemap's rotation is the same as the old one.
I would love to use the rendering approach, as it will allow me to bake in a tint as well. Any ideas why it isn't working?
Answer by coastwise · Apr 04, 2011 at 01:27 PM
I just figured out how to rotate a skybox for my own purposes, check this out:
Create a copy of the built in skybox cubed.shader
and rename it (available from here).
Change line one to have the name "Rotated Skybox Cubed" (or whatever)
At about line 23 add: uniform float4x4 _Rotation;
Modify the vert function (around line 35) to the following:
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(_Rotation, v.vertex);
o.vertex = mul(UNITY_MATRIX_MVP, o.vertex);
o.texcoord = v.texcoord;
return o;
}
Create a C# script called RotateSkybox like so:
using UnityEngine;
[RequireComponent(typeof(Skybox))] public class RotateSkybox : MonoBehaviour {
void Start () {
// Construct a rotation matrix and set it for the shader
Quaternion rot = Quaternion.Euler (60f, 0f, 0f);
Matrix4x4 m = Matrix4x4.TRS (Vector3.zero, rot, new Vector3(1,1,1) );
GetComponent<Skybox>().material.SetMatrix ("_Rotation", m);
}
}
Slap that baby on your camera and you're laughin! (hopefully)
Note: I've simply hardcoded the rotation I needed into the RotateSkybox script as rot
, from you're description you'd either want +/- 90 in the y component instead.
Answer by videep · Nov 20, 2014 at 01:26 PM
Please follow the links for a tutorial on rotating the cubemap in any axis as per users convenience. http://themaxscriptguy.wordpress.com/2014/11/20/rotating-cubemap-in-unity/ https://github.com/theMaxscriptGuy/Unity_Dev/tree/master/CubeMap_Rotation
Your answer
Follow this Question
Related Questions
Setting cubemap faces as rendertexture 0 Answers
Rendering a G-Buffer for a cubemap 0 Answers
forcing texture resolution? 1 Answer
Cubemap render faces 1 Answer
Projecting camera view on to a right angled surface 1 Answer