#Custom Skybox

1 messages · Page 1 of 1 (latest)

rapid hull
#

So, this is my try:

// Load textures from the mod folder
posX = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_PositiveY.dds");
posY = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_PositiveY.dds");
posZ = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_PositiveZ.dds");
negX = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_NegativeX.dds");
negY = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_NegativeY.dds");
negZ = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_NegativeZ.dds");
#
// As you can see, the mainTexture is a Cubemap.
var cubemap = (Cubemap) o.skyboxGalaxy.mainTexture;
// I create a new cube with the same format. I can't modify the existent cubemap because is not readable.
var myCube = new Cubemap(posX.width, cubemap.format, false);

// This is just to convert the format of the Textures to cubemap.format
Texture2D newPosX = new Texture2D(posX.width, posX.height, cubemap.format, false);
newPosX.SetPixelData<Byte>(posX.GetPixelData<Byte>(0), 0);
newPosX.Apply();
Texture2D newPosY = new Texture2D(posX.width, posX.height, cubemap.format, false);
newPosY.SetPixelData<Byte>(posY.GetPixelData<Byte>(0), 0);
newPosY.Apply();
Texture2D newPosZ = new Texture2D(posX.width, posX.height, cubemap.format, false);
newPosZ.SetPixelData<Byte>(posZ.GetPixelData<Byte>(0), 0);
newPosZ.Apply();
Texture2D newNegX = new Texture2D(posX.width, posX.height, cubemap.format, false);
newNegX.SetPixelData<Byte>(negX.GetPixelData<Byte>(0), 0);
Texture2D newNegY = new Texture2D(posX.width, posX.height, cubemap.format, false);
newNegY.SetPixelData<Byte>(negY.GetPixelData<Byte>(0), 0);
newNegY.Apply();
Texture2D newNegZ = new Texture2D(posX.width, posX.height, cubemap.format, false);
newNegZ.SetPixelData<Byte>(negZ.GetPixelData<Byte>(0), 0);
newNegZ.Apply();
#
// I replace the texture, and call the method o.Init() to reset the skybox initialization.
o.skyboxGalaxy.mainTexture = myCube;
o.Init();
#

This is the result

#

I was messing around until I found the error, SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D> wasn't loading properly the files, I then decided to convert these images to .PNG

// Load textures from the mod folder
posX = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_PositiveY.png");
posY = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_PositiveY.png");
posZ = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_PositiveZ.png");
negX = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_NegativeX.png");
negY = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_NegativeY.png");
negZ = SpaceWarp.API.Assets.AssetManager.GetAsset<Texture2D>("MODID/images/GalaxyTex_NegativeZ.png");

This time with promising results, but, as you can see, the resulting cubemap is literally a cube.

rapid hull