Search Unity

Rendertexture does not render terrain :(

Discussion in 'Scripting' started by djoscar, Sep 23, 2009.

  1. djoscar

    djoscar

    Joined:
    Jul 31, 2009
    Posts:
    141
    I'm making a minimap for a game..
    I created new camera, attached rendertexture to it and if I try to add the rendertexture to a gameobject then terrain and everything else shows perfectly but...
    I want to have a 2D minimap, so I tried adding new GUI Texture into game and placed rendertexture in Texture position, but it only renders game objects, where as Terrain is invisible, it doesn't show up :(

    Where is the problem?

    Thank's.
     
  2. KlaRo115

    KlaRo115

    Joined:
    Feb 24, 2006
    Posts:
    675
    Do you need a map like on a road map or a gps? or do you want a realTime video clip from the top of the character's head?
    What about making a screenshot (cmd+shift+4) from inside the editor you then use as the texture of a plane you put under the terrain. Then simply change the layers of the object and the ones the main camera shows, so that in normal view, you can't see the plane with the map on it, but it's rendered by your map camera... :)
     
  3. djoscar

    djoscar

    Joined:
    Jul 31, 2009
    Posts:
    141
    Umm It's more of a GPS lol, basically I added the camera much higher than the character and it will render the character from top, following it everywhere.
    Simple minimap :p

    It works perfectly, just that the terrain isn't being rendered :S
     
  4. djoscar

    djoscar

    Joined:
    Jul 31, 2009
    Posts:
    141
    anyone..? :(

    Need to fix this really badly :/
     
  5. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    Haven't tried render textures yet but how about checking camera far clip and checking the alpha of the terrain on the resulting texture?
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Another thought: have you put the terrain in its own layer? If so, make sure the camera's culling mask is set to render this layer.
     
  7. philc

    philc

    Joined:
    Sep 2, 2009
    Posts:
    3
    Hey,

    I has this exact same issue but found a solution (or what I think was the solution). Inside you OnGUI function instead of using GUI.DrawTexture do a Graphics.DrawTexture(...). This will also allow you to apply a shader to the texture so you can make your mini map any shape.
     
  8. KlaRo115

    KlaRo115

    Joined:
    Feb 24, 2006
    Posts:
    675
    Or simply use a second camera that you can place over your character. Then you'll have to adjust position and resolution of this camera, I already took this for minimaps in my own levels. The camera's output images should then show up at the border of the screen and render everything, included the terrain.
    (Why do you want to use a render texture, if there are other very basic methods?)
     
  9. northman

    northman

    Joined:
    Feb 28, 2008
    Posts:
    144
    :(
    I got same problem, I need show terrain in GUITextute to make the Car's mirror.

    Anyone help?
     
  10. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    You might not need to use a GUITexture to make a car mirror. The Camera class has a rect variable that determines where on the screen the camera will render. You can set the mirror camera so that it renders to a small, mirror-shaped rectangle rather than the whole screen.
     
  11. INSANE_BR

    INSANE_BR

    Joined:
    Sep 10, 2009
    Posts:
    142
    Hi all I'm experiencing the same problem.

    I tried that but my terrain still won't render.

    My terrain is tagged as Default Layer, and my Minimap Camera is rendering Default (most other objects are Default also)

    I want to use a camera and not a Screenshot because the camera show perspective, whats very very cool :)

    Thanks in advance.
     
  12. burnumd

    burnumd

    Joined:
    May 27, 2008
    Posts:
    367
    I've just run into this problem. It looks as though the GUI/Text Shader doesn't render terrain. I'd presume that's the shader when one uses any GUI methods to draw a RenderTexture. The workarounds mentioned (Graphics.DrawTexture, using the view port rect) work, but I plan to file a bug report anyway.
     
  13. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    Still not fixed in 3.5 .... gah.
     
  14. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    This is not a bug, as you must have configured something wrong. It renders perfectly for me,
     
  15. SimplyZ

    SimplyZ

    Joined:
    Jun 19, 2011
    Posts:
    2
    Try using this code. Make sure to set the Material to Unlit/Texture, if you use the normal Diffuse, this will not work!!

    using UnityEngine;
    using System.Collections;

    public class MinimapTest : MonoBehaviour
    {

    public Material aMaterial;
    public Texture aTexture;
    void OnGUI ()
    {

    Graphics.DrawTexture(new Rect(100,100, 128, 128),aTexture, aMaterial);

    }
    }

    I previously had the same issue but this solved it for me.

    Credit goes to Tabu at UnityAnswers for finding this.
     
  16. FreedomFighter1020

    FreedomFighter1020

    Joined:
    Mar 22, 2013
    Posts:
    6
    Great one!
     
  17. Patrik_222

    Patrik_222

    Joined:
    Jul 22, 2022
    Posts:
    2
    I have found it! Go to the camera that renders the mini map. Then go rendering, and there is Opaque texture. Turn that on.