Search Unity

Get the opaque texture of a second camera

Discussion in 'Universal Render Pipeline' started by Abrakidabra, Mar 11, 2020.

  1. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    I am trying to create a black hole gravitational lensing effect using the shader graph node "scene color". It works perfectly, but only when i am looking directly at the black hole.

    If, for example, I instead look directly at a star while the black hole is still in view, it will render the star's colour on the lens effect. It should only render the effect if its behind the black hole. The issue resolves itself if i am looking directly at the black hole however.

    So my idea is to create a second camera which looks at the blackhole directly at all times. I want to access only that second camera's opaque texture to use in my shader graph, and leave the first camera to do the normal camera stuff.

    Is it possible to access a second camera's opaque texture for scene color?
     
  2. pateman

    pateman

    Joined:
    May 3, 2014
    Posts:
    18
    I think that you can create a RenderTexture and make that second camera render to it, and then you can pass that RenderTexture as a parameter to your shader and sample it there. Just an idea.
     
    Abrakidabra likes this.
  3. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Thanks pateman I will try this
     
  4. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Unfortunately it breaks the effect in ways i dont understand :(

    I took some pictures of the problem to illustrate.
     

    Attached Files:

  5. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Thats the render texture result, im not that skilled at shaders so no sure whats up
     

    Attached Files:

  6. pateman

    pateman

    Joined:
    May 3, 2014
    Posts:
    18
    Probably the others won't be able to help without you posting more details about your configuration. Just snap some screenshots of the render texture setup and your shader graph. :)
     
  7. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62
    Yes sir, I just swapped out the scene colour with the render texture
     

    Attached Files:

  8. pateman

    pateman

    Joined:
    May 3, 2014
    Posts:
    18
    Hmm, I'm not an expert, but after a second thought, perhaps you don't really need that second camera at all. Mind sharing the original shader that used only a single camera? :)
     
  9. Abrakidabra

    Abrakidabra

    Joined:
    May 12, 2017
    Posts:
    62