Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to use "Material" input in Custom Render Textures

Discussion in 'General Graphics' started by Passeridae, Jun 26, 2020.

  1. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Hi!
    What do we need this input for?

    I mean, there's a line about it in the documentation which says "Material: Defines what shader is used to update the texture.", but it doesn't tell me much, unfortunately.

    What I've done so far: created a Custom Render Textures asset, made a shader which accepts two texture maps and blends them, put this shader into "Initialization mode > Source" input in the CRT asset, and everything works as expected. Now a CRT asset is a result of blending between these two textures and I can plug it itself as a texture into any other material or another CRT asset. But in order to do so, I need to have a material put into the "Material" input of the CRT asset, or it just doesn't work at all. Any material. I use a blank HDRP Lit Material for this purpose. So, what's the idea here?
     
  2. Astoret

    Astoret

    Joined:
    Jan 22, 2020
    Posts:
    7
    This is my understanding how it works:
    1. Unity initialize the CRT by texture from the "Initialization mode > Source". So your CRT and texture from Source will look the same
    2. Unity render the material and put the result in to your CRT. Lets say you have a material with shader which constantly changing all pixels to red color, so in result the material will be repaint to red and if you specify the material in "Material" field in CRT then the CRT will be repaint to red.

    The main benefit of CRT is working with the material shader. If you set "Double Buffered" checkbox to true it will allow you to access texture from previous pass it named _SelfTexture2D. So if your shader from the "Material" field in CRT changing all pixels from red in first frame in the second frame you will found _SelfTexture2D with all pixels set in red color.

    In some reason the CRT don't work on Android, at lest I didn't manage to make it work on Android so keep it in mind if your target platform is mobile devices.