• 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 D43DB33F · Feb 10, 2018 at 01:26 AM · shadervertexvertex shaderhlslpass

Reuse vertices modified in a previous shader pass

I've recently started to learn shaders and I'm trying to write a shader that :

- Animates a mesh to simulate water waves ;
- Reuses the standard Unity shader so that I don't have to write all the complex lighting stuff myself.

The shader modifies the vertices in the first pass and that pass works as intended. The problem is that, when the subsequent passes are performed, i.e the Unity standard shader passes, these passes do not reuse the modified vertex coordinates !

alt text
As you can see on the picture, my first pass properly updates vertices, but the following passes ignore the updated values.

My question is, how can I make the following passes reuse the updated vertexes ? Do I have to modify every single pass of the unity standard shader to also update the vertices or is there some kind of magic command that I have not learned yet ?

Thanks !

capture.png (140.8 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
Best Answer

Answer by D43DB33F · Feb 11, 2018 at 12:24 AM

After a lot of pain in my ass, I finally managed to create GPU simulated water with proper normals.

The solution in a nutshell is : don't try to save the computed vertices from a pass to another in order to use it for normal computation. Instead, compute fake "neighbor" vertices (assuming that it is possible to recompute them with the available data, which in my case is possible) and use them to recompute the normals. Basically this means 5 times the work for every vertex if you take 4 neighbor vertices to compute an averaged normal based on two cross products.

There are more things to do beyond that in order to use the computed normals. In a nutshell again, it requires to write a surface shader that also has a vertex function. The vert function receives an appdata_full structure as "inout" and assigns both the vertex and the normal into it.

See the following youtube videos : - https://www.youtube.com/watch?v=1G37-Yav2ZM - https://www.youtube.com/watch?v=UfX9dzhBhg0 - https://www.youtube.com/watch?v=cz5mt_0bxqQ

The performance gain of doing this using the GPU instead of the CPU using the Unity API is ridiculous. I can animate about 1 million triangles à 65 FPS using an AMD R9 280 3 Go. I would probably get something like 0.001 FPS if I was doing this with the CPU.

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.

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

120 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

Related Questions

Why does this shader give different result Editor/ Android? 0 Answers

Is it possible to get back data for a specific vertex from a shader ? 0 Answers

Modify vertex position using shaders on Windows Phone 8 0 Answers

Surface Shader, run vertex multiple times 0 Answers

Parsing values in multipass cg shader 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