Search Unity

Question Multiple Shaders or Multi-functions shader?

Discussion in 'General Graphics' started by Tom-Kazansky, Jan 9, 2023.

  1. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    Hello,
    I want my game to have some shader effects like Dissolve, Petrification (turned into stone), Frozen (ice-covered)
    I wonder how I should approach this, I think of the following solution:

    1) Write multiple shaders, each one will handle one effect (so I will have 3 shaders for 3 effects)
    at runtime, I will swap the materials of the model when I need specific effect on it.

    2) Write a composite shader which will include all the effects (so I have 1 shader for 3 effects)
    at runtime, I will toggle/modify effect parameters of a model's material when I need specific effect on it.

    I actually have tried solution (1), it works but I feel it somehow inconvenient.

    the solution (2) seems to be more convenient but it could negatively affect performance since the "code" for the unused effects would have to be processed anyways.

    which solution do you think is better?

    note: I'm a newbie to shader so to do (2) I can only copy the shader (graph) code from separate shader (graph) into the composite one, I'm not sure it is performant. Also my game is mobile-oriented.
     
    Nintendo-Silence likes this.