Search Unity

Question Opaque objects rendered with Lit material in a custom pass don't look the same as drawn normaly.

Discussion in 'High Definition Render Pipeline' started by cubrman, Jul 28, 2020.

  1. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    I want to create an effect where an opaque mesh blocking the camera will slowly fade from view. I want to make it automatic and never involve changing materials to transparent. Custom pass seems to be the way to go, but I have two problems:

    1. When I render opaque objects into a custom render target with their normal Lit opaque shader, they are rendered with weird seams, which seems to be due to lighting systems I do not fully understand.

    Scene before custom pass:
    upload_2020-7-28_17-21-51.png

    Rendering objects (invisible to the camera due to them being on a non-renderable layer) into a custom render target:
    upload_2020-7-28_17-23-17.png
    (Arrows indicate seams-glitches, one can easily see the googles' shape on the helmet even though the helmet is in front of the googles this whole time).

    Here I must say that I've set up everything carefuly: I have a depth buffer connected to my color texture and models are rendered with ZTest set to LEqual. I also tried fiddling with rendererConfiguration flag group of RendererListDesc struct but it did not yield anything useful.

    This problem can be solved by changing the material types of both objects to Transparent, but this is unacceptable to me as I don't know how to make such a change at runtime and I don't want to render every hideable mesh as a transparent object when they are not blocking the camera.

    2. The second issue is the fact that post processing somewhy does not apply to my models, when I subsequently blend them into the scene with a standard alpha-blend:

    Meshes drawn normaly:
    upload_2020-7-28_17-30-0.png

    Now below, meshes never get rendered in a standard way but instead are alpha-blended into the scene from a custom render target:
    upload_2020-7-28_17-31-16.png

    even if we ignore the seams, which are quite noticeable in this screenshot, the colors of the objects do not match. My analysis of the frame with the Frame Debugger show that this is due to Post Processing not being applied to the meshes that are alphablended in.
     

    Attached Files:

  2. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Just checked the DrawRenderersCustomPass - the first problem is also present in there.
     
  3. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Please, Unity team, I really need an answer for this - I don't think I will be able to crack this nut on my own.
     
  4. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Ok the glitches come from the shadowmask (I think) that is computed between the DepthOnly and ForwardOpaque) passes. Unity relies on opaque objects being properly rendered into the depth buffer before the opaque pass so that the shadows can be pre-computed before the acutal models are drawn.

    Hell, I really hope there is a way to overcome this.
     
  5. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Ok the first problem can be fixed by turning off contact shadows (which I don't use anyway). Let's see if I can solve the second one...
     
  6. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Unity I have absolutely no clue how to make post processing apply to my models that I draw with a fullscreen pass. Please at least give me a suggestion.
     
  7. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Honestly Unity I have no clue what to do. I tried writing depth into the depth buffer, setting the stencil values exactly the same as when transparent/opaque is drawn - I just have no fricking clue. It just does not look the same in the slightest.
    What's even more infuriating is the fact that the objects never cast shadows, even when I render them into the depth buffer BEFORE RENDERING. This is just unbeatable.
     
  8. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    S***, I have one hope left: I want to try to render a model in a standard way with a variation of an unlit shader, which has my custom render texture as input. The problem is: I can't set my render texture to the shader! Jesus, it sure could be great if Unity team were actually answering people on their official Unity forum.