Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Builtin Unity shaders source

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

  1. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
  2. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Last edited: Mar 5, 2015
  3. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    Thanks... but this link gives to me a 0kb file :/
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's a 206K file and works fine here.

    --Eric
     
  5. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    ha yes ! it's ok now ! :)
     
  6. unitarian411

    unitarian411

    Joined:
    May 30, 2012
    Posts:
    13
    Sadly the link in the original post by Aras no longer allows downloading of the Unity 5 standard shader source code. Instead it redirects to the full Unity downloads archive.
    Other links found by going through this thread or Googling for "Unity 5 Standard Shader source" also result in 404's or redirects to full Unity downloads.

    This link embedded in the docs does work as of Mar 17 2015:
    http://docs.unity3d.com/Manual/StandardShaderMakeYourOwn.html

    However, when I include these files in my asset folder, I get these three errors:

    Assets/builtin_shaders-5.0.0f1/Editor/StandardShaderGUI.cs(205,47): error CS0122: `UnityEditor.ShaderUtil.GetMaterialProperties(UnityEngine.Object[])' is inaccessible due to its protection level

    Assets/builtin_shaders-5.0.0f1/Editor/StandardShaderGUI.cs(205,17): error CS1502: The best overloaded method match for `UnityEditor.StandardShaderGUI.DetermineWorkflow(UnityEditor.MaterialProperty[])' has some invalid arguments

    Assets/builtin_shaders-5.0.0f1/Editor/StandardShaderGUI.cs(205,17): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEditor.MaterialProperty[]'


    As suggested by this post, I change the offending line from

    DetermineWorkflow( ShaderUtil.GetMaterialProperties(new Material[] { material }) );

    to this:

    DetermineWorkflow( MaterialEditor.GetMaterialProperties(new Material[] { material }) );

    And then, on running I get


    ArgumentException: Could not find MaterialProperty: '_Lightmapping', Num properties: 25
    UnityEditor.ShaderGUI.FindProperty (System.String propertyName, UnityEditor.MaterialProperty[] properties, Boolean propertyIsMandatory) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/ShaderGUI.cs:48)



    This post suggests:

    Delete ShaderGUI.cs from Assets/Shaders/Editor

    The downloaded StandardShader does not have a ShaderGUI.cs only a StandardShaderGUI.cs (the error does go away when I delete that file, but what else have I lost :)

    I would like to use an amended version of the Standard shader to allow for an Infrared shader which I will invoke using
    camera.SetReplacementShader( renderIR , null );
    So I intend to squirrel away a little extra data in my StandardWithIR.shader: a "IR Map" texture and a "IR" brightness scalar which the

    _IRMap( "IR", 2D ) = "black" {}
    _IRStrength( "IRStrength", Range(0.0, 1.0)) = 1.0


    But when I load my StandardWithIR.shader into an object material, I do not see these two vars in the editor (likely because it uses a custom editor/GUI like the file I just deleted...how to proceed ?)

    Thank you in advance !
     
    Last edited: Mar 18, 2015
  7. float

    float

    Joined:
    Jul 29, 2012
    Posts:
    42
    Just a quick question for the Unity5 Standard Shader:
    I see that HeightMap and Occlussion both have a "G" as feeding channel. Should that be Gray or Green?
    My tests show it works with both.

    To me that seems rather strange...
    When i use the Metallic Map that uses R+A i have two spare channels in that Texture (G+B) it would make sense to me if Occlusion would use Green and Height use Blue. That way i could put all the data in one single texture.

    Why is it designed the way it is? If one of the two would use blue it would still work with single maps and combined maps.
     
  8. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    182
    can't find standard shader anywhere now....
     
  9. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    why is this thread still here in its current form? Please update or remake it. The op is NINE years old and hideously out of date, it is worthless
     
  10. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    I was able to grab the unity 5 shader source... :D How is that outdated?

    If you meant that the first post's out of date... that's easy to fix. :)
     
  11. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    where is that actually? the U5 shader source is why i came to this thread in the first place

    It IS easy to fix. Someone at unity tech should just go fix it asap.
     
  12. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
  13. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    On this site, go to the top right click "Get Unity" then click "Free Download", then click "Windows", then click "For Windows" then choose "Built in shaders".

    http://netstorage.unity3d.com/unity/5a2e8fe35a68/builtin_shaders-5.0.1f1.zip

    Edit: FuzzyQuills beat my by 0.01 seconds. Note FuzzyQuills link is to the beta version, so that may no be what you want.
     
  14. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Heh... must be too speedy! :D I actually didn't know that either.
     
  15. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    thanks

    i've got to ask another question though

    Since these shaders are already in the uniy engine, why do i need to download the sources seperately?
    On any custom written shader i can hit the cogs button and select Edit Shader, but with the built in ones, the cog button is greyed out :(
     
  16. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422

    Hehe, I think you just answered your own question :) - since the source is not distributed with Unity, if you want to edit/customise a built in shader you need to source.
     
  17. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Let's combine these two... :D

    Essentially, the built-in shaders are built-in. Literally. So you can't really modify them, hence what Larku said; you will need to use the shader sources to modify them. Then you simply place the newly modified versions into the Unity project you're working on. (You don't need to import all of them though, just the ones you have customized)

    .cginc files are a little different to this rule; after modifying a .cginc, you can either:
    1. place it into a folder in your project called "Resources" (Has to be in there for Unity to detect it)
    2. replace the global .cginc file in the Unity program folders. (I don't recommend this)
    And restart unity for the changes to take effect. :)
     
  18. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    For adding stuff to the standard shader and it's GUI I have found a couple of useful tricks:
    1: Ofc you need to fix the compiler error, and others here have shown how to do so:
    2: I make all non-handled parameters be shown as normal:
    Code (CSharp):
    1. public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] props)
    2. {
    3.     base.OnGUI (materialEditor, props);
    In addition to the 1 line additon I have set [HideInInspector] tags to all shader parameters already in the standard.shader.

    These things allow me to do stuff like:
    Code (CSharp):
    1.  
    2. [Header(Enviorment Stuff)][Toggle(_WETNESS_OFF)] _PREVENT_WETNESS ("Prevent Wetness?", Float) = 0
    3. [Toggle(_ENVIORMENTAL_EFFECT_OFF)] _PREVENT_ENVIORMENTAL_EFFECT ("Prevent Coverage effects?", Float) = 0
    4. [Toggle(_GROUND_OBJECT)] _GROUND_OBJECT ("Ground?", Float) = 0
    5.        
    6. [Header(Stencil Stuff)][Enum(UnityEngine.Rendering.CompareFunction)] _StencilCompFunc ("Stencil Comp Func", Int) = 8
    7. [Enum(UnityEngine.Rendering.StencilOp)] _StencilOp ("Stencil Op", Int) = 0
    8. _StencilRefValue ("Stencil Ref", Int) = 0
    WITHOUT having to further modify the StandardShaderGUI !
     
  19. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    a436t4ataf, Junuxx, levlaj and 3 others like this.
  20. rustinlee

    rustinlee

    Joined:
    May 31, 2014
    Posts:
    20
    The link in the 9 year old OP is still correct, lol
     
  21. Slim_d0g

    Slim_d0g

    Joined:
    Jan 20, 2017
    Posts:
    1
    Hi there. I want to replace standard shader with modified one. So I've downloaded sources, copied Standard.shader into my project as CustomStandard.shader and changed shader name.
    Then I set this shader for camera using camera.SetReplacementShader(customShader, null);
    And all I see is a black screen.
    If I pass builtin standard shader into SetReplacementShader function, scene is rendered just fine.

    Can anyone help me?
     
  22. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    the image below is not mine, but I don't remember where I took it from

     
    Last edited: Feb 14, 2019
  23. GalleanV

    GalleanV

    Joined:
    Apr 1, 2013
    Posts:
    1
  24. dandepeched

    dandepeched

    Joined:
    Feb 22, 2016
    Posts:
    31
    Does anyone know where to find source for "GUI/Text Shader"?
    This is the only default shader that allow to change Source Image tint by it's own Color field.
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    See the first post in this topic; it has a link for shader downloads.

    --Eric
     
  26. dandepeched

    dandepeched

    Joined:
    Feb 22, 2016
    Posts:
    31
    Yes, I saw it and downloaded the latest one, but there is no such shader.
    Also it is not in the latest 5.x, 4.x archives.
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If it's built into Unity, it's included in the download. It's not necessarily called "GUI/Text" as the file name; that's just what the shader is called internally.

    --Eric
     
    dandepeched likes this.
  28. dandepeched

    dandepeched

    Joined:
    Feb 22, 2016
    Posts:
    31
    Thanks for the tip!
    I found it by opening shaders one by one. It is located in "\DefaultResources\Font.shader"
     
  29. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    972
    Hi,
    I have just downloaded the most recent shader pack for 2017.3.
    I have problems with StandardShaderGUI editor script, which generates editor errors:
    `UnityEditor.EditorGUIUtility.TextContent(string)' is inaccessible due to its protection level
    I can't also see fields for the new standard shader features like "roughness".
    Any help appreciated.
     
  30. alpahbeta2000

    alpahbeta2000

    Joined:
    Sep 11, 2013
    Posts:
    9
    I've got builtin shader packs for 20170.3.1p4 and 2018.1.5f1
    Both of them have error "error CS0122: `UnityEditor.EditorGUIUtility.TrTextContent(string, string, UnityEngine.Texture)' is inaccessible due to its protection level":(:(
     
  31. Cortex-Productions

    Cortex-Productions

    Joined:
    Jul 25, 2012
    Posts:
    2
    Same problem here with Unity 2017.4.5f1 builtin shaders:

    "StandardShaderGUI.cs(267,42): error CS0122: `UnityEditor.EditorGUIUtility.TextContent(string)' is inaccessible due to its protection level"
     
  32. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    Search up on c# System.Reflection on youtube
     
  33. jgeibel

    jgeibel

    Joined:
    May 5, 2016
    Posts:
    7
    And do what? This is a compiler warning from the Editor.

    We are also seeing the same thing with Unity 2018.1.8f1,

    Assets/Pluto/Shaders/BuiltIn/Editor/StandardShaderGUI.cs(33,59): error CS0122: `UnityEditor.EditorGUIUtility.TrTextContent(string, string, UnityEngine.Texture)' is inaccessible due to its protection level
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    He's telling you to use reflection to call the internal method that is inaccessible. You'd have to change the code. The shader pack's editor scripts must have been inside the UnityEditor.dll assembly so it had access to internal methods. Either that or in an assembly marked as a friend assembly. The only way you'll be able to call this method is through reflection.
     
    Last edited: Aug 7, 2018
    PabloHassahn likes this.
  35. jgeibel

    jgeibel

    Joined:
    May 5, 2016
    Posts:
    7
    Ah, I get it. I assumed that when I downloaded the zip of Built in shaders for 2018.1.8 from their website [1] that they would work without modification.

    [1] https://unity3d.com/get-unity/download/archive
     
    BradZoob likes this.
  36. jgeibel

    jgeibel

    Joined:
    May 5, 2016
    Posts:
    7
    I found it was much simpler to just replace all these calls to EditorGUIUtility.TrTextContent("") with new GUIContent("").
     
  37. khlorghaal

    khlorghaal

    Joined:
    Nov 15, 2018
    Posts:
    9
    I would REALLY like if we could get complete docs and examples of shader builtin functionality instead of having to reference the standard shaders.
    The way things are scattered throughout files makes learning from them very inefficient and intimidating, with lots of chance to miss important things.
     
    AverageCG and Necronomicron like this.
  38. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    Four years later ... still no online[1] version of shader sources (I thought there was an official one, but I can't find it, only unofficial ones - and this thread doesn't provide one).

    And, because SO MANY devs need this, there's a LOT of out-of-date github and gist online versions.

    So ... because Unity can't/won't put the shader sources online they've created a worse situation where people are referencing out-of-date / incorrect shader source :(. Please could someone at Unity put this stuff online? :)

    [1] - i.e. something online where you can see the shader source. A zip file is not that, a zip file is something you have to download, save, wait, unzip, wait, open a new IDE, wait for it to index, start a search/replace, ... and FINALLY you can see the source. Compare that to: visit github project, open the file you want OR search for shader-macros directly and it works immediately. One of these things is ridiculously slow, the other is almost instant :).
     
    alexzzzz likes this.
  39. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    One of those is mine :)

    I think this can even be done automatically:

    1. Parse https://unity3d.com/get-unity/download/archive for all the builtin_shaders-xxx.zip links.
    2. Download the new ones

    for each of them:
    3. Use git or hg command line to select the proper version branch
    4. Clean up the working folder
    5. Extract the zip
    6. Commit the changes

    7. Push
     
    a436t4ataf likes this.
  40. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    972
    Unity Standard shader and Unity Standard Specular shader use StandardShaderGUI.
    And this is inside the shaders source.

    Where can other shaders GUI be found?
    Actually I need AutodeskInteractiveShaderGUI and this can not be found there.
     
  41. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    You can find that class inside of UnityEditor.dll. This is an non-obfuscated managed code DLL so you can view all the source in it.
     
    edwiz7 and tomekkie2 like this.
  42. TOES

    TOES

    Joined:
    Jun 23, 2017
    Posts:
    134
    Always?

    Funny, because the link is dead now...
     
  43. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    No it's not. Link works perfectly fine. Maybe there was a service outrage for a minute with their server or your connection.