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

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

Vertex Shader problem with _WorldSpaceCameraPos 1 Answer

Create a Wireframe Shader with Shader Forge 1 Answer

[Shader, sprite] frag shade entire sprite image? 1 Answer

Adding transparency to vertex shader? 0 Answers

Fisheye effect vertex shader fail - asking for help - video and code included 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