Search Unity

RenderTexture generated texture -> renders as black.

Discussion in 'Shaders' started by Lucas Meijer_old, May 7, 2008.

  1. Lucas Meijer_old

    Lucas Meijer_old

    Joined:
    Apr 5, 2008
    Posts:
    436
    Hey.

    I'm hoping somebody here can see where I'm doing something wrong.
    I'm blitting several transparent textures ontop of eachother, resulting in a single texture.
    I use a rendertexture for this, a seperate camera, and use the GL.Begin() method of drawing a quad.

    Then I take a Texture2D, and I do ReadPixels(), to read the rendertexture pixels back, so I can store them in a regular Texture2D, to be used as a diffusemap for a regular material.

    When I use the resulting Texture2D with a simple Diffuse shader, the material renders as pitch black.
    Funny enough, the thumbnail inside unity's inspector, looks great. I can see all my layers nicely layered ontop of eachother.

    I figured it was an alpha problem, so added another pass to the rendertotexture, with code copied from a forumpost by aras, that clears the alphachannel.
    same result.

    When I inspect the texture with the game running, in the inspector, and I select "show alpha" the alpha is completely white. I've also checked all my mip levels, they are all correctly filled.

    I'd post the code here, but it's quite a lot of text. The thumbnail looking fine seems to indicate the actual render2texturing and readpixeling is working fine.

    Does this ring a bell for anybody?

    Bye, Lucas
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Does it look fine in the RenderTexture itself prior to copying over to the Texture?

    Did you call Apply () on the texture?
     
  3. Lucas Meijer_old

    Lucas Meijer_old

    Joined:
    Apr 5, 2008
    Posts:
    436
    Apply() does the trick.

    filing documentation enhancement request :)

    Thanks,

    Lucas
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    It's actually already in the documentation.
     
  5. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
    @Joachim_Ante I know this thread is SUPER old but I've just run into the exact same problem but, Apply() doesn't fix the issue. The image's thumbnail displays what it should (a radial-gradient) but when I take an actual look at it, the image is completely black. I noticed converting it to a sprite fixes this, but I don't think this will work for me because I am reading the pixel values of the texture. How would I fix?

    The texture doesn't get displayed anywhere in the scene because it is meant to just act as a heightmap
     
  6. falahPrgm

    falahPrgm

    Joined:
    Jul 31, 2019
    Posts:
    1
  7. lazycatontreebranch

    lazycatontreebranch

    Joined:
    Jul 5, 2020
    Posts:
    2
    change shader to sprite
     
    BrandyStarbrite likes this.
  8. lazycatontreebranch

    lazycatontreebranch

    Joined:
    Jul 5, 2020
    Posts:
    2
    or better to unlit texture
     
  9. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Good fixes guys.
     
  10. orangetech

    orangetech

    Joined:
    Sep 30, 2017
    Posts:
    50
    Call renderTexture.Creat()
    work for me