Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Temporary Render Textures break while playing on a Mac ONLY through Steam

Discussion in 'Universal Render Pipeline' started by HenryCGS, Oct 11, 2023.

  1. HenryCGS

    HenryCGS

    Joined:
    Dec 19, 2018
    Posts:
    3
    This is probably the most cryptic bug I've ever faced and probably the worst one to debug.

    I'm developing a 2D game using URP 12.1.8, on Unity 2021.3.14f1. In order to create some interesting visual effects, I've created a custom ScriptableRendererFeature which allows me to add additional buffers which I can render sprites to in custom shader passes, using temporary RTs. The code is found at the bottom of this post.

    It works perfectly. I have created a couple of buffers with this and used them in many shaders. I was afraid of poor performance, but I've done a lot of profiling and saw nothing of significance.

    I have tested this on Windows, Linux, and Mac. It works perfectly on all of them.
    Well. Except. For one very specific detail.
    It doesn't work specifically on Mac, while playing the game through Steam.

    Let me be clear: I can download the game with Steam, and if I play it directly from the executable, it works just fine. But if I run the game through Steam (by clicking the big green Play button), all effects using custom buffers simply disappear. All of them, no exceptions. Here are some screenshots:

    This is how the game looks normally. This is indeed running on a Mac, running the game directly from the executable. Notice the water effects: the character is sunk on the water, he has reflections and so do the plants. There is also some rippling on the edge of the water. All of these effects use the aforementioned buffers.


    And this is how it looks while playing it from Steam. Notice how all the water effects are gone. Interestingly, the water actually still renders the "simple" part. It's just one big sprite, but its shader has multiple passes. It's as if the custom passes are simply not rendering.


    So, yeah. Like. How do you even begin to debug this? I'm seriously completely lost here.

    My only theory was that it might be related to the Steam Overlay, as it does hijack itself onto the rendering of a window. But after a few tests, we're not so sure anymore. We've tried to run the unity editor itself through steam so that the overlay would show up in the editor, and everything looked normal. We've also downloaded the game externally, added it as a non-steam game and ran it, and everything looked normal as well.

    If anyone has any clue as to what might be happening here, any help would be appreciated. Even if you have some suggestions for ways to debug this, I'd love to hear those. I'd love to publish this game for Mac, but without fixing this I'm unable to. Thanks.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4.  
    5. public class LayerBufferFeature : ScriptableRendererFeature {
    6.  
    7.     [SerializeField] private string cameraTag = "RenderCamera";
    8.     [SerializeField] private Settings settings = new Settings();
    9.  
    10.     private Pass pass;
    11.  
    12.     public override void Create () {
    13.         pass = new Pass(settings);
    14.     }
    15.  
    16.     public override void AddRenderPasses (ScriptableRenderer renderer, ref RenderingData renderingData) {
    17.         if (IsValidSettings() && IsValidCamera(ref renderingData))
    18.             renderer.EnqueuePass(pass);
    19.     }
    20.  
    21.     private bool IsValidSettings () {
    22.         return settings != null && settings.layerMask != 0;
    23.     }
    24.  
    25.     private bool IsValidCamera (ref RenderingData renderingData) {
    26.         var cam = renderingData.cameraData.camera;
    27.         return cam.cameraType == CameraType.SceneView || cam.CompareTag(cameraTag);
    28.     }
    29.  
    30.     [System.Serializable]
    31.     public class Settings {
    32.         public RenderPassEvent renderPassEvent = RenderPassEvent.BeforeRendering;
    33.         public LayerMask layerMask = 0;
    34.         public string bufferName = "_CustomBuffer";
    35.         public string lightModeTag = "Universal2D";
    36.         public ClearFlag clearFlag = ClearFlag.Color;
    37.         public Color clearColor = Color.clear;
    38.         public FilterMode filterMode;
    39.         public SortingCriteria sortingCriteria;
    40.         public Vector3 sortingAxis = Vector3.down;
    41.     }
    42.  
    43.     class Pass : ScriptableRenderPass {
    44.         private Settings settings;
    45.         private int layerMask;
    46.         private ShaderTagId lightModeID;
    47.         private RenderTargetIdentifier customBuffer;
    48.         private int customBufferID;
    49.  
    50.         public Pass (Settings settings) {
    51.             this.settings = settings;
    52.             layerMask = settings.layerMask;
    53.             renderPassEvent = settings.renderPassEvent;
    54.             lightModeID = new ShaderTagId(settings.lightModeTag);
    55.             customBufferID = Shader.PropertyToID(settings.bufferName);
    56.         }
    57.  
    58.         public override void OnCameraSetup (CommandBuffer cmd, ref RenderingData renderingData) {
    59.             var descriptor = renderingData.cameraData.cameraTargetDescriptor;
    60.             cmd.GetTemporaryRT(customBufferID, descriptor, settings.filterMode);
    61.             customBuffer = new RenderTargetIdentifier(customBufferID);
    62.             ConfigureTarget(customBuffer);
    63.             ConfigureClear(settings.clearFlag, settings.clearColor);
    64.         }
    65.  
    66.         public override void OnCameraCleanup (CommandBuffer cmd) {
    67.             cmd.ReleaseTemporaryRT(customBufferID);
    68.         }
    69.  
    70.         public override void Execute (ScriptableRenderContext context, ref RenderingData renderingData) {
    71.             var drawSettings = CreateDrawingSettings(lightModeID, ref renderingData, SortingCriteria.None);
    72.             var filterSettings = new FilteringSettings(RenderQueueRange.all, layerMask);
    73.             var sortingSettings = new SortingSettings(renderingData.cameraData.camera) {
    74.                 criteria = settings.sortingCriteria,
    75.                 customAxis = settings.sortingAxis,
    76.                 distanceMetric = DistanceMetric.CustomAxis
    77.             };
    78.             drawSettings.sortingSettings = sortingSettings;
    79.             context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filterSettings);
    80.         }
    81.     }
    82.  
    83. }
    84.  
     
    Last edited: Oct 11, 2023
  2. HenryCGS

    HenryCGS

    Joined:
    Dec 19, 2018
    Posts:
    3
    Bumping this as I'm still in the dark. We've updated Unity to 2022.3.11f1 and the issue persists.
    Additionally, we've found out that the issue also seems to happen on the Steam Deck, but we need to make some more tests to verify this.