Search Unity

Dissolve shader only for parts of the mesh

Discussion in 'Shaders' started by FellowPlayer123, Sep 13, 2021.

  1. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    114
    How to activate shader, namely some kind of disposable shader only for parts of the mesh, like belly or hands? The whole mesh is using one material.
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,549
    You would need a custom shader/material that has some way of knowing how to restrict the dissolve effect. Whether that's by being passed in analytic shape data to clip with, or reading from vertex colors to isolate the effect to.

    A shader can only do what it's programmed to do, it doesn't know about what another shader has done with the mesh data before, as the modifications done in a vertex and fragment shader only exist during that shader's invocation and are output as pixels to the graphics buffers, they don't alter the actual geometry.

    Typically games will have a "dissolve" variant of their shader they can enable to use the effect. Since most things that will be able to be dissolved will likely be using the same shader in the first place. There's an important distinction between shader and material here though. Materials merely hold values to apply to a given shader. So if you have 2 shaders with the same properties, but slightly different function (like dissolve effect added in the code), then you can simply change to the Dissolve shader on your material during runtime and everything will still render properly. (Though often Shader Keywords will be used for something like this in Unity).