Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by abragon · Jul 26, 2017 at 02:08 PM · shadershadersnormalsvertex shaderextrusion

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 alt text

_Amount = 0.01 alt text

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". alt text

 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?

amount001.png (203.5 kB)
amount0.png (211.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image abragon · Jul 17, 2017 at 04:06 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

105 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges