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 KonstantinMaximus · May 10, 2016 at 05:30 PM · shadersvertex shader

Shader Vert Offsets in local space

I have a shader that applies offset to each vertex based on a sin wave, this is the vert function:

     void vert ( inout appdata_full v ) 
     {        
         float twoPi = 2 * 3.141592653;

         float4 change = float4( 0, 0, 0, 0 );
         
         float redSin = sin(_Time.x * _Speed) * _Amplifier;
         change.x += redSin * _RedStrength;    
           
         change = mul ( _World2Object, change );

         v.vertex += change;
     }

If object has no rotations, everything works great. But if object is rotated, it moves as if it is not rotated. So, regardless of rotations all of the objects with this shader move uniformly. I made it so that each material is instanced, not shared, but that didn't help. What am I missing?

Also, I looked at this: http://answers.unity3d.com/questions/561978/modifying-vertex-position-in-a-surface-shader.html and http://answers.unity3d.com/questions/819002/getting-the-local-vertex-positions-in-vertex-shade.html and http://answers.unity3d.com/questions/561900/get-local-position-in-surface-shader.html, but none of these helped :(.

Also, if I don't multiply change by _World2Object, shader behaves differently depending on the distance from the camera... If object is rotated, axis of movement switches at different distances. Weird!!!....

Please HALP! How do I apply vert changes in local space?

EDIT: This is a surface shader.

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 FortisVenaliter · May 10, 2016 at 05:38 PM

The point of a vertex subshader is to transform the vertices from local to screen space. You still need to do that conversion manually, after you've done your sin wave transformation. Check out these official examples.

Comment
Add comment · Show 9 · 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 KonstantinMaximus · May 10, 2016 at 05:53 PM 0
Share

These are structured differently to what I am used to. I am kind of a noob when it comes to shaders, I followed "Normal Extrusion with Vertex $$anonymous$$odifier" example to get started from this page: http://docs.unity3d.com/$$anonymous$$anual/SL-SurfaceShaderExamples.html. Would you $$anonymous$$d nudging me closer to what I need to take a look at?

avatar image Eno-Khaon KonstantinMaximus · May 10, 2016 at 06:02 PM 0
Share

The main changes to make are based on your vertex shader's declaration:

 void vert ( inout appdata_full v )

By using inout, you're letting Unity automatically create and pass data through the vertex shader for you.

You need to grab the vertex position information before it's automatically been converted (or convert it back yourself, but then you're transfor$$anonymous$$g from object->world->object->world space for no real reason).

avatar image KonstantinMaximus Eno-Khaon · May 10, 2016 at 06:32 PM 0
Share

So, I should try switching to "v2f vert (appdata v)" and calculate transforms using something like this:

 v2f o;
 o.vertex = mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex);

If i understand you correctly.

Show more comments

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

44 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

Related Questions

How to reuse HLSL shader code? 1 Answer

Change vertex location in standard shader 0 Answers

Does pixel shaders behave like vertex shaders when pixel light count is set to 0 from quality settings ? 1 Answer

Quad vertex color shader 0 Answers

From within the frag function of a shader, can you access the uv values of vertices? 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