Search Unity

RenderTextureReadWrite enumeration (Linear or sRGB)

Discussion in 'Shaders' started by metaleap, Jun 25, 2014.

  1. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    The docs http://docs.unity3d.com/ScriptReference/RenderTextureReadWrite.html are a little "lean" on this RTT constructor option.

    Consider a project that is fully and always in Linear color space.

    You render into HDR reflection textures that get later applied in the light post-pass (yes). You render non-HDR G-buffers (they don't do lighting yet so LDR is ok for albedo/normal/etcpp).

    I suppose these rendertextures don't need to always linearize and delinearize themselves all the time only to be re-linearized when fed into the final pass (that ultimately gets gamma-corrected just before it's blit to screen).

    So that leads me to conclude I should construct them with RenderTextureReadWrite.Linear, right?

    At the same time, I don't want them to operate in "gamma space". Especially the reflection passes perform supercheap Lambertian NdotL vertex lighting so that should happen in linear space.

    Aaand presto, confused once again! :D
     
  2. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    .... bump? ;)
     
  3. braaad

    braaad

    Joined:
    Oct 4, 2012
    Posts:
    102
    Yes, set them to Linear. This will tell Unity to not use sRGB samplers for them. Anything inside the pipeline should operate in linear space, and as you say the GPU will convert when blit to the screen. By setting Linear or sRGB you are telling the API what sampler to use, so as long as you keep everything in linear you should be good.

    With regard to your last paragraph about not operating in gamma space, it seems like you are thinking Linear mode will convert to gamma? am I reading this right? Like I said before the mode should just tell the API what sampler to use for that particular texture, so unless you tell it to use sRGB it should be linear.

    It's a bit confusing, but I hope I understood what you were asking.

    Edit: I just realised after posting this, maybe Unity does something different when set to linear colour space? I don't know, like you said the docs are fairly thin. You might have to do some more testing.
     
  4. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Thanks, OK gonna experiment. On re-reading the thin docs, sounds like "Default" should auto-select Linear for a project in Linear Space and a RenderTexture that's not the very final screen pass. But then "sounds like it should" has been a dangerous assumption ever since :D
     
  5. braaad

    braaad

    Joined:
    Oct 4, 2012
    Posts:
    102
    Yeah, you would assume that's what would happen. Wouldn't be as fun if they told us everything :rolleyes: