How to copy a cubemap into a cubemapArray-Asset (DirectX11) with Graphics.CopyTexture

In the documentation it says:

“Cubemap arrays do not have an import pipeline for them, and must be created from code, either at runtime or in editor scripts. Using Graphics.CopyTexture is useful for fast copying of pixel data from regular Cubemap textures into elements of a cubemap array. From editor scripts, a common way of creating serialized cubemap array is to create it, fill with data (either via Graphics.CopyTexture from regular cubemaps, or via SetPixels or SetPixels32) and save it as an asset via AssetDatabase.CreateAsset.”

But I don’t succeed in copying a cubemap into a cubemapArray, it just remains black. Is this function working with these parameters for cubemap to cubemap-Array?

mipmapLevel = 0;
slice = 0;
Graphics.CopyTexture(myCubeMap, 0, mipmapLevel, myCubeMapArray, slice, mipmapLevel);

Hey,

Firstly you haven’t specified a platform, so I would run SystemInfo.supportsCubemapArrayTextures to be sure they’re available:

Have you populated your cubemap array with placeholder cubemap faces?

What texture format are you using for the textures inside your cubemap? (TextureFormat.ARGB32, RenderTextureFormat.ARGB32 etc…)?

Are you using https://docs.unity3d.com/ScriptReference/Texture2D-mipmapCount.html to calculate the mip map level for your textures?

I hope this helps.

Andy

Hi Andy,

thanks for your answer.
My platform is Windows 7 on DirectX11, I have run
SystemInfo.supportsCubemapArrayTextures and yes, the system supports CubeArraytextures.

I use for the test TextureFormat.RGBAHalf, but I would like to use TextureFormat.BC6H in the end, because the prerendered cubemaps (created with Vray in 3DStudioMax) are .hdr-textures. The layout is 6 faces side by side.

I have not used Texture2D-mipmapCount yet, since I am very close to my cubemap and should only see the first mipmaplevel.

I have used Graphics.CopyTexture( loadedTexture, b, 0, textureArray, b, 0);

I could post the complete code if necessary.

Could you give me a feedback?

Thanks Robert

P.S.: So here is an extract of the code:

path = "Assets/Resources/ReflectionMaps/";
loadedTexture = AssetDatabase.LoadAssetAtPath( path + "reflectionMap.asset", typeof(Cubemap) );
dim = 256;
textureArray = CubemapArray(dim, 1, TextureFormat.RGBAHalf, true, true);
Graphics.CopyTexture( loadedTexture, b, 0, texArray, b, 0);
texArray.Apply( false, false );
AssetDatabase.CreateAsset(texArray, "Assets/Resources/reflectionMaps/reflectionMapsArray.asset");
AssetDatabase.SaveAssets();

Hmm, no answer yet.
I have managed to create cube Arrays per Script, and it works fine with get/setPixels, but not with Graphics.CopyTexture. The latter works in the viewport, but not when I try to save the array as asset, it will remain black. Any idea why? I need to use Graphics.CopyTexture because I would like to use BC6H-format.

Here is a sample of the code:

cubeArray = CubemapArray(dim, hdrTexturesNames.Count, textureFormat, true, true); //mipmap bool, linear bool
AssetDatabase.CreateAsset(cubeArray, "Assets/Resources/reflectionMaps/" + "reflectionMapsArray.asset");

for (var a = 0; a < hdrTexturesNames.Count; a++)
{
	cubeMapAsset = AssetDatabase.LoadAssetAtPath( path + hdrTexturesNames[a] + ".hdr", Cubemap ) as Cubemap;
	miplevels = cubeMapAsset.mipmapCount;
	for (var f = 0; f < 6; f ++)
	{
		for (var b = 0; b < (miplevels - 2); b++) //the last two levels don't work because the minimum pixel dim is 4 for BC6H
		{
			texWidth = dim / Mathf.Pow(2,b);

			Graphics.CopyTexture(cubeMapAsset, f, b, 0, 0, texWidth, texWidth, cubeArray, (f + 6 * a), b, 0, 0);
		}
	}
}

AssetDatabase.SaveAssets();