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

Any way to apply shader/image effect to everything in a canvas?

Discussion in 'UGUI & TextMesh Pro' started by dgoyette, Mar 11, 2019.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    I've been working on a computer screen UI interface. Things were going pretty well as I was creating a shader to apply to the images on the screen, but then I realized the same shader won't work at all for TextMeshPro objects, and it won't look good for things like buttons or dropdowns (which seem to have weird UVs).

    So I figured there must be a way for me to pass the canvas as a while through my shader, in order to apply a consistent effect (distortion, chromatic aberration, warping) to the whole thing. But I don't see a way to do this.

    Could anyone suggest an approach to applying an effect to an entire canvas?

    Thanks.
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @dgoyette

    Warning - this is not tested. Just an idea.

    How about creating a screen space camera canvas and use it as your to be computer screen canvas.

    Make a separate camera for this canvas, and make it have a render texture asset as it's target texture.

    This way you can have your UI canvas neatly rendered in one texture.

    From this point onward, I have no idea how things work. I know one can assign a render texture to a material.

    There is also a custom render texture that supposedly can be passed to a shader (don't know how and if it works):
    https://docs.unity3d.com/Manual/class-CustomRenderTexture.html
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    That's a good point. I actually do exactly what you're describing for my player's HUD: I have a camera capturing a canvas, I send that camera to a render texture, and then I project that texture on a curved surface (the inside of the player's mask). With that approach, I can apply a custom masterial to the single image.

    The concern with using this approach more broadly is that having extra cameras is expensive. It's okay for my main HUD. But the case I'm trying to address deals with every TV/Computer screen in my game. Rooms might have lots of computers/screens with separate content on them. These screens tend to be prefabs, and I'm not even sure that I could get each to render to its own distinct render texture. But even if I could, having an extra camera rendering in the screen for every physical screen in my game seems like it would just kill performance. It's worth exploring a little more, though. Maybe a camera that only renders a single UI layer isn't so expensive, and I could afford to have many going at once.