I have a script that dynamically loads a cubemap face from a set of textures using the SetPixels method as shown below. I am using 24-bit RGB textures with their read/write flag set.
The script works, though the results are very different to what I see when I manually select cubemap faces through the editor (even if I select the same texture as my script). The cubemap generated by the script is either completely corrupt or all the faces are upside down. Is there an additional conversion step the editor is doing I can do in my script?
public class ReloadCubeMap : MonoBehaviour {
public Cubemap cm;
public Texture2D top;
public Texture2D bottom;
public Texture2D front;
public Texture2D back;
public Texture2D left;
public Texture2D right;
void OnGUI() {
if (Event.current.Equals(Event.KeyboardEvent("r")))
{
Color[] faceColors;
faceColors = top.GetPixels();
cm.SetPixels(faceColors, CubemapFace.PositiveY);
faceColors = bottom.GetPixels();
cm.SetPixels(faceColors, CubemapFace.NegativeY);
faceColors = front.GetPixels();
cm.SetPixels(faceColors, CubemapFace.PositiveZ);
faceColors = back.GetPixels();
cm.SetPixels(faceColors, CubemapFace.NegativeZ);
faceColors = right.GetPixels();
cm.SetPixels(faceColors, CubemapFace.PositiveX);
faceColors = left.GetPixels();
cm.SetPixels(faceColors, CubemapFace.NegativeX);
cm.Apply();
}
}
}