Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

render texture colors aren't as expected

Discussion in 'General Graphics' started by bdavis1000, May 16, 2019.

  1. bdavis1000

    bdavis1000

    Joined:
    Oct 4, 2013
    Posts:
    18
    I'm using a render texture to apply full screen transition effects. When one of these occurs, I set the main camera's target texture to a new render texture. This texture is then referenced by a Raw Image on a canvas rendering to a second camera. This takes up the whole screen and it should not be noticeable to the user that anything has occurred at the time the switch happens. The raw image has a default shader on it, and the second camera is configured identically to the main camera. The problem I am seeing is that the colors are not correct on the new render texture. Here is an example:

    https://imgur.com/a/EMIJkbU

    The first image is what the scene looks like prior to switching to a render texture.

    The second image is a render texture created as such:
    Code (CSharp):
    1. new RenderTexture(EffectiveRes.x, EffectiveRes.y, 32, RenderTextureFormat.ARGB32);
    What's odd to me about this is the background, which is clearly being rendered to the texture, is fully opaque. Yet it seems to have written the alpha level of every pixel in the foreground to the texture, and ignored the background. This obviously isn't correct.

    The final image is what I see in the scene if I swap a render texture created like this:
    Code (CSharp):
    1. RenderTexture(EffectiveRes.x, EffectiveRes.y, 24, RenderTextureFormat.Default);
    onto the raw image. Here it is mostly correct, but if you look closely the black bar in the middle is a bit washed out, and the previously mostly transparent puzzle piece sprites on the top left buttons are very visible.

    What I am wondering is, how can i get the colors looking identical? I can keep trying different formats and bit depths but I don't understand why either of these render textures is configured incorrectly.
     
  2. darreney

    darreney

    Joined:
    Oct 9, 2018
    Posts:
    33
  3. bdavis1000

    bdavis1000

    Joined:
    Oct 4, 2013
    Posts:
    18
    I was able to resolve my issue by setting the RenderTextureReadWrite conversion settings:

    Code (CSharp):
    1. new RenderTexture(w, h, 32, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
    2.  
     
    SuperRaffles likes this.
  4. darreney

    darreney

    Joined:
    Oct 9, 2018
    Posts:
    33
    Ah nice that you found fix! thank you for sharing~
     
    SuperRaffles likes this.
  5. chantey

    chantey

    Joined:
    Mar 5, 2017
    Posts:
    49
    yeah nice, in my case the correct one was
    Code (CSharp):
    1. RenderTextureReadWrite.Linear
     
    SuperRaffles likes this.