Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

create cubemap on real time

Discussion in 'Scripting' started by nafasso, Jun 15, 2015.

  1. nafasso

    nafasso

    Joined:
    Dec 3, 2013
    Posts:
    22
    Hello,

    first of all excuse me if my english is not perfect but I am not a native speaker so please let me know if you do not get something.

    So here is my concern:
    I am creating a cubemap thanks to a camera and I display this cubemap in a cube which has a camera inside too.
    I am using the script in the doc which uses the RenderToCubemap function.
    So as the first camera used to create the cubemap is actually a first person character, it can move so I am updating the cubemap each frame so the cube texture can be up to date.
    BUT to check if everything was working well I splitted my screen so I can see through the player camera and the cube camera at the same time. So as I walk with the player in my scene, the texture is updated well but the updating is not fluent. What I mean is that you can see that it is updated and I would like it to appear fluent.
    I don't think it is because of the computer because the player view is perfectly fluent and the PC is not working so much. I just wonder if the function RenderToCubemap is really good for runtime ?
    If somebody has any advices to help me with that ...

    Thank you for your time
     
  2. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Make sure you RenderToCubemap in late update, after your movement calculations are complete. Otherwise the cubemap will always appear to be "one frame behind".

    Just taking a guess based on the problem you described.
     
  3. nafasso

    nafasso

    Joined:
    Dec 3, 2013
    Posts:
    22
    Hello,

    first of all thank you for your quick answer.
    Actually I took the script of the doc and I adapted it to my project by adding some modifications so the RenderToCubemap is called in the late update.
    I ran some tests and it appears to be much more fluent if I render less faces so my idea was maybe to render only the faces in the frustrum of the camera but as the camera can rotate according to the mouse look I need to make it dynamic.

    Do you think I can do that by using raycasts ?
    I also did not really understand how the facemask works. Actually I did not find any indication on which number represents which face of the cube. So for now I use (int) CubemapFace.PositiveX for example but to render more than on face I don't know how to do it by calling the function only once because the addition of those (int) CubemapFace does not seem to work. I tried to log the int representing the faces in the console but for example PositiveX seems to be represented by 0 and when I try to call the function by putting directly 0 instead of (int) CubemapFace.PositiveX it does not seem to work.
    Would you have any idea of how to solve this ?

    EDIT: actually I just ran some other tests and it appears that none of positive faces work. What I mean is that when I call UpdateCubemap ((int)CubemapFace.PositiveX); nothing is displayed, every faces of my cube remain dark but UpdateCubemap ((int)CubemapFace.NegativeX); works perfectly fine for its corresponding face. Same thing for Y and Z faces. Does somebody know about this ? Am I missing something ?

    EDIT2: ok so I tried more and I found that the lines which decide how many faces to display are
    Code (CSharp):
    1. int faceToRender = Time.frameCount % 6;
    2. int faceMask = 1 << faceToRender;
    3. UpdateCubemap (faceMask);
    apparently if I change this 6 by 5, it renders 5 faces but I do not really understand this process so if somebody can help me on this ...
    Also what I noticed it actually I think there is no performance issue, it is just the junction of the faces which become visible when there is movement. What I mean is when there is no moving object in the image displayed on the cube, everything is perfect but when there is a moving object or if the camera is moving then we can see the angles of the cube and the faces seems not to be refreshed at the same time so this might be a sync issue.
    Any idea on how this could be solve or at least improved ?
     
    Last edited: Jun 16, 2015