Search Unity

Replacement shader for camera --> only touch alpha, leave rest as is

Discussion in 'Shaders' started by R_RT, Sep 18, 2017.

  1. R_RT

    R_RT

    Joined:
    Jan 22, 2017
    Posts:
    7
    Hey guys,

    I was wondering if I could use a replacement shader to ONLY change the values in the alpha channel and leave the RGB values as they would be without the replacement shader.

    Basically I am trying to switch the alpha channel and put in the depth value. What I am doing right now is to render just twice, once for the standard view of the camera with RGBA and one time to get the depth texture into RGB of another texture to then access it.

    Because I don't need the alpha anyway I want to render just once, having depth in the alpha channel. What I got right now is like changing the whole camera-shader, which ends up having the RGB values changed as well...
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    R_RT likes this.
  3. R_RT

    R_RT

    Joined:
    Jan 22, 2017
    Posts:
    7
    Thanks. Yeah I'm gonna go for float texture probably, so there won't be precision loss.
    Accessing z-buffer is not my problem either, that's fine, I just do not know how to not affect the other channels when I replace the shader of the camera with the custom one.
     
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    There isn't really a shader of the camera. Materials have shaders and then there are postprocessing shaders.

    You can write to alpha only using ColorMask A.

    When you just want to write to the z-buffer and not to the color buffer, just remove SV_Target as target and only keep SV_Depth.