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 MythicManiac · Dec 22, 2015 at 09:05 AM · graphicsmaterialsshadowsmesheslights

Strange shader/lightning behavior in generated mesh

For some reason this happens with my generated mesh:

This is what it looks like if all squares are the same size:

This is the same done with block objects and also what I would like it to look like:

All pictures use the same material, so I don't think that is the casue.

Any idea what could cause this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by wibble82 · Dec 22, 2015 at 04:00 PM

I am not sure what your mesh generation code is doing, but I suspect it is sharing vertices between faces in some way, and this is causing a problem if the normals to the faces are not the same.

The issue you show looks like the sort of problem you get with cubes when you don't give each face its own vertices - it takes on a 'curved' effect from a lighting point of view, as the normals point out diagonally from each corner and blend across the cube.

If you are currently trying to share vertices between triangles in any way, I would avoid it for the moment. Start with mesh generation that:

  • Just creates 3 new vertices for every triangle

  • Calculate the normal to the triangle using the cross product of the 2 edges

  • Store that same normal for all 3 vertices

This is not optimal, but should give you a correct mesh.

Once you've got that, you could look at more efficient use of vertices - for example you could easily share vertices between the 2 triangles on a single face of a block, and if you're careful perhaps more. Start simple though - and only make it better if it isn't good enough! :)

(Edit: Just remembered the 'RecalculateNormals' function on a mesh. Provided you do my first step - 3 vertices for each triangle, and they have the correct winding order, recalculate normals should do the rest if you're using it).

-Chris

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 MythicManiac · Dec 23, 2015 at 07:27 PM 0
Share

Ah, that makes sense. I was actually generating a matrix of (totalWidth + 1)* (totalHeight + 1) vertices, that I just mapped my triangles onto. Didn't think it'd cause this kind of behavior.

avatar image
0

Answer by MythicManiac · Dec 22, 2015 at 08:37 PM

I figured out why this happens, yet to fix it though.

The difference between blocks and my mesh was, that the blocks were always size of (1,1,1), while my mesh was a lot bigger. Using same size squares didn't work because the overall mesh is still bigger and applying the material on it does weird things apparently.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Missing shadows on custom steppedAtten shader 0 Answers

Slower realtime shadow update speed? Possible? 1 Answer

Bumped Specular only works for directional lights? 1 Answer

Point lights can't cast shadows? Is forward rendering something that can be changed? 3 Answers

Shadow Black Lines Glitches 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