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);
Answer by AndyJenkins30 · Apr 26, 2017 at 12:54 PM
Hey,
Firstly you haven't specified a platform, so I would run SystemInfo.supportsCubemapArrayTextures to be sure they're available: https://docs.unity3d.com/ScriptReference/SystemInfo-supportsCubemapArrayTextures.html
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
Answer by Robert1977 · Apr 28, 2017 at 03:24 PM
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();
Answer by RobertRe · Jan 25, 2018 at 03:13 PM
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();
Did you eventually get it to work with Graphics.CopyTexture? I have the same problem. SetPixels works, but then the source needs to have read/write enabled, which I don't want. Also I can't use the desired texture format because of it.
No, unfortunately not. Graphics.copytexture just worked at runtime, but not when i wanted to store the cubemaparrays as assets permanently. which is strange, because it works with Texture2DArrays. Set Pixels, as you said, doesn't allow to use a compressed format like BC6H, which is sad.
Thanks for your quick response on this old thread. $$anonymous$$y it still doesn't work, looks like I won't be able to use cubemap arrays.
Your answer
Follow this Question
Related Questions
Get Public Methods from MonoScript 4 Answers
can i get help please 0 Answers
I create material with script but it does not render right 0 Answers
I want my script to wait 2 seconds before continue in a condition, in update, using C# 2 Answers
Invoking a Function From A Variblized Script And Object 1 Answer