Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Multiple Materials for Multiple Effects?

Discussion in 'Shaders' started by lvictorino, Aug 25, 2014.

  1. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    Hi there,

    I'm kind of new to the mighty world of shaders so please excuse the naiveness of this topic.

    I'm in the context of a pixel art game where, let's say, players can drive 2D cars with guns on their rooftops. At the beginning of the game every player can choose the color of his car. As all cars use the same sprite (a grayscale one) I use a swap palette shader to change colors properties. Everything works fine so far.

    Now, when players shoot, I animate the guns on cars' rooftops to fire bullets. I'd like to add a "fake" lighting effect on the car sprite to give some visual credibility to the shot.

    I've planed to use a one line texture with a gradient going from black to white to cover the sprite, and then write a shader to multiply car sprite colors by the one line sprite colors. Then the left of the car should be darker than the right.

    - PAUSE HERE -
    As I'm not 100% sure of what I'm doing I'd like to have your opinion on that method too... Is it the right way to perform what I want to achieve? Any better idea?
    - UNPAUSE -

    So everything seems fine except that Unity 4.6 (beta) seems to not offer the possibility to add multiple materials to a SpriteRenderer.

    Naturally I came to ask myself is Multiple Material was a good idea and if it was how I could to combine effects...

    Do I have to do everything in the same shader (the one swapping palettes)? It seems unproductive...
    Is there a way to combine shaders on a SpriteRenderer? Apparently it's possible to duplicate material entry... but nothing appears in the Editor... Bug?
    If I had another material to the car sprite, is there a way that my shader uses the result of the previous material work? I mean... the car sprite are in grayscale, if I add another material to the SwapPalette one I use, is there a way to receive as _MainTex the colored sprite resulting of the SwapPalette shader used? How?

    Thanks for your help and advice.
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I'm not sure whether multiple material support was meant to be removed from sprites. I can't think of a good reason why it would be missing when it's on every other Renderer.

    As far as I know, there is essentially no difference in performance between one Renderer with two materials, and two Renderers with separate Materials that share the same mesh.
     
  3. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    Hey Daniel, thanks for your answer.
    I'm going to contact support to be sure that Multiple Materials not accessible in the Editor is a bug (by the way, have you tried on your version of Unity to confirm that it's not a local problem I may have only on my machine?).

    So having multiple material to perform what I want to do ( swap palette + fake lighting to simulate gun shot) seems correct to you, Right? How to work with the colors resulting of the first material in the second one?
     
  4. Pablomon

    Pablomon

    Joined:
    Mar 9, 2015
    Posts:
    40
    Did they ever reply?
     
  5. treecki

    treecki

    Joined:
    Feb 6, 2017
    Posts:
    28
    Still can't seem to change the Sprite Renderer to have multiple materials in Debug mode. Is this going to be fixed?
     
  6. Bit_Rot

    Bit_Rot

    Joined:
    Dec 4, 2018
    Posts:
    4
    Any word on this 4.5 year old, crippling issue? Still looks very much broken.
     
    emredesu and ghallo-K like this.
  7. dvdarias

    dvdarias

    Joined:
    Sep 24, 2014
    Posts:
    12
    In my experience, as of Unity 2019.3, you can not set multiple materials on the SpriteRenderer normal/debug inspector.

    You can set multiple materials via the field
    Renderer.materials
    but as soon as you change any parameter in the SpriteRenderer (Sprite, Flip, Color, etc.) it automatically resets the list to only one material, making it useless.
     
  8. Sudden62

    Sudden62

    Joined:
    May 3, 2017
    Posts:
    11
    I wanted to confirm this as well, for Unity 2019.4. It's silly because Unity seems to take and apply the shaders of the materials in the order they are placed in the Materials array, so the functionality is there. Although it may be buggy because I got this to work for one object but not another using the exact same materials.