Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
1
Question by carlosrcp · Sep 10, 2016 at 12:15 AM · shadershadowvertexshader writing

Shadows in a shader with vertex modifier

How can i have correct shadows in an mesh with vertices deslocated by the shader? The shadows appear like the mesh wasn't changed.

I'm using this shader:

   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"
       }

found here https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html.

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 Namey5 · Sep 10, 2016 at 12:26 AM

You have to add the 'addshadow' keyword to the surface declaration, i.e.

 #pragma surface surf Lambert vertex:vert addshadow
Comment
Add comment · Show 4 · 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 carlosrcp · Sep 10, 2016 at 12:41 AM 0
Share

thanks, this works, but when try to move only some vertices, using: if(v.vertex.y>0.5f) v.vertex.xyz += v.normal * _Amount;

it doesn't work, what i'm really trying to do is to deform just some vertices, what can i do?

avatar image Namey5 carlosrcp · Sep 10, 2016 at 12:47 AM 0
Share

Which doesn't work, the shadows or the vertex displacement?

avatar image carlosrcp Namey5 · Sep 10, 2016 at 12:52 AM 0
Share

the shadows, the vertex deforms but the shadows stay the same

avatar image Chandru_S · Aug 26, 2018 at 11:42 AM 0
Share

I know this is from two years ago but thank you very much

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

90 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

Related Questions

how to get spot-/point-/..lights working with vertex displacement shader? 0 Answers

Help with URP shader for a procedural terrain mesh 0 Answers

Shader MVP matrices: what does vertex position mean at each step? 2 Answers

How to cast terrain detail shadow? 0 Answers

Offset value not responsive in secondary texture 2 Answers


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