Search Unity

Hacking the default sprite shader

Discussion in 'Shaders' started by imaginaryhuman, Nov 22, 2014.

  1. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I'm trying to write a custom version of the default sprite shader, because I want the benefit of working with the built in sprite sheets, colliders, tinting, etc... and will be modifying the output rgb values. But I need to be able to rely on the sprite's RGB values being exactly the same as they are in the source image file. I'm using the values as `data` to do some calculations so the numbers must not be modified. What concerns me is that in Unity 4.5, Unity changed to a `premultiplied alpha` shader, with GL_ONE, GL_ONE_MINUS_SRC_ALPHA as the blend mode. Does this not mean that somewhere along the pipeline, internally, Unity will multiply the RGB values by the sprite's Alpha value... so that in the shader I'm getting modified values and not the original image values? Like is the sprite system now hardwired to HAVE to use premultiplied a input?
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I kind of see what's happening with it now .. since the sprite shader has a tint color, the tint gets applied in the shader and then the shader multiplies rgb by the `final alpha` (alpha*alpha), and outputs that.. hence the GL_ONE in the blend.