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 /
  • Help Room /
avatar image
0
Question by shapirog · Mar 16, 2017 at 08:59 AM · meshlightingmaterialswatermeshfilter

Changing a mesh with code but it doesn't react to the lighting

Hello, I'm trying to make some low-poly water. So I have a plane and I put a script on it that I found online:

 using UnityEngine;
 using System.Collections;
 
 public class Water : MonoBehaviour 
 {
     public float scale = 7.0f;
     public float heightScale = 1.0f;
     private Vector2 v2SampleStart = new Vector2(0f, 0f);
 
     void Update () 
     {
         MeshFilter mf = GetComponent<MeshFilter>();
         Vector3[] vertices = mf.mesh.vertices;
 
         for (int i = 0; i < vertices.Length; i++)
         {
             vertices[i].y = heightScale * Mathf.PerlinNoise(Time.time + (vertices[i].x * scale), Time.time + (vertices[i].z * scale));
         }
         mf.mesh.vertices = vertices;
     }
 }
 

Ok, great. So it makes the plane wiggle and looks like water. However the changes that are made by this script do not cause the material to react to the lighting. Since the plane starts totally flat, and is uniformly lit with no shadows or specular on anything, once this script starts, the vertices move around but there's no shading at all. It's totally flat. I've confirmed the lighting/material works by exporting a plane from Cinema4D that has a little bit of displacement baked onto it, and this is affected by the lighting. However, even when I put the script on this one, the lighting doesn't change! Polygons that were lit/shadowed from the beginning retain their same exact color.

Am I missing something simple here?

Thanks!

plane with displacement from script: plane with displacement from script

plane with displacement baked into model: plane with displacement baked into model

screen-shot-2017-03-16-at-045509.png (27.2 kB)
screen-shot-2017-03-16-at-045458.png (11.4 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 shapirog · Mar 16, 2017 at 09:30 AM

Well I made some progress... I got it to update the shading with RecalculateNormals(); but it resets the smoothing to the default so it no longer looks flat shaded. Is there a way to have it update the normals but keep the flat-shaded look? Or would it be better to try a totally different approach to get the water to look low-poly/flat shaded?

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

112 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

some sprites are turning transparent while using a normal map and others don't 0 Answers

How to get the name of a model file(fbx) contained in a certain prefab with scripts? 1 Answer

URGENT How to get triangles of mesh in world space? 0 Answers

Thin black lines between meshes 1 Answer

Create a custom quad mesh from script 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