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

Help with: Simple Shader to Blit Camera RT to my custom RT

Discussion in 'Shaders' started by LB_Chris, Feb 26, 2020.

  1. LB_Chris

    LB_Chris

    Joined:
    Jan 29, 2020
    Posts:
    33
    Hey there, I have never really come in touch with shaders but came up with a really simple Idea which might be doable via shaders or might not, I hope you can tell me.

    QUESTION: How do I copy the content of the RenderTexture of my main rendering camera to another RenderTexture in URP (by calling Blit?)? I am using Vulkan and developing for Oculus Quest. Is it even possible then? Also since I have never written shaders (though I know some basics), can someone link me a really simple tutorial to utilize a shader?


    BACKGROUND: At the moment I am doing exactly this inside a CustomRenderPassFeature. I just upgraded to Vulkan to utilize the AsyncGPUReadback which sadly is not available on OpenGL. That works fine when using Multipass but creates weired stuff for Multiview and I currently have identified my CRPF to be the curlpit (Vulkan support for URP just came out so it might be fixed sooner or later).
     
  2. unityuserunity85496

    unityuserunity85496

    Joined:
    Jan 9, 2019
    Posts:
    89
    I can't answer much for you. This place is a desert for answers and MORE so for what you'll have to journey into, but you'll need to get to grips with command buffers. I have a few posts that go over harder nuance trying to use them. My most recent does cover your task I think. The commented out code is the RT way of doing things you'll find but I have found that it clashes when I use two. ANYhoo

    None is optimized in this snippet.

    Heres a snippet

    Code (CSharp):
    1.  
    2.  
    3.      
    4.           _oooopsTexture = new RenderTexture(Screen.width, Screen.height, 16, RenderTextureFormat.ARGB32);
    5.  
    6.  
    7.           CommandBuffer opaques_MagicBuffer = new CommandBuffer();
    8.           opaques_MagicBuffer.name = "Colorzzzzzz as defaults render";
    9.  
    10.           // colorTexIDOpaques = Shader.PropertyToID("_Opaques_render");
    11.           // opaques_MagicBuffer.GetTemporaryRT(colorTexIDOpaques, -1, -1, 24, FilterMode.Bilinear);
    12.           // // DONT set the render target, thats what breaks the texture
    13.           // // opaques_MagicBuffer.SetRenderTarget(colorTexIDOpaques);
    14.           // // opaques_MagicBuffer.GetTemporaryRT(colorTexIDOpaques, originalTextureDescriptor);
    15.           // opaques_MagicBuffer.Blit(BuiltinRenderTextureType.CurrentActive, colorTexIDOpaques);
    16.           // opaques_MagicBuffer.SetGlobalTexture("_opaques_RenderOut", colorTexIDOpaques);
    17.  
    18.  
    19.           // alternative non RT Render Texture
    20.  
    21.           // DONT set the render target, thats what breaks the texture
    22.           // opaques_MagicBuffer.SetRenderTarget(colorTexIDOpaques);
    23.  
    24.           opaques_MagicBuffer.Blit(BuiltinRenderTextureType.CurrentActive, _oooopsTexture);
    25.           opaques_MagicBuffer.SetGlobalTexture("_opaques_RenderOut", _oooopsTexture);
    26.  
    27.  
    28.           _cam.AddCommandBuffer(CameraEvent.AfterForwardOpaque, opaques_MagicBuffer);
    29.  
    30.  
     
  3. LB_Chris

    LB_Chris

    Joined:
    Jan 29, 2020
    Posts:
    33
    Thank you for your answer. I have come across that approach aswell, but sadly it doesn't work for me either (I tried your code and played around with it for a bit. The RT receives a black texture). I cannot say for sure what causes that circumstance, but I guess it still might have something to do with Vulkan, maybe only in combination with URP?

    Either way, we have come to the conclusion to wait for a month or two to let Unity work on the matter of Vulkan (+URP) and then continue working on that matter.
     
  4. unityuserunity85496

    unityuserunity85496

    Joined:
    Jan 9, 2019
    Posts:
    89
    The other issue could be the Hardware directly. I have not been able to solve getting those command buffers to work with Vuforia AR on ipad. They make for a world of artifacts any way I try to send textures to the screen. Unity is REALLLLLLLY bad at documenting advanced things like Command Buffers and adding ANY extra elements is gonna be next to impossible at times

    Have the fun!!!
     
  5. LB_Chris

    LB_Chris

    Joined:
    Jan 29, 2020
    Posts:
    33
    Yup, I can kind of confirm that. The only positive I can see there is that they might spend more ressources on the development then :p

    Have fun, too :)