Search Unity

Question Sprite Lit Master and Vertex Color multiplication

Discussion in 'Shader Graph' started by Tom-Atom, Aug 22, 2019.

  1. Tom-Atom

    Tom-Atom

    Joined:
    Jun 29, 2014
    Posts:
    153
    Hi! In our game, when object is hit, it blinks in solid color. Some time ago I created shader for this and put tutorial on YoutTube (
    ). In that time we modified unlit Sprite Default shader.

    In short, it does not switch materials like other solutions, but is uses part of alpha range of Sprite Renderer's Color to signalize blink. Let's say you reserve alpha below 0.1 for blinking and shader remaps rest of alpha range (0.1 ... 1.0) to 0.0 ... 1.0, so you do not loose any alpha values. Blinking is preseted with solid non-transparent color. In other words, alpha is abused to pass additional per-vertex data, so batch is not broken and we can use single material for all sprites.

    Now, I wanted to add normal maps and 2D lights, so I added LWRP package and tried to modify Sprite Lit Default shader with Shader Graph to achieve the same result.This is how it looks:

    Blink Lit Shader.png

    I almost works. Problem is, that in very end of generated shader is this line:

    surf.Color *= IN.VertexColor;


    In shader I take all steps to create final fragment color. But shader adds multiplication of it with per-vertex sprite color from Sprite Renderer. Instead of solid blink color I get it partially transparent or even tinted:

    TintAlpha.png TintAlphaColor.png

    Is there any way how to avoid this last multiplication in Shader Graph? Or is it possible to modify input vertex color and output different one (for Sprite Lit Master)?

    I found the last multiplication is loaded into final shader from template files in folder \Library\PackageCache\com.unity.render-pipelines.lightweight@6.9.1\Editor\ShaderGraph\:
    - lightweightSpriteLitPass.template
    - lightweightSpriteForwardPass.template
    - lightweightSpriteUnlitPass.template

    It is also my current warkaround - just go into these files and comment out the line. But I would rather know how to do this directly in Shader Graph...
     
    danielbrm likes this.
  2. mateusthiago

    mateusthiago

    Joined:
    Dec 13, 2018
    Posts:
    4
    I do not have the answer for this, but this is the answer I've been looking for a problem very much like this.
    Instead of changing the template files I just changed it in the generated code from shader graph and saved it as a new shader.

    Thank you very much!
     
    Tom-Atom likes this.