Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 tkoknordic · May 26, 2015 at 01:59 PM · shadercgvertex shader

How to access other vertices in vertex shader?

I have a special mesh where my vertices are in groups of four. Vertices in a group are continuously in the vertex array. I would like to have a vertex shader that linearly scales so that with scale value of 1.0 all vertices would have orginal positions and with scale value of 0.0 all vertices would be in the center of their groups of four.

Semi pseudo code could be something like:

 Shader property _Scale Range(0.0, 1.0)
 
 CGPROGRAM
 #pragma vertex vert
 uniform float _Scale;
 vert(appdata v) {
     v2f o;
     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
     int vertexindex = (vertexIndex / 4) * 4; // floor to /4
     float4 center = average_float4(
         vertex[vertexindex],
         vertex[vertexindex + 1],
         vertex[vertexindex + 2],
         vertex[vertexindex + 3]);
     o.pos = lerp_float4(center, o.pos, _Scale);
     return o;
 }
 ENDCG

Subquestions:

-How to access other vertices within vertex shader?

-Is there average and lerp fuctions for float4 type?

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
Best Answer

Answer by tanoshimi · May 26, 2015 at 05:01 PM

You can't access vertices other than the one currently being processed - the shader pipeline is designed to be parallelized so there is no way to logically define vertex[i+1].

However, you could encode the "group centerpoint" in an additional property associated with each vertex (the xyz coordinates encoded as the rgb components of the vertex colour of each vertex in the mesh, for example) and pass them into the shader that way.

Comment
Add comment · Show 1 · 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 tkoknordic · May 26, 2015 at 05:05 PM 0
Share

That is a good idea! I have been working with compute shaders and CUDA and there you can access the index of parallel process. And it's okay to use same (vertex)data as long as you just read it. I hope your answer's $$anonymous$$d set will help me also in the future.

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

19 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

Related Questions

UnityPixelSnap in custom vertex shader behaves differently to implementation in default sprite shader. 0 Answers

Where is model space origin in shaderlab? 1 Answer

Parsing values in multipass cg shader 0 Answers

Vertex Shader Properties Issu 1 Answer

Adding transparency to vertex 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