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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How To Disable Linear Color Space for Render Texture?

Discussion in 'General Graphics' started by topsekret, Jun 10, 2016.

  1. topsekret

    topsekret

    Joined:
    Apr 18, 2013
    Posts:
    69
    I have a camera in my scene that is being used to render a flow map in real time. The camera renders certain particles where the particle color encodes a direction.

    Everything works fine in gamma space, but in linear space, the gamma->linear conversions are breaking everything.

    According to the documentation about render textures, I should be able to set the RenderTextureReadWrite mode of my camera's render texture to Linear to avoid these conversions, even though the project is set to linear space:

    "However, if your render texture will contain non-color data (normals, velocities, other custom values) then you don't want Linear<->sRGB conversions to happen. This is the Linear read-write mode."

    Unfortunately, none of the values of that enum appear to change anything. What am I doing wrong?

    I have also tried setting GL.sRGBWrite in OnPreRender and setting it back in OnPostRender, but that doesn't do anything either (yes, the script with OnPreRender and OnPostRender is attached to my camera). Does that variable only work if you are rendering using the GL API, but not general Cameras?
     
  2. topsekret

    topsekret

    Joined:
    Apr 18, 2013
    Posts:
    69
  3. ciwolsey

    ciwolsey

    Joined:
    Jun 13, 2016
    Posts:
    29
    Did you ever figure this out?
     
  4. topsekret

    topsekret

    Joined:
    Apr 18, 2013
    Posts:
    69
    I never got it to work using the setting on the render texture. So I ended up having to work around it by converting between linear and gamma space in the shaders and doing conversions on colors passed to the shaders. Kind of unfortunate that we have to pay the performance cost of these redundant calculations.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Were you using render textures from GetTemporary(), or using new RenderTexture()? I think some people have had issues with GetTemporary.
     
  6. topsekret

    topsekret

    Joined:
    Apr 18, 2013
    Posts:
    69
    I was using the RenderTexture constructor.
     
  7. amasinton

    amasinton

    Joined:
    Aug 12, 2006
    Posts:
    137
    I got this working (at least for my requirements).

    The documentation notes: "Note that some render texture formats are always considered to contain "linear" data and no sRGB conversions are ever performed on them, no matter what is the read-write setting. This is true for all "HDR" (floating point) formats, and other formats like Depth or Shadowmap."

    So, when using the RenderTexture constructor, I used the RenderTextureFormat.ARGB32 and RenderTextureReadWrite.Linear parameters. That seemed to do the trick for me.
     
    choudaniel3 and Hysparions like this.
  8. Cicaeda

    Cicaeda

    Joined:
    Sep 29, 2017
    Posts:
    34
    Bumping because this is the first thread on Google.

    For render textures created as assets in the project folder, you can set your inspector to Debug Mode and toggle the SRGB setting there. This was the only thing that worked for me.
     
  9. claus_interactive

    claus_interactive

    Joined:
    Nov 22, 2018
    Posts:
    9
    Thank you Mr. Cicaeda, that did the trick for me too.