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 sven1994 · Aug 05, 2011 at 04:30 PM · rotationshaderlightingsurfaceshader

Surface shader: Wrong lighting when moving vertices

Hi everyone. I'm currently trying to make a shader that rotates the mesh. I have a float as an input that represents the rotation in degrees around the z-axis (so in the picture below the actual rotation (transform.rotation) is still zero in both cases).

By the way, I'm using the Strumpy Shader Editor and am not very experienced with shaders in general. I also uploaded my graphs

The problem is that the light coming from a directional light somehow rotates with the mesh (can't explain it better) and the light of the point light acts weird, too.

What am I missing here?

Example

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
1
Best Answer

Answer by Owen-Reynolds · Aug 05, 2011 at 07:00 PM

If you are literally moving the verts in the mesh, then you need to recalculate the normals (Mesh.RecalculateNormals is a built-in, if you don't want to do it by hand.) The thing is, if you are only rotating the verts, then why not just rotate the model? Everything is set up to do the math for you when you use Transform.rotate.

The shader has no good way of knowing which way a face is "aimed," so we tell it with normals. For example, normals on the "top" verts are pre-made pointing upish. If you twist the verts around so that your top verts are now facing forwards, those normals still say the face counts as pointing up, so lights wrong (and the new top still counts as pointing backwards.)

But why don't all rotated models light wrong? When you spin a model overall, using the rotation, that rotation is sent to the shader. The auto-part of the surface shader knows how to fix the normals based on rotation. So, surface shaders work fine with rotated models, they expect it and even calculate the "fixed" normals for a non-rotated model. FYI, original normals are modelView and fixed ones are worldView (if you have to look these things up.)

If all you are doing is a rotate on verts, and you can't rotate the whole model, you'll need to also rotate the normals by the same angle (could also use recalNorms, but it does the same thing, slower, since it starts from scratch.)

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 sven1994 · Aug 05, 2011 at 07:49 PM 0
Share

Thank's for the explanation. It was more or less an experiment and for learning purposes. For example, if I had about 200 wheels that should all be rotated I could - of course - call Rotate() on everyone - or just set one float value for the material they are all sharing. That's why I did that :D

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Help with adding a normalmap to a shader 1 Answer

Two Color Lighting Shader Not Working 2 Answers

Standard Surface Shader with fade too dark 0 Answers

Why are Cubemaps and Specular highlights not equally blurry at the same Roughness / Glossyness value with standard pbr shader? 0 Answers

Shader: get nearest point light's color, direction and general custom lighting questions 0 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