• 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 Daniel · Jun 03, 2010 at 12:58 PM · shader

Vertex shader input is scaled?

I notcied strange behaviour when I made shader which used model space in calculations. If it was no scale on object it was fine, but when I added scale it went wrong. So I started to experiment with it, I have made simple shader which is applied to sphere and changes it's vertices:

v2f o;

float3 n = normalize(v.vertex.xyz);

float3 vv = n * 10.25;

float4 nv = float4(vv,1);

o.pos = mul(glstate.matrix.mvp, nv);

// normally this is: o.pos = mul(glstate.matrix.mvp, v.vertex);

It getting vertex, computing normal (object is sphere, so it is simple normalize) and scales normal by 10.25 (just a number). Then resulting vertex is multiplied by MVP matrix as usual.

What was strange for me: resulting spehere is not affected by scale value set in the editor, but if I replacing my vertex by the original v.vertex it works fine. So for me it looks like unity scales vertices somewhere before vertex shader and MVP matrix doesn't contain scale.

Am I correct or it is some misunderstanding here? Also if it is so, is it any way to change this. Thanks.

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

Answer by Aras · Jun 08, 2010 at 08:45 AM

Correct. Right now (Unity 2.x) all scaled objects are pre-scaled on the CPU. So the GPU or shaders already ever see the already scaled version. Which means they don't have to normalize the normals, for example.

In upcoming Unity 3.0, we plan to let the GPU handle uniform scale. Non-uniform scaled meshes will still be pre-scaled on the CPU.

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 Daniel · Jun 08, 2010 at 12:31 PM 0
Share

Thanks for explanation.

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

No one has followed this question yet.

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

Toon Diffuse Shader Unsupported 1 Answer

bump map in combination with toon shading 1 Answer

having a camera render an object only if it appears after a plane 1 Answer

fragment Shader -> get the current pixel color int the color Buffer :D 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