Search Unity

Can I view full built in shader source?

Discussion in 'Shaders' started by Bas-Smit, Dec 17, 2014.

  1. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    When writing shaders in Unity it is often useful to view the built in source. Problem is that a lot is going on under the hood, which forces you to dig through the cginc files and compiled shaders. Is there any way I can get to the full cg source? Ie after all the surface shader boiler plate has been added but before the shader is optimized and compiled to the platform specific formats?

    Thanks, Bas
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  3. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    Thanks, but those are just the surf functions, I'm looking for the surf functions along with all the surface shader boilerplate, ie the bulk of the code. Some of which can be found in the various cginc files, but reconstructing a functional shader is a very painstaking process of piecing together the surf functions, snippets from the cginc files, and manually decompiling gles shaders to recreate the actual vert and frag programs.
     
    Last edited: Dec 17, 2014
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    In Unity, select a surface shader and click "show generated code" in the inspector. You'll see all the passes and a lot of the compiled Cg. They still make reference to stuff in Lighting.cginc, AutoLight.cginc, UnityCG.cginc, but you won't be left guessing what any of the intermediate parts are.
     
    oferei likes this.
  5. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    Ahhh, I missed that little button, thanks so much