Search Unity

Object rendered by overlay camera no shadow from other objects on other camera

Discussion in 'Universal Render Pipeline' started by DevCas1, Mar 15, 2021.

  1. DevCas1

    DevCas1

    Joined:
    Sep 24, 2015
    Posts:
    21
    I had an object rendered by an overlay camera, and then be overlaid on top of the base camera. This worked perfectly, until I noticed the object rendered by the overlay camera receives no shadows from other objects (rendered by the base camera). It only receives self shadows.
    With shadow.png The intended effect (with exaggerated light intensity)
    No shadow.png The current effect
    I did it like this to deal with object clipping.
    No clipping.png The wanted effect with overlay and base camera
    Clipping.png The result with having the base camera render both cannon and the scene
    Is there another way to do it? Perhaps have the cannon have a different shader that is very much like the URP Lit shader, except that it always renders on top of the camera's resulting image? (this to prevent it from rendering on top of the helmet geometry, which is rendered by another overlay camera)
     
    Marc-Saubion likes this.
  2. pimpekdev

    pimpekdev

    Joined:
    Feb 18, 2020
    Posts:
    4
    bump, i would like to know the anwser too, i dont know how to solve this problem
     
    Marc-Saubion likes this.
  3. igloogamescompany

    igloogamescompany

    Joined:
    Jan 28, 2020
    Posts:
    1
    I think I accidentaly stumbled acrossed the solution while messing with urp. Instead of telling one camera to cull everything but the gun, create a secondary urp renderer that renders only the gun layer and tell the camera to use that.
     
    valdygra and bmedeiros95 like this.
  4. DevCas1

    DevCas1

    Joined:
    Sep 24, 2015
    Posts:
    21
    Could you please explain this setup in more detail? My current setup has one base camera and an overlay camera, where the base camera renders everything but the gun, and the overlay camera renders only the gun. Then there's also a third overlay camera rendering only the helmet.

    How would this differ from your setup? Currently not seeing the difference
     
  5. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    110
    If you take a look in the Frame Debugger you'll see that each of the cameras in the camera stack has its own render process. This means that each camera has their own MainLightShadow pass, which means that any object only rendered by one camera will not be present in the shadowmap of the other.
    My advice would be to ditch camera stacking (at least for the gun camera) and instead draw the gun using the RenderObjects renderer feature. This will make sure that the gun is drawn with the shadowmap that the environment is drawn into. Make sure to draw the gun at a late pipeline event (like BeforeDrawingPostProcessing) and make sure that the depth test is set to Always to avoid clipping with the environment.
    Hopefully that solves it for you :)
     
  6. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    110
    One thing to be aware of with the above solution;
    You will get shadows on the gun when it is inside the environment geo, even though it's forced to not clip.
     
    Marc-Saubion likes this.
  7. DevCas1

    DevCas1

    Joined:
    Sep 24, 2015
    Posts:
    21
    Will have a look into using RenderObjects, thank you! Should that give worse results, it isn't the worst thing in the world. Just curious if it was possible
     
  8. ahmadgml32

    ahmadgml32

    Joined:
    May 29, 2020
    Posts:
    4
    Want to change fov for the gun when aiming for example throw script in real time how can I do that?
     
  9. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    110
    @ahmadgml32
    You can modify the renderer (UniversalRendererData) in use by assigning it to script:
    Code (CSharp):
    1. public UniversalRendererData rendererData;
    2.  
    3. void Start()
    4. {
    5.     RenderObjects ro = rendererData.rendererFeatures.OfType<RenderObjects>().FirstOrDefault();
    6.  
    7.     if(ro != null)
    8.     {
    9.         ro.settings.cameraSettings.cameraFieldOfView = 120;
    10.     }
    11.  
    12.     rendererData.SetDirty();
    13. }
    Currently there is no API for getting a reference to the current Universal Renderer completely from script. You need to assign it in the editor
     
  10. PanoTron

    PanoTron

    Joined:
    Oct 21, 2015
    Posts:
    5
    This is the only solution after hours of digging that really works. I wonder if there is overhead because the weapon-only rendering camera still has Everything in its culling mask, but its renderer doesn't include those layers (this way shadows work).
    Thank you dawg. I needed a camera stack solution to have a different FOV for my weapons. (the render objects FOV solution was being weird for me and didn't work with the SSAO renderer feature)
     
    valdygra likes this.