Builtin Unity shaders source

Discussion in 'ShaderLab' started by Aras, Jun 21, 2006.

  1. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Messages:
    4,047
    Here's the sourcecode for all builtin Unity shaders (always at latest version): http://unity3d.com/download_unity/builtin_shaders.zip

    Unity 1.6.2 shaders, if you still need them, are here: http://unity3d.com/download_unity/builtin_shaders-1.6.2.zip

    The sourcecode is provided as a reference and for learning purposes. You don't need to put the shaders into your project; they're all builtin. If you do, be sure to modify shader name at start of the file, otherwise names will collide with the builtins.

    Also checkout UnityCG.cginc and AutoLight.cginc in Unity.app/Contents/CGIncludes - the builtin shaders use some helper functions/macros/variables from there.
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Messages:
    4,047
    Updated the above with Unity 1.5.1 builtin shaders source code (cleanups, small fixes, more fallbacks).
  3. joacoerazo

    joacoerazo

    New Member

    Joined:
    Apr 5, 2006
    Messages:
    214
    Thank you Aras

    This is must learn for me.
  4. Jessy

    Jessy

    New Member

    Joined:
    Jun 7, 2007
    Messages:
    7,173
    I seemingly did need to put these into my project, and I don't see any problems arising due to the names. Any reason for this? I guess I've been using Unity successfully in some kind of cripple state, but I have no idea what is going on.
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Messages:
    4,047
    No, you don't need to put them into your project. These are the sources if you want to develop your own shaders and want to take a look at how built-in ones are done.

    Presumably your Unity installation is corrupt (or maybe you're out of disk space?). Try reinstalling Unity.
  6. Jessy

    Jessy

    New Member

    Joined:
    Jun 7, 2007
    Messages:
    7,173
    For any other neophytes that seem to have this problem, just get out of debug mode and pick your shader then. Thanks, Daniel!
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Messages:
    4,047
    Updated with Unity 2.0 and 1.6.2 shaders.
  8. Jonathan Czeck

    Jonathan Czeck

    New Member

    Joined:
    Mar 17, 2005
    Messages:
    1,713
    When someone has a chance, could we please have the 2.1 shader update?

    Thanks,
    -Jon
  9. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Messages:
    3,522
  10. Jonathan Czeck

    Jonathan Czeck

    New Member

    Joined:
    Mar 17, 2005
    Messages:
    1,713
    Even better, thank you!
  11. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Messages:
    4,047
    Edited the initial post, now always links to latest shaders.
  12. minevr

    minevr

    New Member

    Joined:
    Mar 4, 2008
    Messages:
    1,009
    Thank you! :twisted:
  13. JonnyHilly

    JonnyHilly

    Member

    Joined:
    Sep 4, 2009
    Messages:
    581
    If I want to deliberately replace one of the builtin unity shaders with a slightly modified one, how would I do that ?

    If I add it to my project with the same name... which one will be used ?
    for example the vertex_lit shader that unity uses on the detail objects. like bushes and rocks.
  14. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    if you add your own one with the same name, yours will override the builtin one.

    thats how the SM3 enhanced terrain shader (showcase board) works :)
  15. JonnyHilly

    JonnyHilly

    Member

    Joined:
    Sep 4, 2009
    Messages:
    581
    awesome, thanks
  16. jcarpay

    jcarpay

    Member

    Joined:
    Aug 15, 2008
    Messages:
    408
    Last edited: Oct 1, 2010
  17. gfxguru

    gfxguru

    New Member

    Joined:
    Jun 5, 2010
    Messages:
    92
  18. Daniel Brauer

    Daniel Brauer

    Member

    Joined:
    Aug 11, 2006
    Messages:
    3,158
    As Aras said, the link in the first post always has the current shaders.
  19. HonoraryBob

    HonoraryBob

    Member

    Joined:
    May 26, 2011
    Messages:
    305
    I downloaded the file that contains the source code for the built-in shaders, but the (plain) "Specular Shader" isn't in there. I was hoping to see how it creates that beautiful, realistic glow which the other specular shaders in Unity don't seem to produce.
  20. andeeeee

    andeeeee

    Unity Technologies

    Joined:
    Jul 19, 2005
    Messages:
    8,729
    Welcome to the forum, HonoraryBob!

    The code for the Specular shader (at the root of the menu) is actually included in the archive but the filename is a bit misleading - it's in the Normal-Glossy.shader file.
  21. brn

    brn

    Member

    Joined:
    Feb 8, 2011
    Messages:
    291
    Hi Aras, Are the 3.5 beta shaders available? Im getting some requests to make my shader pack compatible to the new functionality.
    If I've missed a thread some where id be happily re directed to it.

    Cheers
    Brn
  22. Waz

    Waz

    Member

    Joined:
    May 1, 2010
    Messages:
    160
    Still not available?
  23. mindlace

    mindlace

    New Member

    Joined:
    Mar 31, 2007
    Messages:
    24
    How about the 3.5-release shaders?
  24. snaker

    snaker

    Member

    Joined:
    Feb 25, 2012
    Messages:
    11
    Thank you!
  25. Manuk

    Manuk

    New Member

    Joined:
    Jan 20, 2012
    Messages:
    2
    Does anyone else think that the files in there should have a header stating their version?

    Is the current file 3.5 already?

    Replacing the Internal-PrePassLighting.shader works, but not for cameras with HDR activated - there you get no lighting (all medium gray).

    Does this warrant a Bug-Report? Or does Aras monitor this thread?
  26. Manuk

    Manuk

    New Member

    Joined:
    Jan 20, 2012
    Messages:
    2
    Seems fixed now.

    I had a look at the file dates:
    A downloads from 9. March 2012 were probably built 13. February 2012 (date of folders in zip).
    The file I downloaded today 11. June 2012 was probably built 11. March 2012.

    It now is working with 3.5 as expected (e.g. including HDR paths in the prepass-lighting shader).

    It seems something in the deployment of the builtin-shaders package went wrong. Or is it always lagging a few months behind?
  27. Jtbentley_v2

    Jtbentley_v2

    New Member

    Joined:
    Sep 5, 2012
    Messages:
    174
    The download link on the first post is broken... ?
  28. breakeren

    breakeren

    New Member

    Joined:
    Jun 8, 2010
    Messages:
    1
    I cant download Either
  29. Nemox

    Nemox

    Member

    Joined:
    Feb 16, 2010
    Messages:
    370
    I also can't download any of the built-in shaders. The ones on the examples pages seem to be missing important parts, so this package is very important to me.
  30. Martin Kraus

    Martin Kraus

    Member

    Joined:
    Feb 18, 2011
    Messages:
    614
    Which URL are you referring to? This page: http://unity3d.com/support/resources/assets/built-in-shaders doesn't appear to have "examples" in its address. Which specific shader are you missing?
  31. DrakharStudio

    DrakharStudio

    New Member

    Joined:
    Mar 2, 2012
    Messages:
    4
  32. Chickenlord

    Chickenlord

    Member

    Joined:
    May 13, 2011
    Messages:
    381
  33. Manul

    Manul

    New Member

    Joined:
    Nov 30, 2012
    Messages:
    14
  34. MRKane

    MRKane

    New Member

    Joined:
    Oct 4, 2012
    Messages:
    1
    I think this is topic relevant, but including one of the internal shaders in the project doesn't seem to overwrite it's function, for instance "Hidden/Internal-Flare". Are there any notes on project behavior when trying to include these shaders as part of it?
  35. HaoEver1987

    HaoEver1987

    New Member

    Joined:
    Sep 29, 2012
    Messages:
    8
    Hi Aras, from DX11Examples-4.0.0b7.zip I have taken in many new ideas.
    But I find these shaders can not adjust shadow, do you have any idea?
    I'm going to write hair shader.
    Please contact me by Email: haoxutao88@126.com, thank you very much.
    Last edited: Apr 8, 2013
  36. MadM

    MadM

    New Member

    Joined:
    Mar 6, 2012
    Messages:
    9
    Hi,

    I just want to know if I am allowed legally to use these shaders code as source (and also with modifications) within my commercial Unity projects as long as I give them new names ? we have pro licences. Or is there some license restrictions (GPL or other) ?

    Best regards,

    Pierre
  37. Farfarer

    Farfarer

    Member

    Joined:
    Aug 17, 2010
    Messages:
    2,109
    You're free to use them in your Unity projects - they're here for reference and modifying :)
  38. rea

    rea

    Member

    Joined:
    Oct 10, 2009
    Messages:
    800
  39. alexzzzz

    alexzzzz

    Member

    Joined:
    Nov 20, 2010
    Messages:
    794
  40. FuzzyQuills

    FuzzyQuills

    Member

    Joined:
    Jun 8, 2013
    Messages:
    700
    Anyone know how to replace a cginclude? I am attempting custom shadow filtering, but I have no idea where to put the new autolight.cginc...
  41. guavaman

    guavaman

    Member

    Joined:
    Nov 20, 2009
    Messages:
    512
    Just paste the contents inside the CGPROGRAM. Or you can do an include if you have a lot of shaders that need to share it, include it like this in each:

    Code (csharp):
    1.  CGPROGRAM
    2.  #pragma debug
    3.  #pragma surface surf Lambert_AlphaTestGlowFix alphatest:_Cutoff
    4.  #include "includes/SurfaceOutputVtxC.cginc"
    5.  #include "includes/LightingModels.cginc"
    The path is relative to the shader file.
  42. Farfarer

    Farfarer

    Member

    Joined:
    Aug 17, 2010
    Messages:
    2,109
    If you want to replace the built-in ones I think you can place them in the root of your Assets folder?
  43. FuzzyQuills

    FuzzyQuills

    Member

    Joined:
    Jun 8, 2013
    Messages:
    700
    Actually, I worked it out: modified CG includes go into a folder named Resources, that way, they take effect on any shaders present in the folder once you restart unity