• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Robert1977 · Feb 01, 2017 at 07:34 PM · scripting problemscript.arraysgraphic

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);
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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();



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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();
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MeessenPhilips · Apr 05, 2019 at 02:25 PM 0
Share

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.

avatar image Robert1977 MeessenPhilips · Apr 05, 2019 at 02:31 PM 0
Share

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.

avatar image MeessenPhilips Robert1977 · Apr 05, 2019 at 02:49 PM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Opening Door pressing a key (keyboard or pad) 1 Answer

Solved how to get half the collider of a box2d or capsulecollider2D 0 Answers

Script to get Eye Material to move only seems to work in Inspector/Edit Mode 0 Answers

Collision script doesnt work,OnCollisonEnter2D does not work if it collides with the enemy 2 Answers

Cannot create new C# Script Assets, and files with meta data are missing 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges