Search Unity

Thumbnail shows a corner of the screen area.

Discussion in 'Unity Everyplay' started by JeffersonTD, Apr 25, 2015.

  1. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    In general the Everyplay integration seems to work very easily out of the box. The thumbnail creation also works easily in principle, but I'm having one problem with that. For some reason that screenshot thumbnail shows just the lower left corner of the screen area. What I would like to have is take the screenshot from the middle area of the screen. I've tried using the pixel manipulation methods of Texture2D to do this, but as the texture only has the lower area, that probably doesn't help.

    Any idea as to why I'm getting the lower left area of the screen instead of the full screen and any idea how to change this so that I'd get the middle area?
     
  2. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Are you using texture or file based thumbnail? If using texture based, are you using NPOT (none power of two) texture or POT? If using NPOT, try if you get same result with POT textures.
     
    JeffersonTD likes this.
  3. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Thanks for the reply. I'm using a texture. It should be POT as I'm instantiating the texture simply by
    new Texture2D (256, 256);
    I then give that texture as a target for the thumbnails. After taking the thumbnail, I assign that target texture to the material I'm using, the result being what I think is actually the lower left quarter aka 1/4 of the whole screen area (using iPhone5).
     
  4. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Weird. Are you sure you haven't changed the material tiling from 1/1 to something else? Are you using the SetThumbnailTargetTextureId(int textureId) or SetThumbnailTargetTexture(Texture2D texture) to set the texture? If you are using the former, you must also set the texture width/height using SetThumbnailTargetTextureWidth(int textureWidth) and SetThumbnailTargetTextureHeight(int textureHeight).

    ps. just tested with iPhone 5 and the latest Everyplay but for me the thumbnail contained the whole screen like supposed to
     
    Last edited: May 3, 2015
  5. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Thanks for the tip! I have a 1/1 tiling and regarding the methods, isn't it actually the opposite: SetThumbnailTargetTexture wouldn't require setting the width? At least the code annotations say:

    Code (csharp):
    1.  
    2. [Obsolete("Defining texture width is no longer required when SetThumbnailTargetTexture(Texture2D texture) is used.")]
    3.     public static void SetThumbnailTargetTextureWidth(int textureWidth)

    I now tried a little bit differently by directly assigning the texture I want like this:

    Code (csharp):
    1. Everyplay.SetThumbnailTargetTexture((Texture2D)myMaterial.mainTexture);
    but that didn't seem to work at all. The way I get the one quarter screen in the thumbnail is like this:

    Code (csharp):
    1. thumbnailTexture = new Texture2D(100,100);
    2. Everyplay.SetThumbnailTargetTexture(thumbnailTexture);
    3. Everyplay.TakeThumbnail ();
    4. videoThumbnailMaterial.mainTexture = thumbnailTexture;
    Is there something wrong in the way I assign the material?
     
    Last edited: May 2, 2015
  6. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Hmh, there's something weird going on with this. For some reason when I change the camera angle in the game (by tilting the device) that thumbnail image incrementally disappears and shows the original texture instead! So not only is the thumbnail only a quarter of the screen, it somehow still preserves the original texture in the same material simultaneously? :confused: Here's a cropped shot of the situation where the angle is about 45 degrees. The darker areas on the top and left are the original material and the green and yellow come from the thumbnail. If I tilt it all the way (device to portrait position),the thumbnail shot isn't shown at all, and when I tilt it back (to landscape position) the thumbnail image is shown again.
     
  7. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Yes, meant former, not latter. :)

    The way you set the reference is just right. However are you really calling TakeThumbnail at the same time you initialize the texture? At least for performance reasons you should create the texture and set the thumbnail texture in Awake or Start instead. Then call TakeThumbnail at some point during recording.
     
    Last edited: May 4, 2015
    JeffersonTD likes this.
  8. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    No, I'm not calling them at the same time. I just wrote the principle flow there like that. In reality the first two rows (thumbnailTexture initialization and setting the target texture) are called only once, and the latter two every time I take a thumbnail.

    I wonder why it's not getting the full screen there. :/ The same thing happens on iPad mini too. And due to my other problem ( see http://forum.unity3d.com/threads/problem-building-for-ios-after-fb-integration.323169/ ) I'm having trouble debugging the problem on the device. And EveryPlay only works on the end device, so I can't really test in Unity either. :|
     
  9. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    I also have a secondary problem related to this. If I try to get a certain part of the picture with getPixels / setPixels or getPixel / setPixel like this:

    Code (csharp):
    1. newTexture.SetPixel (x, y, orig.GetPixel (startPointX + x, startPointY + y));
    I always end up with plain gray. Setting my own hardcoded colour or using some other texture for getPixel works fine, but for some reason not the thumbnailTexture.
     
  10. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Not 100% sure but this is probably caused by Everyplay rendering the thumbnail directly to the memory address on the GPU and GetPixel probably just gets the pixels from the texture data duplicate that is not on the GPU. Unfortunately I don't see a way to get around this with Unity Indie but with Unity Pro or 5.x you should be able to blit the thumbnail to a render texture with Graphics.Blit and set the source offset/tiling to the material used for blitting.
     
  11. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Thanks for clearing that out! Having read your comment I realized that I probably would not need the read/set pixels for what I'm trying to do: texture scaling and offsetting would allow me to reach the same goal. Well, it did, although there's something weird about that too: why is it that setting scale to 2 causes the texture to go grey again, whereas scale 0.5 works fine? Normally both scales work fine.

    In any case I still have the primary problem, and testing with the offset sort of confirms that the rest of the screen is nowhere: by using the offset I see how the thumbnail image wraps back to the left edge at the point which should be only at the middle point of the screen. Any ideas what's up with this?

    And then there's also the tilt effect problem described a couple of posts ago ( ). Ideas regarding that? Do I have a problematic shader for this or something? I'm using Unlit/Texture.

    So problem summary:
    1. Getting only one quarter of the screen to the thumbnail.
    2. Having the screenshot incrementally disappear when rotating the camera.
    3. Showing only a specific part of the thumbnail. SOLVED

    I might be able to bare with problem 2, but unless a solution for 1 is found, I probably need to ditch the whole thumbnail, which would be a pity. It's just that a bad thumbnail is worse than having no thumbnail at all.
     
  12. surathunity3d

    surathunity3d

    Moderator

    Joined:
    Sep 30, 2014
    Posts:
    128
    Hi @JeffersonTD

    Kindly request you to send us a test case at support@everyplay.com for 1 & 2.
    Also, please mention the link to this thread as a reminder.
    You can upload the test case to DropBox, Google Drive, etc or if it is not too big attach it as a zip.

    This will help us to reproduce the issue and fix it faster.

    Cheers
    Surath
     
  13. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    I made a minimal test project for reproducing those issues, but sadly (for me) the only problem I was able to reproduce was something that only resembles problem 2. This problem only occurs in portrait mode: the thumbnail behaves weirdly by appearing entirely grey what appears to be a little bit more than half of the time. For maybe about 5% of the time the greyness is only partial and maybe 40% of the time you see the thumbnail as it should be seen. In any case the whole thing is blinking on and off very quickly as the angle of the quad changes. In landscape mode it works entirely fine, so if the problem is really just the portrait mode, that shouldn't be a problem for my game, which only supports landscape orientation.

    I could send you this test project to demonstrate the portrait mode greyness, if you want, but maybe not that much point doing that, as I wasn't able to reproduce the main issue there?

    Now I should just figure out what exactly makes my game project differ from this quick test project. What I do have different is that whereas my test project only has one camera in my game project I have multiple cameras (6 active ones), and even with different FOVs, but that shouldn't be a problem, right? I also have one 2D gui element in the game project, but that shouldn't affect anything either, right? And my game project supporting landscape right and landscape left but not the portrait orientations shouldn't be a problem either, right? Maybe I should test how my game project would behave if I were to allow the other two orientations...

    ...ed: okay, I tested allowing portrait orientation in the game. If playing in portrait mode it still takes the thumbnail as if the game was played in landscape mode. This means that playing in portrait mode I don't get the lower left corner but rather the UPPER left corner rotated to a 90 degree angle! So a step for the worse actually - and more importantly, it still didn't give me a clue as to why it only gives that quarter of the screen and why the test project doesn't have that problem. Ideas for what the effective difference could be related to?
     
    Last edited: May 4, 2015
  14. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Yes, when you use texture based thumbnail, the thumbnail will always be in landscape. This is actually for convenience since otherwise if the game supports multiple orientations you would need to recreate the thumbnail textures with different size every time the orientation changed. The ThumbnailTextureReadyDelegate(Texture2D texture, bool portrait) delegate method contains portrait boolean which will tell if the thumbnail is shot in portrait.

    So if the texture is portrait, you could a) create a new 90 degree rotated texture of the thumbnail b) rotate the the thumbnail ui item 90 degrees c) use a shader that rotates the uv 90 degrees. If it's not portrait, just show it like it is.

    You could define the thumbnail texture size like below. It takes the aspect ratio into account and also old devices that do not support NPOT textures:

    Code (CSharp):
    1. // My thumbnail landscape width
    2. int thumbnailWidth = 256;
    3.  
    4. // Thumbnails are always stored landscape in memory
    5. float aspectRatio = (float)Mathf.Min(Screen.width, Screen.height) / (float)Mathf.Max(Screen.width, Screen.height);
    6.  
    7. // Calculate height based on aspect ratio
    8. int thumbnailHeight = (int)(thumbnailWidth * aspectRatio);
    9.  
    10. // Check for NPOT support, if not found, use nearest POT size
    11. if(SystemInfo.npotSupport == NPOTSupport.None) {
    12.     thumbnailWidth = Mathf.NextPowerOfTwo(thumbnailWidth);
    13.     thumbnailHeight = Mathf.NextPowerOfTwo(thumbnailHeight);
    14. }
     
    Last edited: May 5, 2015
  15. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Hmm, I don't see why it would be a requirement to recreate the thumbnail. If eg. the shot is taken in portrait eg in resolution 1080x1920 and then switched to landscape, I don't see why the shot aka the texture would need to change? The screen layout may need to change otherwise as well, and the author of the game or other app can deal with the thumbnail similarly. In any case, this is hardly a problem as it's simple to just rotate the gui element.

    Thanks for the effort to help. It's just that the only reason I was trying the portrait view was to find out if that would reveal something about the nature of the one-quarter-problem. But it didn't.

    What's very confusing now is that as I rebuilt the test project, it's now working perfectly, in other words it doesn't have the portrait mode flickery issue I described earlier. I still have the older build that has the flickery issue, but I don't know how I ended up with that. Even though it's not about the main issue of this thread (the quarter-screen thing) could it tell you something if I sent you that build? LibiPhonelib.a probably isn't needed for the package to make it smaller?

    One thing came to mind. This is probably far-fetched but as I have hard time finding out the cause, could this other issue http://forum.unity3d.com/threads/problem-building-for-ios-after-fb-integration.323169/ somehow be related to the quarter screen thing?
     
  16. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    FB thing should not relate to this. Hmm.. is the recorded video fine ? or is it cropped the same way? The build without code does not probably help much. If you are able to replicate any of these problems with some simple test case I would be happy to view that.
     
    Last edited: May 5, 2015
  17. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    The crashing isn't necessarily about FB, that's just my guess. I'll probably at some point try if removing some fb functionality removes the freezing problem. That could help in resolving this thing too.

    Recorded videos are fine, which is of course the most important thing. It's just the thumbnail that's not working.
     
  18. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Okay, I made sure. The freezing IS about Facebook, and totally unrelated to this.
     
  19. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    If you have a new iOS8 device that supports Metal rendering you could check if the issue happens with both, Metal and OpenGL by forcing the graphics API from the Player Settings / iOS / Graphics API.
     
  20. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    I'm testing with iPhone 5 (not S) and iPad mini, so Metal doesn't seem to be supported.
     
  21. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    This is frustrating. I've tried having all player settings the same in the test and the game project (including settings like target iOS version and GPU skinning). I've tried having all sorts of different cameras in the test project like I have in the game project. I've tried setting the texture directly like I wrote in the code snippet above and I've tried using the texture ready delegate. I've tried several small changes to the way I'm taking the texture. Still, the result is always the same: test project works, but the game project gets those 1/4 screen thumbnails (yes, looking at the thumbnail I'm ~98% sure it's exactly 1/4).

    Running out of ideas here. Well, there is one thing I could still test: building a new scene within my game project and testing with that. If that has the 1/4 thumbnail then the issue should be about the project settings. Otherwise it should be about what's going on in the scene...

    ed: okay, I tried that. Running that test scene from my game project results in that test scene also causing those faulty 1/4 thumbnails. So that would suggest that it's related to some project settings. Any ideas what that could be? I think at least the player settings should be the same now.
     
    Last edited: May 6, 2015
  22. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Hmm. One thing that comes to my mind is downscaled graphics (target resolution), however if you already checked that it is same for the both projects I start to be out of ideas too.
     
    JeffersonTD likes this.
  23. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Huh, I now first tried just cleaning out the library directory, which didn't help. Then I took a more drastic measure and deleted all my project settings. And, good news, that actually helped! It's working now!!! :)

    I really don't know what was causing that, but one guess could be that as this was a project I originally started quite a long time ago, I at some point did a migration to a newer Unity version. Maybe the migration was somehow incomplete and something wasn't just quite right. Interestingly though, everything else has been working properly. It's only this thumbnail thing that has caused problems.

    When I have more time I'll still try to pinpoint which group of settings exactly was the one causing trouble. Currently I only put those settings back that are absolutely needed for the game to work (layers and tags at least). Maybe GraphicsSettings or ProjectSettings? I'll probably test that quickly tomorrow. Maybe I'll even find a specific trouble-causing setting I had somehow earlier failed to notice. You might be interested to know too, so I'll keep you posted. Would also be really interesting to know if now, as a solution was found, you would have some ideas regarding as to why this was happening.
     
  24. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Great news! :) Yeah, the cause would be interesting to know.
     
  25. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Thanks. I'll investigate that later. Unfortunately I have to say that problem 2 still persists:

    2. Having the screenshot incrementally disappear when rotating the camera (or the mesh containing the thumbnail material).

    Before assigning the thumbnail that particular material works fine, so that would suggest that the problem isn't shader-related. The material only works this way after assigning the thumbnail. My GUI design is such that the GUI elements move a bit and with gyroscope control activated actually quite a lot, so I'd need the the thumbnail to allow different view angles. But after taking the thumbnail shouldn't the thumbnail texture act like any other texture? So I wonder what's causing this.

    I'll investigate this at some point during the weekend too.
     
  26. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Unfortunately I don't fully understand what you mean, but yes, the thumbnail is a regular texture except you can't read pixels from it since it is updated outside Unity.
     
  27. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Well it so happens that this thing I was able to reproduce in the test project, so I sent it to you via email. I hope that clears the problem out!
     
  28. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    I pinpointed the troublemaker: it was the quality settings. But I compared each single setting within the asset and they were all the same in the broken and the working version of it, so the problem has to be somewhere beneath the configurable surface! So some Unity version upgrade indeed probably was the cause.

    I don't think I have any way of getting any deeper with this, so it would be truly interesting and educational, if someone had an explanation as to what the heck the difference can be and how it ended up manifesting itself in this weird bug.
     
  29. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Ok, unfortunately no idea about the cause but thanks for debugging it.
     
  30. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Not that it's that important for me at least, but if you are interested in pursuing that, it could potentially be reproduceable by creating a project with an old version of Unity (something like 4.1.) and copying the qualitysettings file from that. I didn't try that, but any way.

    In any case, any ideas regarding the thumbnail angle problem ( ) for which I sent the example project?
     
  31. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    The texture for the thumbnail or FaceCam should be created without mipmaps and the preferred color depth is 32. For example: Texture2D texture = newTexture2D (256, 256, TextureFormat.ARGB32, false);
     
  32. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Thanks! That helped! :)