• 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 tanoshimi · Sep 15, 2013 at 07:38 PM · shadershaderlab

Eye space vertex manipulation in surface shader

Hi,

Short Form Question: Can the vertex:VertexFunction modifier specified for a surface shader only modify vertices in model space?

Longer Form Question: I currently have a vertex/fragment shader that does some vertex manipulation in eye/view space in the vertex program, something like this:

 v2f vert (appdata_base v)
  {
      v2f output;
 
      // Transform model coords to viewspace coords
      float4 pos = mul(UNITY_MATRIX_MV, v.vertex);
 
      // Do some stuff with pos in viewspace
      ...

      // Project from viewspace to clip coords for the fragment shader
      o.pos = mul(UNITY_MATRIX_P, pos);
  
      return o;
  }

I'm now trying to convert this into a surface shader so that I get all the lovely goodness from automatic lighting calculations etc.

I initially thought I'd be able to do this by moving the code above into a vertex modifier. However, looking at the docs more carefully, "..it is possible to use a "vertex modifier" function that will modify incoming vertex data in the vertex shader..." so, if I understand the pipeline correctly, the vertex values in the Input structure of the vertex modifier are supplied (and must be returned) in model space, right? Because it's a sort of vertex preprocessor whose output is then fed into the "real" vertex shader created based on the surf() function?

So, although I can access UNITY_MATRIX_MV in the modifier function in order to perform the calculations, it's of no use because there's no way to convert the output back to model space coordinates to pass onto to the vertex function. In which case, is there any other way I can do vertex modification in viewspace in a surface shader? (other than by letting Unity compile and create the various vertex/fragment shaders from the surface shader and then inserting it into each variant manually), or do I have to stick with my current vertex/fragment and just manually add all the PITA lighting stuff myself?

Hope that makes sense, and thankyou for any advice!

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

Answer by jonnyhopper · Oct 25, 2013 at 01:29 PM

I guess if you were willing/able to calculate the inverse view matrix in code and upload it to the shader you could multiply by that and then _World2Object?

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 AdBar · Feb 13, 2014 at 03:37 PM 0
Share

Wouldnt multipling your changes to the vertex by UNITY_$$anonymous$$ATRIX_IT_$$anonymous$$V work?

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

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

clipping shader for OpenGL quad 0 Answers

Shader - Using Multiple Pass for different shader target 1 Answer

Does AlphaToMask works in unity ? 0 Answers

Shader mesh not being effected by directional lights? 1 Answer

Shader to mask what is before it 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