• 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 Modifier" example to get started from this page: http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html. Would you mind 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 transforming 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_MATRIX_MVP, 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

45 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

Related Questions

2D sprite - jelly, squeeze, squash 0 Answers

Mobile performance of splat map shader with distance blending 0 Answers

How to Mask Vertex Animation? 0 Answers

How to reuse HLSL shader code? 1 Answer

'vert': output parameter 'o' not completely initialized 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges