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

Uber Shader for Sprites (inc normal maps / emission / specular + more)

Discussion in 'Shaders' started by ToddRivers, Jan 5, 2017.

  1. ToddRivers

    ToddRivers

    Joined:
    Mar 15, 2013
    Posts:
    17
    In case its useful to anyone but I've put together an Uber Shader for rendering sprites and other alpha blended objects:

    https://github.com/traggett/UnitySpriteShaders

    It supports normal maps, specular, emission and a ton of other stuff, plus works with either multipass pixel lighting OR single pass vertex lighting. (Vertex lighting packs a lot of stuff into texture channels so it can approximate per pixel effects).
    It also supports rending back faces with corrected tangents.
    Anyways its free / open source so hopefully it might help some peops :)


     
    Adogus, Kokowolo, zIyaGtVm and 4 others like this.
  2. robotmechanic

    robotmechanic

    Joined:
    Dec 29, 2009
    Posts:
    106
    This looks great! Thanks for open sourcing this! :)
     
  3. antonkudin

    antonkudin

    Joined:
    Aug 4, 2014
    Posts:
    32
    Looking great! Is there a benefit to use this before Standard shader? Obviously theres few cool features, but if i replace my Standard shader material for sprites (I use normal and metallic maps) will there be a benefit? Performance boost?
     
  4. ToddRivers

    ToddRivers

    Joined:
    Mar 15, 2013
    Posts:
    17
    The main benefit is you can use vertex lighting which means rendering is done in a single pass.
    This is firstly quicker than mulit-pass based lighting unity's standard shader does, plus also means you can render sprites with sub meshes without getting any nasty overdraw from additional lights passes. This is normally the case with skeleton based animations like ones from Spine (Spine actually now ships with a version of these shaders!).

    Obviously nothing's free in programing so vertex lighting can be less accurate than forward based per pixel lighting, but if you're sprite mesh is generated with enough verts you won't notice the difference.
    You can also turn off what you don't use which will speed up the shader in comparison to the standard shader.

    I recommend playing around and seeing what works best - every project is different these shaders let you do some things the standard shader can't do but there will be times where the unity standard shader works and makes the most sense too!
     
  5. AlcyonGames

    AlcyonGames

    Joined:
    Sep 16, 2016
    Posts:
    39
    Hi!, is it possible to have a version for 5.6? Or is it compatible with Unity 5.6.X? We don't want to update Unity to 2017.X yet. THANKS!
     
  6. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,875
    This is a shader, you shouldnt really have to make different versions for different versions of unity until 2018 and SRP is out. Essentially, yes it will likely work.

    Also, 5.6 is way more unstable that 2017.3. All other 2017 releases were garbage but 2017.3 is well worth it, you should update unless you have a very good reason (i.e. tech that requires lower version of unity specifically)
     
  7. AlcyonGames

    AlcyonGames

    Joined:
    Sep 16, 2016
    Posts:
    39
    Thank you for the answer!
     
  8. Nyxo

    Nyxo

    Joined:
    Mar 12, 2013
    Posts:
    23
    So I started using this shader for the purposes of Depth of Field on SpriteRenderers, and it works perfectly for that! However, shortly thereafter, I started using Sorting Group Components, and noticed I was getting inconsistent results of either the Sorting Group working perfectly, or not at all. At first I thought it was something to do with the Sorting Group or my configuration or something, but if I only change the material for my SpriteRenderers back to Sprites/Default, the Sorting Group seems to consistently go back to working properly 100% of the time. This also happens if I simply disable the "Write to Depth" property on the material for these shaders. So now I'm inclined to believe this is an issue with these shaders, and specifically to do with literally the only feature I really wanted from them >_>

    Is this something you're aware of @LostInActon? My results are sorta consistent, but not very reproducable... It's really weird. But I have some local prefabs here that show the issue.

    This is all seen in Unity 2018.2.3f1, using a clone of the GIT repo for these shaders as of Sept 20 or so.
     
  9. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Is it possible to have it receive shadow?
     
  10. dfr1238

    dfr1238

    Joined:
    Jun 18, 2019
    Posts:
    1
    how to make Diffuse Ramp Work? have the sample?
     
  11. The_Dark_Swordsman

    The_Dark_Swordsman

    Joined:
    May 16, 2020
    Posts:
    6
    Big thanks! Still works great in 2022
    upload_2022-9-20_18-43-20.png upload_2022-9-20_18-43-22.png