Search Unity

[Solved] Changes to customized UnityStandardInput.cginc are ignored?

Discussion in 'Shaders' started by phlake, Jul 14, 2018.

  1. phlake

    phlake

    Joined:
    Jun 20, 2018
    Posts:
    3
    I am trying to make a small change to the standard shader to add an additional additive color to Emission. However, my changes seem to have no effect. I am surely missing something obvious, but I'm a noob and I don't know what I could have missed. Here's what I've done:

    After downloading the built-in shaders source matching the version of Unity that I'm using (2018.1.1f1), I created a new folder named "Shaders" in my Assets. I copied two files from the downloaded source to my new Shaders folder: Standard.shader (from DefaultResourcesExtra) and UnityStandardInput.cginc (from CGIncludes).

    I renamed the file Standard.shader to CustomStandard.shader.

    I then edited the CustomStandard.shader file, making three small changes. First, I renamed the shader at the top of the file:

    Code (csharp):
    1. Shader "CustomStandard"
    Then I defined my new emission-related property at line 32 near the existing emission properties:

    Code (csharp):
    1. _EmissionExtraColor("Extra Color", Color) = (0,0,0)
    Finally, at the bottom of the file I commented out the CustomEditor:

    Code (csharp):
    1. //CustomEditor "StandardShaderGUI"
    Next I moved on to edit my copy of UnityStandardInput.cginc to modify the emission calculation. First I defined my new property (placing it near the two existing emission properties at line 52):

    Code (csharp):
    1. half4       _EmissionExtraColor;
    and then I modified the return value of the Emission(...) function at line 199:

    Code (csharp):
    1. return tex2D(_EmissionMap, uv).rgb * _EmissionColor.rgb + _EmissionExtraColor.rgb;
    Back in the Unity editor, I modify a model to choose my CustomStandard shader and I can see that the shader's CustomEditor is definitely gone and my new property is present and I can edit and define _EmissionExtraColor. However, doing so has no visible effect on the model.

    As a sanity check, I returned to UnityStandardInput.cginc and modified the Emission(...) return value again to simply return 0 (my test model has an emission map defined so it will be immediately apparent in the Unity editor if the emission map is ignored):

    Code (csharp):
    1. return 0; //return tex2D(_EmissionMap, uv).rgb * _EmissionColor.rgb + _EmissionExtraColor.rgb;
    Back in the Unity editor, the sanity check fails. The emission map appears on the model like usual. So it seems like my changes to CustomShader.shader show up in Unity but my changes to UnityStandardInput.cginc are ignored. Why might that be?
     
  2. phlake

    phlake

    Joined:
    Jun 20, 2018
    Posts:
    3
    I figured this out. The problem is that UnityStandardInput.cginc is not directly included by CustomStandardShader.shader -- instead it is the other *.cginc files that include it, such as UnityStandardMeta.cginc. But I am not overriding those files.

    I copied all of the files from CgIncludes to my Assets/Shaders folder, and now my changes to UnityStandardInput.cginc are showing up as expected.
     
  3. Haymun

    Haymun

    Joined:
    Sep 14, 2017
    Posts:
    1
    Legend.