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
  3. Dismiss Notice

Question How to make _CameraOpaqueTexture work with new 2D renderer

Discussion in 'Shader Graph' started by dr4, Jan 13, 2020.

  1. dr4

    dr4

    Joined:
    Jan 14, 2015
    Posts:
    106
    Hi,

    I spent a lot of hours trying to find a solution for this but all the results were very poor, so, I have a 2D glass effect in my game, the effect looks great but the problem is that I need the new 2D Renderer Data to work with the 2D lights, but as soon as I change the default used by Lightweight all my glass effect disappear and I just have a gray sprite instead of the effect with the sprite shape, it seems like the _CameraOpaqueTexture totally stops working, I also tried to have the 2 renderers working together with this Renderer list but that wouldn't work as only the one set to default and assigned to the camera have a result, so now it seems like I need to lose the glass effect to have the lights, could someone advice me please? this is a huge step back for me

    upload_2020-1-13_1-14-25.png

    upload_2020-1-13_1-20-35.png

    upload_2020-1-13_1-24-31.png
     

    Attached Files:

  2. Mucha505

    Mucha505

    Joined:
    Apr 19, 2015
    Posts:
    6
    Hi, I've had similar issue, where I needed to use _CameraOpaqueTexture to create gravity distortion effect and managed to make it work with 2D Renderer in URP, Unity 2019.3

    In this link https://unitylist.com/p/wsc/Shader-Graph-Experiments I've read that you can "create a second camera that renders to a texture and use that as a property instead of _CameraOpaqueTexture." and that' exactly what I've done:

    1. Create render texture
    2. Create secondary camera that display same content as main camera and set render texture to the texture you've just created.
    3. In shader graph use this render texture instead of _CameraOpaqueTexture

    Here is more detailed tutorial about render texture http://unity.grogansoft.com/in-game-security-camera-using-render-texture/
     
  3. dr4

    dr4

    Joined:
    Jan 14, 2015
    Posts:
    106
    Hey @Mucha505 ,

    I'm aware of the second camera solution, another solution based on that (which I think it is better than render to a texture) is create a second camera and apply the old renderer to it (the one that can see the _cameraOpaque), so you have one rendering all the 2D features and one more rendering the old features that Unity removed, still I find this very costly, and more considering that my camera have a fair amount of scripts and functionality, I will end up using that if unity keeps on delaying a fix for this but for now I'm waiting a miracle, still thank you for the solution!
     
  4. Teky

    Teky

    Joined:
    Aug 23, 2017
    Posts:
    8
    Any news on this fix? I am in the same situation and the second camera makes my game to drop the FPS a lot so it is not an option.
     
  5. dr4

    dr4

    Joined:
    Jan 14, 2015
    Posts:
    106
    not that I'm aware, and I look regularly, I had to remove all the _CameraOpaque effects of my game on trade for the 2D lights and I know some more developers who are struggling because of the same problem, I can't stress enough how much this is needed but for some reason Unity does not see it as a priority at all.
     
    tonytopper likes this.
  6. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    120
    You can apply these effects using a custom scriptable renderer feature. You can take Blit feature and pass from here and use your custom material to apply your effect, just keep in mind that it should be done after rendering transparents.
    I don't work with 2D, but I don't really see why camera opaque texture should work with sprites, since sprites are not opaque.
    If you need to use scene color in your object shaders rather that in a post effect, you can copy scene color to a custom render texture with a scriptable renderer feature similar to Blit mentioned above, and then render you objects with Render Objects scriptable renderer feature, this way their shaders will have access to your render texture containing scene color captured at a correct point. But these objects will be rendered on top of everything else.
     
    Last edited: Sep 1, 2020
  7. Teky

    Teky

    Joined:
    Aug 23, 2017
    Posts:
    8
    Thanks for your help, I have been trying to understand how this works for a while now, but I seem to have reached an impasse. In order to use a Renderer feature you need to be able to add a new feature to the renderer pipeline. If you are using the 2D forward renderer this is possible but for the experimental 2D renderer (The one with the beautifull 2D lights) this is not possible or at least not available. I really don´t know much about this topic so I might be completly wrong, but so far no luck for me.
    Thanks anyway!
     
  8. RedHillbilly

    RedHillbilly

    Joined:
    Mar 24, 2014
    Posts:
    38