Search Unity

Resolved Different materials (with the same shader) display what the same camera shows.

Discussion in 'General Graphics' started by Volchok, Sep 7, 2021.

  1. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Hi!

    I have a material that displays on itself what the camera shows. With one camera and one material, everything is fine. But as soon as I make a copy of the material and assign it a rendering from the second camera (which is located in a completely different place), it still displays to me what the first camera shows.


    Maybe something is wrong in the shader. :rolleyes:

    Help me understand why this is happening?

    What should I do so that the second material (just a copy of another one, but with the same shader) displays what the second camera shows?

    Thanks!

    GrabScreenTexture:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [ExecuteInEditMode]
    4. public class GrabScreenTexture : MonoBehaviour {
    5.  
    6.     public Material mat;
    7.  
    8.     public void OnPostRender() {
    9.  
    10.         RenderTexture screenRT = RenderTexture.GetTemporary(
    11.             Screen.width,
    12.             Screen.height,
    13.             0
    14.         );
    15.  
    16.         Graphics.Blit(null, screenRT);
    17.  
    18.         mat.SetTexture("_ScreenTex", screenRT);
    19.  
    20.         RenderTexture.ReleaseTemporary(screenRT);
    21.     }
    22. }
    If disable the first camera, then there is no display on the first portal, and the second portal renders what I need - the image from the second camera. If I change the depth of the second camera to a greater (or equal) depth than the first camera, then the image of the second camera is shown on both portals.

    Is it possible to make different materials show the image only of their cameras?

    If all this is implemented with Target Texture according to the classical scheme, as here:

    Everything works, but with simple squares.
     
    Last edited: Sep 7, 2021
  2. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I found a way to solve the problem. The question is closed.