• 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
Question by batch · Dec 06, 2014 at 01:08 PM · shaderrandomverticesvertexshaderlab

How to move vertices up/down randomly in shader.

Hello!

I have a plane and I'd like to adjust the y positions of the vertices in the shader. Actually moving them is simple enough, but I was wondering what the best way of getting the random values for heights was?

Would I need a random function inside the shader to get a value wit$$anonymous$$n a range?

Thanks

Comment

People who like this

0 Show 2
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 batch · Dec 06, 2014 at 03:19 PM 0
Share

Hey, thanks for the reply! Sorry I was vague.

What I'm hoping to achieve is to modify a flat plane so that the vertices will move up and/or down in the y axis, giving it an uneven surface.

I am just using this:

   // Vertex modifier
    void vert (inout appdata_full v) 
    {
        v.vertex.y += _Amount;
    }

where _Amount will be the random value generated. With the function you provided, what float2 input should it take?

Thanks a lot!

avatar image SimonTS · Dec 06, 2014 at 03:39 PM 0
Share

Unless you want complete randomness you should probably use some kind of noise function such as perlin noise.

But for optimization purposes you should probably just use a texture as a heightmap to offset your verts!

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Gruffy · Dec 06, 2014 at 02:58 PM

Hey bud, Are you trying to scroll your texture with the shader or somet$$anonymous$$ng like that ? You would be looking to do t$$anonymous$$s in the Surf shader function

You could call to the _Time property and multiply it by a set of values based on the x and y you set it. yo could then effect them with random values passed into the vars holding the x and y values. I could go on. the code would look similar to t$$anonymous$$s...

 fixed yScrollValue = _ScrollYSpeed * _Time;

you might make _ScrollYSpeed an accessible parameter in the inspector for the shader allowing you to adjust/tweak it visually afterwards.

You could be looking for a a small function to run on a float in your code like so....

 float randomNum(in float2 uv)
 
     float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453));
     return abs(noise.x + noise.y) * 0.5;
 }


but without your code, who knows ? Then again, who even knows, if you are using Unitys shader language, Cg, HLSL ?

So... Could you possibly add in your shader code please, so we can get to the bottom of it faster for you.

Hope that helps some Take care Bud Gruffy

Comment
robertbu
Roiw

People who like this

2 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Shader problem: length() en distance() 1 Answer

Why doesn't this vertex+fragment shader work? 0 Answers

Moving vertices in shaders 1 Answer

Vertex Shader problem with _WorldSpaceCameraPos 1 Answer

How do I make a vertex invisible if its X value is > myFloat 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