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

Object highlight with shader on second material

Discussion in 'Shaders' started by mj321, Aug 23, 2016.

  1. mj321

    mj321

    Joined:
    Aug 23, 2016
    Posts:
    21
    Hello all,

    i'm a Unity beginner, so please bear with me.

    I'm trying to highlight an object. There are several shaders out there i've found, but i need something that i can add to any existing object, even if it already has custom shaders (which were not done by me).

    I'd like to use the shader shown here:


    My idea was to add a second material (which i could later do with a script) that just contains the glow shader. But whatever i try, i can't get the output from the second shader to show up transparently over the original output from the first shader.

    Is this something that's just impossible? Or does the shader in the 2nd material need to do something special in order to achieve this?

    Thanks.
     
  2. HNessReg

    HNessReg

    Joined:
    Aug 22, 2016
    Posts:
    4
    The first problem here is that the shader made in that video isn't transparent, it'll simply cover all of the previous material. You'll have to change the glow shader to support transparency. This mainly involves setting the queue tag to transparent, and outputting an alpha value.

    You can then add two materials to a single mesh through the mesh renderer in the inspector. Open the materials array and add in your glow shader. However this isn't recommended as Unity will quickly tell you. It apparently reduces performance and won't work if you have submeshes.

    Beyond that, I don't know what you can do that's within reason. You could perhaps at least make it easier to use in other shaders by writing it as an includable file. I'm curious if there's a method myself, but I'd more than likely prefer to just write a single shader specifically using all the functionality needed.
     
    mj321 likes this.
  3. mj321

    mj321

    Joined:
    Aug 23, 2016
    Posts:
    21
    Thanks, setting the queue tag to transparent was indeed the key thing i was missing. I still don't have exactly what i want, but i can work from here.