1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Builtin Unity shaders source

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

  1. Alesk

    Alesk

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

    FuzzyQuills

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

    Alesk

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

    Eric5h5

    Volunteer Moderator Moderator

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

    --Eric
     
  5. Alesk

    Alesk

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

    unitarian411

    Joined:
    May 30, 2012
    Posts:
    12
    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:
    16
    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:
    103
    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,807
    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,807
  13. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,168
    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,807
    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,168

    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,807
    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:
    657
  20. rustinlee

    rustinlee

    Joined:
    May 31, 2014
    Posts:
    5
    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?