- Home /
How to add "fat" feature to the Standard.shader?
Update: I stripped down the Standard.shader and added the normal extrusion code. The problem is when _Amount > 0 then the passes won't execute correctly.
_Amount = 0  
 
_Amount = 0.01 
The code is as follows:
 Shader "Custom/StandardBlowUp"
 {
     Properties
     {
         _Amount("Extrusion Amount", Range(0,1)) = 0.0
         _Color("Color", Color) = (1,1,1,1)
         _MainTex("Albedo", 2D) = "white" {}
         
         //_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
 
         //_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
         //_GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
         [Enum(Metallic Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 0
 
         [Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
         //_MetallicGlossMap("Metallic", 2D) = "white" {}
 
         [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
         [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
 
         [Enum(UV0,0,UV1,1)] _UVSec("UV Set for secondary textures", Float) = 0
 
 
         // Blending state
         [HideInInspector] _Mode("__mode", Float) = 0.0
         [HideInInspector] _SrcBlend("__src", Float) = 1.0
         [HideInInspector] _DstBlend("__dst", Float) = 0.0
         [HideInInspector] _ZWrite("__zw", Float) = 1.0
     }
 
     CGINCLUDE
     #define UNITY_SETUP_BRDF_INPUT MetallicSetup
     ENDCG
 
     SubShader
     {
         Tags{ "RenderType" = "Opaque" "PerformanceChecks" = "False" }
         LOD 300
 
         // ------------------------------------------------------------------
         //  Base forward pass (directional light, emission, lightmaps, ...)
         
         CGPROGRAM
         #pragma surface surf Standard vertex:vert
 
         struct Input {
             float2 uv_MainTex;            
         };
 
         float _Amount;
 
         void vert(inout appdata_full v) {
             v.vertex.xyz += v.normal *_Amount;
         }
 
         sampler2D _MainTex;
 
         void surf(Input IN, inout SurfaceOutputStandard o) {
             fixed4 maintex = tex2D(_MainTex, IN.uv_MainTex);
 
             o.Albedo = maintex.rgb;
             o.Occlusion = maintex.g;
         }
         ENDCG
             
         Pass
         {
             Name "FORWARD"
             Tags{ "LightMode" = "ForwardBase" }
 
             Blend[_SrcBlend][_DstBlend]
             ZWrite[_ZWrite]
 
             CGPROGRAM
             #pragma target 3.0
 
         // -------------------------------------
 
             #pragma shader_feature _NORMALMAP
             #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
             #pragma shader_feature _EMISSION
             #pragma shader_feature _METALLICGLOSSMAP
             #pragma shader_feature ___ _DETAIL_MULX2
             #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
             #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
             #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
             #pragma shader_feature _PARALLAXMAP
 
             #pragma multi_compile_fwdbase
             #pragma multi_compile_fog
             #pragma multi_compile_instancing
             // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
             //#pragma multi_compile _ LOD_FADE_CROSSFADE
 
             #pragma vertex vertBase
             #pragma fragment fragBase
 
             #pragma vertex:vert
             #include "UnityStandardCoreForward.cginc"
 
             ENDCG
         }
         // ------------------------------------------------------------------
         //  Additive forward pass (one light per pass)
         Pass
         {    
             Name "FORWARD_DELTA"
             Tags{ "LightMode" = "ForwardAdd" }
             Blend[_SrcBlend] One
             Fog{ Color(0,0,0,0) } // in additive pass fog should be black
             ZWrite Off
             ZTest LEqual
 
             CGPROGRAM
             #pragma target 3.0
 
         // -------------------------------------
 
 
             #pragma shader_feature _NORMALMAP
             #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
             #pragma shader_feature _METALLICGLOSSMAP
             #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
             #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
             #pragma shader_feature ___ _DETAIL_MULX2
             #pragma shader_feature _PARALLAXMAP
 
             #pragma multi_compile_fwdadd_fullshadows
             #pragma multi_compile_fog
             // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
             //#pragma multi_compile _ LOD_FADE_CROSSFADE
 
             #pragma vertex vertAdd
             #pragma fragment fragAdd
 
             #pragma vertex:vert
             #include "UnityStandardCoreForward.cginc"
 
             ENDCG
         }
         // ------------------------------------------------------------------
         //  Normal Extrusion
     }    
 
     FallBack "VertexLit"
     //CustomEditor "StandardShaderGUI"
 }
 
 
I have this shader to extrude normals, which can be found in the surface shader examples titled: "Normal Extrusion with Vertex Modifier".  
 
 Shader "Example/Normal Extrusion" {
     Properties {
       _MainTex ("Texture", 2D) = "white" {}
       _Amount ("Extrusion Amount", Range(-1,1)) = 0.5
     }
     SubShader {
       Tags { "RenderType" = "Opaque" }
       CGPROGRAM
       #pragma surface surf Lambert vertex:vert
       struct Input {
           float2 uv_MainTex;
       };
       float _Amount;
       void vert (inout appdata_full v) {
           v.vertex.xyz += v.normal * _Amount;
       }
       sampler2D _MainTex;
       void surf (Input IN, inout SurfaceOutput o) {
           o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
       }
       ENDCG
     } 
     Fallback "Diffuse"
   }
How do I add this to the Standard.shader?
Answer by BodhiPurplePill · Jul 17, 2017 at 03:33 PM
Add "_Amount ("Extrusion Amount", Range(-1,1)) = 0.5" to properties.
Add "vertex:vert" to #pragma line
Change "fullforwardshadows" to "addshadow" in #pragma line
insert
float _Amount; void vert (inout appdata_full v) { v.vertex.xyz += v.normal * _Amount; }
Under struct Input
I updated the question, but couldn't apply all your suggestions.
"fullforwardshadows" nor "addshadow" did exists, the closest thing was '#pragma multi_compile_fwdadd_fullshadows'
When I inserted what you said I got a error: Unexpected token void.
 struct Input {
             float2 uv_$$anonymous$$ainTex;
             float _Amount;
             void vert(inout appdata_full v) {
                 v.vertex.xyz += v.normal *_Amount;
             }
         };
Your answer
 
 
             Follow this Question
Related Questions
Mobile performance of splat map shader with distance blending 0 Answers
What is the meaning of a vertex shader for a post-processing shader? 1 Answer
Quad vertex color shader 0 Answers
URP Height Map Shader Problem,URP Custom Shader: Cannot access the UVs of the object 0 Answers
Need to get lighting to work on bending vertex shader... 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                