• 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 kidkilgore · Oct 14, 2019 at 07:45 AM · vertex shader

Cannot get vertex position after vertex shader has modified it

I have a simple perlin noise vertex shader making ocean waves, everything in that regard is working fine. I am hoping to have a boat on this ocean and have the boat float along with the vertex shader perlin noise waves.

The problem is, no matter what I poke at I can't seem to access this adjusted vertex value anywhere?! I have tried the following:

 var mesh = Ocean.GetComponent<MeshFilter>().mesh;
 Vector3[] vertices = mesh.vertices;  // I've looked at UVs and Normals as well, not 
                                      // exactly sure what they are but I looked! :)

 // for v in vertices, print v.y -- It's always the same no matter what the waves are doing


I also tried raycasting to see if I could hit the ocean and get the correct value, but I believe the collider on the ocean is not changing from the vertex shader results. That makes some sense, but I am very confused on how the vertex shaderis changing the vertices, but I cannot access this value?

Could it be I need to grab the position from somewhere else?

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
1

Answer by Bunny83 · Oct 14, 2019 at 12:19 PM

No, you can not access the result of the vertex shader since this all happens on the GPU in video memory where the CPU has no access to. Vertex and fragment shaders are part of the rendering pipeline and are only responsible for rendering / displaying. They aren't meant for calculating data that you can use on the CPU. There are compute shaders which allow you to send information to specialized shaders which compute things on the GPU and pass the results back to the CPU. However this sending to the GPU and back has some bandwidth limits. So apart from the fact that you need a rather new GPU to support this, you have to ask yourself if the amount of work is worth it to offload it to the GPU.


If you just want to query a position on your perlin noise generated water, you just need to recreate the exact same algorithm on the CPU. Since you don't need to calculate the whole mesh but you are only interested in one (or a few) points this should be really fast on the CPU.


Since we don't know anything about your actual shader we can not really help you any further here.

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

111 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

Related Questions

Rotating/Jiggling lots of coins using a Vertex shader 0 Answers

How to compute shadows in custom Surface Shaders? 0 Answers

Combine Vertex / Fragment and Surface Shader 0 Answers

Fisheye effect vertex shader fail - asking for help - video and code included 1 Answer

Changing the color of individual particles 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