Search Unity

Using Render Textures To Create a Cubemap

Discussion in 'Scripting' started by Major, Aug 14, 2015.

  1. Major

    Major

    Joined:
    Jul 26, 2012
    Posts:
    69
    I want to use a render texture that I have created in a script as a cube map. It follows the horizontal format where each side is lined up all on the same level. The sides go X+, X-, Y+, Y-, Z+, Z-. However I can't assign this to my material that is using a cube map. I get the error that really doesn't make sense to me:

    RenderTexture.Create failed: cube maps must be power of two and width must match height

    If I export my rendered cubemap and then re-import it as a normal texture and do the cube map setup it does work as intended. However I don't want to do it this way because the conversion from render texture to Texture2D takes a very long time and I want this cubemap to be dynamic and capable of changing within a short amount of time.

    What would be the best way of going about this?
     
    Last edited: Aug 15, 2015
  2. Major

    Major

    Joined:
    Jul 26, 2012
    Posts:
    69
    bump
     
  3. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Sounds like you're generating the faces manually. The simplest method to do this is to make a new rendertexture with power of 2 width and height, then add myrendertexture.isPowerOf2 = true;
    myrendertexture.isCubemap = true;
    mycamera.RenderToCubemap (myrendertexture);
    myrendertexture.Create();
    No need to even touch Texture2D and it's fast enough to do in real time.
     
  4. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Just curious: couldn't you just use a reflection probe for that and update it as often as you want?