Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Blitter.BlitCameraTexture seems to fail on VR devices when SPI.

Discussion in 'VR' started by emptybraces, Dec 11, 2023.

  1. emptybraces

    emptybraces

    Joined:
    Mar 30, 2015
    Posts:
    23
    I modified a blurring RendererFeature from the official manual.
    https://docs.unity3d.com/Packages/c...tainers/create-custom-renderer-feature-1.html

    Here is my code and capture video.
    https://github.com/emptybraces/Unity_URP_Stackable_UI_Blur

    upload_2023-12-12_5-41-15.png

    upload_2023-12-12_5-41-32.png
    It is fine on the editor, but when I check it in quest through OculusLink, it is instantly grayed out.
    I saw in the manual that cmd.Blit is not working, but is Blitter.BlitCameraTexture also same? I would like to know if there is a workaround. Or is there something wrong with the code...
    I'm use Unity 2022.3, 2023.2, SinglePassInstanced, XR Interaction Toolkit.
    Code (CSharp):
    1. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    2. {
    3.     if (renderingData.cameraData.camera.cameraType != CameraType.Game)
    4.         return;
    5.  
    6.     //Get a CommandBuffer from pool.
    7.     var cmd = CommandBufferPool.Get(nameof(ScreenBlurRenderPass));
    8.     using (new ProfilingScope(cmd, _profilingSampler))
    9.     {
    10.         var camera_target_handle = renderingData.cameraData.renderer.cameraColorTargetHandle;
    11.         Blitter.BlitCameraTexture(cmd, camera_target_handle, _grabRTHandle);
    12.  
    13.         cmd.SetGlobalTexture(_grabTexID, _grabRTHandle);
    14.  
    15.         UpdateBlurSettings();
    16.  
    17.         Blitter.BlitCameraTexture(cmd, camera_target_handle, _blurRTHandle1, _material, 0);
    18.  
    19.         Blitter.BlitCameraTexture(cmd, _blurRTHandle1, _blurRTHandle2, _material, 1);
    20.         cmd.SetGlobalTexture(_grabBlurTexID, _blurRTHandle2);
    21.  
    22.         if (param.IsApplyScreen)
    23.         {
    24.             Blitter.BlitCameraTexture(cmd, _blurRTHandle2, camera_target_handle);
    25.         }
    26.         else
    27.         {
    28.             CoreUtils.SetRenderTarget(cmd, camera_target_handle);
    29.         }
    30.     }
    31.  
    32.     //Execute the command buffer and release it back to the pool.
    33.     context.ExecuteCommandBuffer(cmd);
    34.     // cmd.Clear();
    35.     CommandBufferPool.Release(cmd);
    36. }
    UPDATE:
    Apparently cannot Blit to RTHandle unless the injection timing is set BeforeRenderingSkybox or less.
     

    Attached Files:

    Last edited: Dec 13, 2023
  2. tw00275

    tw00275

    Joined:
    Oct 19, 2018
    Posts:
    99
  3. emptybraces

    emptybraces

    Joined:
    Mar 30, 2015
    Posts:
    23
    Thank you for info! I see Acylic sample on v0.5.0 latest, left side of camera Acrylic sample is don't working, but right side Acrylic Fast sample is working. I'll dive into their code.
     
    Last edited: Dec 16, 2023
  4. emptybraces

    emptybraces

    Joined:
    Mar 30, 2015
    Posts:
    23
    In Acrylic scene, processing on the right side was textures were pre-blurred and then just clipped so it's not that real-time background blurred.
    But left side sample seems perfectly fine in Multi-pass mode, and even in my sample is working if Multi-pass.
    It seems that transparent objects cannot be grabbed in SPI mode. I changed thread title...
     
  5. emptybraces

    emptybraces

    Joined:
    Mar 30, 2015
    Posts:
    23
    SPI requires the following information in RenderTextureDescription.
    Now working.

    _blurTextureDescriptor.volumeDepth = 2;
    _blurTextureDescriptor.dimension = TextureDimension.Tex2DArray;
     
    tw00275 likes this.
  6. tw00275

    tw00275

    Joined:
    Oct 19, 2018
    Posts:
    99
    emptybraces likes this.