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
1
Question by Dywindel · Oct 21, 2019 at 06:11 PM · shadersprogramming

Wavey Shaders, Where to start?

Hi,

One part of a game I'm working on requires a high vertex plane to animate in waves; sort of like an ocean. Originally, I achieved this effect by randomly moving each vertex in the plane and using smooth shading. This created the desired effect, but was computationally heavy.
Here's what it looks like from the side..

I want to turn this into a surface shader, but I'm having a bit of trouble and I don't have access to Unity's ShaderGraph.

I also tried just moving the verts along their normals randomly in the surface shader, but that doesn't create the soft shadow effect shown in the first link (I think this is the limitation of ShaderForge too).

I'm only familiar with Vert and Frag shaders and not familiar enough with surface Shaders to know how to achieve this affect. What's the best direction to go in at the moment? I feel like learning surface shaders is unecessary. Is this just not possible to do for me right now and is it better to just buy a pre-made shader on the asset store?

Thanks for any feedback in advance.

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
2

Answer by Pangamini · Oct 21, 2019 at 06:31 PM

Surface shader is just a shader.... well, technically it generates a lot of fragment shaders for different parts of the pipeline, and unity shader framework calculates a lot for you. But you can move vertices in a vertex shader just the same, then use the result in the surface shader. The only tricky part is to calculate the normals, but if you are generating the waves (eg. from a sin or a texture) you could just generate the normals in the vertex shader

Comment
Add comment · Show 3 · 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 Dywindel · Oct 22, 2019 at 11:23 AM 0
Share

That's the bit I need. I need to understand how to regenerate the normals after I've moved the vertices. Do you know where I can find information about how to do this? Or a practical example?

avatar image Pangamini Dywindel · Oct 22, 2019 at 11:42 AM 1
Share

That's closely bound to how you generate the wave displacement. If you generate the displacement by sampling a heightmap of the wave, then the easiest solution would be to generate the normals the same way - by sampling a normalmap of the wave.

If you are generating some arbitrary displacement, you might need to get into geometry shaders that can see the whole triangle and more... and things get complicated pretty quickly. So unless you want to do a bit of research here, stick to the first option

avatar image Pangamini Pangamini · Oct 22, 2019 at 11:45 AM 1
Share

Or, you can just ignore vertex normals (set them to all point upwards) and sample the animated normal map in the pixel shader. Same as above, you should have a matching normal function to your height function (whether it's a texture or some sine wave composite)

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

136 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 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

Multiple Cars not working 1 Answer

Shadergraph Custom Function undeclared identifier 4 Answers

Do TEXCOORDS need to be in sequence? 1 Answer

Is it possible to read light value per vertex with a shader? 0 Answers

doubles and compute shaders 1 Answer


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