Search Unity

Question looking for transparent urp shaders that z-write

Discussion in 'Shaders' started by canslp, Mar 16, 2023.

  1. canslp

    canslp

    Joined:
    May 6, 2019
    Posts:
    36
    i'm looking for a shader that does all of the following:
    - is transparent (at least with cutout, according to the texture alpha)
    - writes to the depth buffer
    - does not have automatic shadow culling at fixed distances
    - bonus: can use normal maps, can render with 2-sided faces and shadows

    i understand that transparent shaders generally do not z-write, since they usually only do one pass, not to the depth buffer. i've been using the urp speedtree8 shader, because it's a transparent shader that z-writes. it also conveniently allows 2-sided rendering. unfortunately, this is a really specialized shader that has some weird properties. there's all kinds of features i don't need, like color jitter. but this shader also seems to be doing some efficiency things meant for foliage- notably it culls shadows if you get too close to them. this seems to be a completely fixed value, which is really frustrating. i'm pretty unfamiliar with hlsl, and this seems to be too technical for shader graph. is there a shader available that is just a transparent, depth-writing lit shader? if not, where can i get one? thanks
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You can get a shader that does all of this by using the included Lit shader by setting Render Face -> Both and enabling Alpha Clipping (which another name for Alpha Test or Cutout).
    upload_2023-3-16_10-32-39.png
    Similar settings exist for Shader Graph.

    If you want an alpha blended transparent shader that writes to the depth buffer, that also supports lighting, etc. That's a harder request. And depending on what you mean by "depth buffer" may actually be impossible. If you want transparent objects to show up in the camera depth texture used by post processing, it's not at all possible because of the way URP handles the depth texture. If you want it for ghost or hologram style rendering then you don't really need a complicated shader for this. You will probably want two separate materials with one that writes to the depth and the other that's the regular Lit shader set to Transparent. Though that depth only shader will need to be written using HLSL.
     
    Demoralizator and canslp like this.
  3. canslp

    canslp

    Joined:
    May 6, 2019
    Posts:
    36
    that's perfect, thanks. i didn't realize you could do alpha clipping in opaque mode