Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Unexpected behaviour of fallback material with DrawRenderers

Discussion in 'Universal Render Pipeline' started by Si1ver, Dec 9, 2022.

  1. Si1ver

    Si1ver

    Joined:
    Aug 23, 2014
    Posts:
    3
    Hi!

    We encountered strange behavior in rendering on URP 12.1.8 and I would like to know if it's a bug or we don't understand something.

    When using SRP, we expect objects to be filtered according to filtering settings when calling context.DrawRenderers(). We have an issue when objects are missing from expected drawing result, until they are moved in scene.
    We are using both custom filtering settings and draw settings as shown below.

    Code (CSharp):
    1. _filteringSettings = FilteringSettings.defaultValue;
    2. _filteringSettings.renderingLayerMask = 1 << 20;
    Code (CSharp):
    1. var drawingSettings = CreateDrawingSettings(
    2.     _fallbackTestId, // <- Materials without "FallbackTest" pass don't get into render, till manually moved in scene!
    3.     ref renderingData,
    4.     SortingCriteria.CommonOpaque
    5. );
    6.  
    7. drawingSettings.fallbackMaterial = _fallbackMaterial; // Doesn't work, till manually moved in scene!
    We expect that objects that comply to filtering requirements but not comply wit drawing setting will be rendered with fallback material. This is based on our understainding of this documentation https://docs.unity3d.com/ScriptReference/Rendering.DrawingSettings-fallbackMaterial.html

    Here is a screenshot of the scene from sample project with additional rendering pass. All objects should be rendered with additional rendering pass that adds red color overlay. No objects are rendered as we expect - we suppose that they were filtered out incorrectly.
    before_move.jpg

    Here is a screenshot of the same scene after 'stud' object was moved. Additional pass appeared in Frame Debugger but only one object that was moved is rendered as expected. When movement is cancelled with Ctrl+z or manually returned to initial position, object is disappearing again from additional pass.
    after_move.jpg

    We are using Unity 2021.3.15f1 on Windows 10 (DX11 renderer) and macOS (metal renderer) (silicon Editor version) and issue appears.

    If anyone knows if this is expected for some reason or a known bug please let me know. If this is unknown bug I'll be happy to submit a bug report.

    One may check a minimal repro here https://github.com/alexmalyutindev/unity-fallbackMaterial-filltering-bug

    See Assets/BUG_REPRO directory for custom ScriptableRendererFeature.

    To reproduce the issue open SampleScene. Everything on the scene should be rendered using fallback material which makes objects appear with red color overlay. Instead everything is rendered using default material until something is moved.
     
    alexmalyutindev likes this.
  2. cjacobwade

    cjacobwade

    Joined:
    Jun 8, 2013
    Posts:
    10
    We're having a similar issue. Were you able to find some workaround @Si1ver?
     
  3. Si1ver

    Si1ver

    Joined:
    Aug 23, 2014
    Posts:
    3
    Hi @cjacobwade
    Sorry I've missed your mention.

    This is not a bug and a misleading naming. This fallback material is used only for motion vector pass and it can not be used in cases when your objects are not supposed to be moving. It triggers render only for objects that was moved.

    One way to solve this is creating special shader pass and render feature that uses it to render objects for your effect.