Search Unity

Render Texture Not working in 4.6

Discussion in 'UGUI & TextMesh Pro' started by Jribs, Oct 2, 2014.

  1. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    Hey so Render Texture doesn't seem to be working at all in the 4.6 beta.
    At least not with the current documentaion about Render Texture.

    Does it have a different implementation than previously?

    Has anyone else tried this?
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Post code. there's no known problem with render textures.
     
  3. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Is the camera actually looking at something relevant, and obviously, it's not the same camera as the scene camera?
     
  5. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    Yeah, there is something in the cameras view area and correct, it is not the same camera as the scene camera.

    Is this working for you in unity 4.6? If it is working for you then it must be another issue.
     
  6. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Relying on RenderTextures heavily in current pjt, they're working just fine in 4.6 for me.
     
  7. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    This might sound silly but can you go over your use of it? Even just the basics of adding the Render Texture

    This is driving me crazy that following the basic tutorial from the unity documentation is not working.
     
  8. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Yep, create a Render Texture via Assets/Create/Render Texture. Next select a camera and drag the render texture onto the Target Texture property in the inspector. That's it. Now click select the RenderTexture and make sure that it's displaying the cameras output.
     
  9. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    So here is what I am doing.

    Starting from a blank brand new project and scene.

    Create a Render Texture via Assets/Create/Render Texture.

    Add a second camera, so I now have 2 in the scene.

    I then drag the Render Texture onto the Target Texture property of the second camera.

    I move the cameras around and add a tree prefab in front of the second camera (the one with the render texture) so it has something to see.

    I then create a plane that is in view of the first scene camera and drag the Render Texture onto that.

    Nothing. All I get is a black plane. When I click on the Render Texture it only shows black in the inspector.

    What am I doing wrong??
    Are there any special settings needed for the camera? Or for the Render Texture? I don't understand.

    I just made sure I had downloaded the latest 4.6.20 and completely reinstalled unity.
     
  10. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    This may be a silly question after this many replies, but are you sure you have Unity Pro?
     
  11. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    I do have unity pro
     
  12. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Won't help a lot with the problems you have, but just a week ago i followed some sort of youtube tutorial for rendertexture and it works for me. Few questions that might help you narrow down your problem:
    1) In play mode if you switch to scene and select camera that is meant to render to texture - do you see the view there?
    2) If you add resource to your project library (rather than using runtime one). If you select resource - do you see anything there?

    Make sure you set cullingmask and clear flags to something reasonable on both cameras. This has to work.
     
  13. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Are you lighting that plane, or setting its shader to something like Unlit/Texture? Also, highlight the camera and make sure the tree shows up on its Camera Preview window.

    BTW, if you've never used a feature, and then you try it in a beta and can't get it working, it's best not to post a thread titled "feature X doesn't work in this new beta!" because (as you are seeing) the feature IS working in the beta, you just aren't figuring out how to do it correctly, and that kind of thread title is now misleading.
     
  14. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    perhaps the tree is clipped by the camera and your scales are all out. In any case upload a reproduction scene which contains your particular situation.
     
  15. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    Hey @Jribeira have you found a solution to your problem?
    It seems that the same is happening to me.
     
  16. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    I don't know if it is a solution but it started working after I started with another brand new project. No issues. Not sure why it was doing it.
     
  17. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    I am experiencing the same.

    I get a back screen in my project even though my camera does show content in the preview panel when I click on the camera. When I click on the rendertexture, it shows black, not the output of my camera. I then create a new scene, try to do everything from scratch and same issue...

    So then I open up another project, do the same in there and lo and behold... it works like a charm. So what the hell is up with that??? At first I saw it working in 4.6.1f1 but it didn't work in 4.6.1p1 so I thought it was a bug in the patch release but then I opened the project in f1 and still the same issue...

    So now I am left wondering if there is a combination of settings that will make this not work. i.e. set the rendertexture size to 256x256 then use the camera in iOS build option with a 16:10 ratio, forward rendering and rendering items over the span of hundreds of units instead of scaling everything down to using 0..10 units only... I don't really know... some combination of something

    Oh... Oh bloody heck... I think I might have just answered my own question :O So now someone else who is having this issue can go verify if this is their issue also...

    I am doing an iOS project but I only have Unity Pro, not iOS pro... could THAT be why rendertexture is not working? The other project that it worked in was set to a Standalone build while the project that it didn't work in was set to iOS... Gonna go check that out now...

    Bleeding amazing that I turn to here for help when I am fresh out of ideas and then I possibly find the answer while asking you for help :p But could that really be it
     
  18. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    Awww shoot... that is exactly it... :( As soon as I switch to iOS platform the render texture stops receiving input :(
    Bugger...

    Just had a look on the license comparison page and it seems this is correct... I need to upgrade my license before that will work... bugger! :(
     
  19. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    NOOOOOOOOOOOOOOOOOO! not the wallet!
     
  20. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    I know, right? :(

    lol... fortunately, for my specific use case scenario and the reason why I wanted to use a render texture... I managed to get around that by just adding a Mask component to one of my game objects and that was that! :D Phew! :D $750 or add a Mask component :D lol

    To explain that statement... I wanted to display a 2D UGUI GUI on top of in-scene 3D content taking up the top part of the screen but I also wanted to have more 2D UGUI content slide into view from "behind" the in-game 3D content into a 2D user intractable area. I already do the 3D scene via a separate camera and have the UGUI camera layer over it so how to get the 2D content to slide out from BEHIND the camera that gets rendered first, instead of appearing on top of it?

    Option 1, render the 3D scene into a texture and display via RawImage in the main camera
    Option 2. Add a mask to the parent object of the objects being spawned... the area that conveniently covers exactly the visible area I wanted to use... :)

    but that is just me. Thought I might mention that I had the same issue as the others and that my issue was a second pro license. Perhaps this might be other's problem also.
     
    Last edited: Jan 18, 2015
  21. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Has anyone successfully rendered a canvas to a RenderTexture?
     
  22. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    we did. it takes 1-2 frames to do so as layout is only calculated and drawn at the very end of current frame.
     
  23. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    I was hoping to be able to capture the UI view from specific cameras (to blur the UI elements behind pop-up dialogs). With NGUI, I managed to do this sort of thing with Camera.Render

    Would be nice if this worked with the new UI system, too...
     
  24. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    haven't tried adding effects on camera, but we were able to capture some of elements with dedicated cameras. I doubt that effects would void it. Can't really comment much more. I dropped the task in the middle, because it became redundant, but later my teammate reused some of my code in his components and it seems to be working well :)
     
  25. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    there is a fix coming in one of the next releases which fixes the Camera.Render issue.
     
    bluescrn likes this.
  26. XceQtor

    XceQtor

    Joined:
    May 20, 2014
    Posts:
    2
    when is the next release sir? i have trouble about this too
     
  27. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    well we try for patches every week. But i dont think it will be in the next patch.
     
  28. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Do we need to call Camera.Render in order to capture the UI into a RenderTexture?
    Or can we simply use the old fashioned way of using two cameras where the one that renders the UI has its Render Target set to point to a RenderTexture?
     
  29. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    If you wait for it to capture at the end of the frame you'll be fine. The issue was just when calling Camera.Render the UI didnt know it needed to emit GEO to be rendered.
     
  30. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    I've tried assigning a RenderTexture to the camera, and that causes the UI to be rendered. It works, so long as the render texture exactly matches the current screen resolution.

    If the render texture is lower res and/or a different aspect ratio (a reduced-res power-of-2-sized buffer to be used for a blur effect), it all goes a bit wrong, the layout gets rescaled in rather undesirable ways... And I'm assuming that this will probably happen with Camera.Render when the fix is in, too?

    Is there any way to 'lock' the effect of the Canvas Scaler so that it won't attempt to rescale things when rendering to a texture? - So that it thinks the resolution is unchanged when switching to the render texture? (As the blurred image that I'm trying to generate will then be stretched over the whole screen)
     
  31. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Hey phil, can you get into more detail about how to capture the UI - and only the UI - into a render texture?
    I need that RT for further post processing.
    Code (csharp):
    1.  
    2. void OnRenderImage(RenderTexture sourceTexture, RenderTexture destTexture)
    3.  { Graphics.Blit(sourceTexture, destTexture, myMat); }
    4.  
    This doesn't seem to work. Probably because it doesn't fetch the sourceTexture at the very end of the UI rendering process.
    An example of how to do some post processing on UI would be nice.