Search Unity

Modified shaders of LWRP resets to the original version after I restart unity

Discussion in 'Universal Render Pipeline' started by Danielsantalla, Nov 12, 2019.

  1. Danielsantalla

    Danielsantalla

    Joined:
    Jan 7, 2015
    Posts:
    75
    Hello guys,

    I'm a absolute beginner with shaders and LWRP but I'm trying to modify de unlit shader of the LWRP to make it cast shadows. So far I've managed to make it work and indeed, it does casts shadows but after I turn off my pc, everything seems to reset to factory preset, don't know why. I'm using Unity 2019.1
    Here is the code for the shader:

    Code (Boo):
    1. Shader "Lightweight Render Pipeline/Unlit"
    2. {
    3.     Properties
    4.     {
    5.         _BaseMap("Texture", 2D) = "white" {}
    6.         _BaseColor("Color", Color) = (1, 1, 1, 1)
    7.         _Cutoff("AlphaCutout", Range(0.0, 1.0)) = 0.5
    8.  
    9.         // BlendMode
    10.         [HideInInspector] _Surface("__surface", Float) = 0.0
    11.         [HideInInspector] _Blend("__blend", Float) = 0.0
    12.         [HideInInspector] _AlphaClip("__clip", Float) = 0.0
    13.         [HideInInspector] _SrcBlend("Src", Float) = 1.0
    14.         [HideInInspector] _DstBlend("Dst", Float) = 0.0
    15.         [HideInInspector] _ZWrite("ZWrite", Float) = 1.0
    16.         [HideInInspector] _Cull("__cull", Float) = 2.0
    17.      
    18.         // Editmode props
    19.         [HideInInspector] _QueueOffset("Queue offset", Float) = 0.0
    20.      
    21.         // ObsoleteProperties
    22.         [HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
    23.         [HideInInspector] _Color("Base Color", Color) = (0.5, 0.5, 0.5, 1)
    24.         [HideInInspector] _SampleGI("SampleGI", float) = 0.0 // needed from bakedlit
    25.     }
    26.     SubShader
    27.     {
    28.         Tags { "RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "LightweightPipeline" }
    29.         LOD 100
    30.  
    31.         Blend [_SrcBlend][_DstBlend]
    32.         ZWrite [_ZWrite]
    33.         Cull [_Cull]
    34.  
    35.         Pass
    36.         {
    37.             Name "Unlit"
    38.             HLSLPROGRAM
    39.             // Required to compile gles 2.0 with standard srp library
    40.             #pragma prefer_hlslcc gles
    41.             #pragma exclude_renderers d3d11_9x
    42.  
    43.             #pragma vertex vert
    44.             #pragma fragment frag
    45.             #pragma shader_feature _ALPHATEST_ON
    46.             #pragma shader_feature _ALPHAPREMULTIPLY_ON
    47.  
    48.             // -------------------------------------
    49.             // Unity defined keywords
    50.             #pragma multi_compile_fog
    51.             #pragma multi_compile_instancing
    52.  
    53.             #include "UnlitInput.hlsl"
    54.  
    55.             struct Attributes
    56.             {
    57.                 float4 positionOS       : POSITION;
    58.                 float2 uv               : TEXCOORD0;
    59.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    60.             };
    61.  
    62.             struct Varyings
    63.             {
    64.                 float2 uv        : TEXCOORD0;
    65.                 float fogCoord  : TEXCOORD1;
    66.                 float4 vertex : SV_POSITION;
    67.  
    68.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    69.                 UNITY_VERTEX_OUTPUT_STEREO
    70.             };
    71.  
    72.             Varyings vert(Attributes input)
    73.             {
    74.                 Varyings output = (Varyings)0;
    75.  
    76.                 UNITY_SETUP_INSTANCE_ID(input);
    77.                 UNITY_TRANSFER_INSTANCE_ID(input, output);
    78.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
    79.  
    80.                 VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
    81.                 output.vertex = vertexInput.positionCS;
    82.                 output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
    83.                 output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z);
    84.              
    85.                 return output;
    86.             }
    87.  
    88.             half4 frag(Varyings input) : SV_Target
    89.             {
    90.                 UNITY_SETUP_INSTANCE_ID(input);
    91.  
    92.                 half2 uv = input.uv;
    93.                 half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv);
    94.                 half3 color = texColor.rgb * _BaseColor.rgb;
    95.                 half alpha = texColor.a * _BaseColor.a;
    96.                 AlphaDiscard(alpha, _Cutoff);
    97.  
    98. #ifdef _ALPHAPREMULTIPLY_ON
    99.                 color *= alpha;
    100. #endif
    101.  
    102.                 color = MixFog(color, input.fogCoord);
    103.  
    104.                 return half4(color, alpha);
    105.             }
    106.             ENDHLSL
    107.         }
    108.  
    109.         Pass
    110.         {
    111.             Tags{"LightMode" = "DepthOnly"}
    112.  
    113.             ZWrite On
    114.             ColorMask 0
    115.  
    116.             HLSLPROGRAM
    117.             // Required to compile gles 2.0 with standard srp library
    118.             #pragma prefer_hlslcc gles
    119.             #pragma exclude_renderers d3d11_9x
    120.             #pragma target 2.0
    121.  
    122.             #pragma vertex DepthOnlyVertex
    123.             #pragma fragment DepthOnlyFragment
    124.  
    125.             // -------------------------------------
    126.             // Material Keywords
    127.             #pragma shader_feature _ALPHATEST_ON
    128.  
    129.             //--------------------------------------
    130.             // GPU Instancing
    131.             #pragma multi_compile_instancing
    132.  
    133.             #include "UnlitInput.hlsl"
    134.             #include "DepthOnlyPass.hlsl"
    135.             ENDHLSL
    136.         }
    137.  
    138.             Pass
    139.         {
    140.             Name "CastShadow"
    141.             Tags { "LightMode" = "ShadowCaster" }
    142.  
    143.             CGPROGRAM
    144.             #pragma vertex vert
    145.             #pragma fragment frag
    146.             #pragma multi_compile_shadowcaster
    147.             #include "UnityCG.cginc"
    148.  
    149.             struct v2f
    150.             {
    151.                 V2F_SHADOW_CASTER;
    152.             };
    153.  
    154.             v2f vert(appdata_base v)
    155.             {
    156.                 v2f o;
    157.                 TRANSFER_SHADOW_CASTER(o)
    158.                 return o;
    159.             }
    160.  
    161.             float4 frag(v2f i) : COLOR
    162.             {
    163.                 SHADOW_CASTER_FRAGMENT(i)
    164.             }
    165.             ENDCG
    166.         }
    167.         // This pass it not used during regular rendering, only for lightmap baking.
    168.         Pass
    169.         {
    170.             Name "Meta"
    171.             Tags{"LightMode" = "Meta"}
    172.  
    173.             Cull Off
    174.  
    175.             HLSLPROGRAM
    176.             // Required to compile gles 2.0 with standard srp library
    177.             #pragma prefer_hlslcc gles
    178.             #pragma exclude_renderers d3d11_9x
    179.             #pragma vertex LightweightVertexMeta
    180.             #pragma fragment LightweightFragmentMetaUnlit
    181.  
    182.             #include "UnlitInput.hlsl"
    183.             #include "UnlitMetaPass.hlsl"
    184.  
    185.             ENDHLSL
    186.         }
    187.     }
    188.     FallBack "Hidden/InternalErrorShader"
    189.     CustomEditor "UnityEditor.Rendering.LWRP.ShaderGUI.UnlitShader"
    190. }
    191.  
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    if you added the LWRP package just using the pakage manager it will check for any changes each time you launch unity – and thus overwrite your changes with the original shaders in the git repo.
     
  3. Danielsantalla

    Danielsantalla

    Joined:
    Jan 7, 2015
    Posts:
    75
    How do I stop this from happening?
     
    M_R_M likes this.
  4. Shane_Michael

    Shane_Michael

    Joined:
    Jul 8, 2013
    Posts:
    158
    Just save the shader in your project assets folder. You will just have to give the full path for the includes for it to compile:
    Code (csharp):
    1.  
    2. #include "Packages/com.unity.render-pipelines.lightweight/Shaders/UnlitInput.hlsl"
    3.  
     
    Danielsantalla likes this.
  5. Danielsantalla

    Danielsantalla

    Joined:
    Jan 7, 2015
    Posts:
    75
    Thanks! this worked perfectly