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 Gargore · Oct 23, 2013 at 11:11 PM · shadergeometryvertexshader

Vertex shader does not receive vertex coordinates as I expected. Why?

Hi!

I'm making a vertex shader for transform the vertex coordinates. For some reason when I use cubes or plane gameobjects and I have several in the viewport with the same mesh and shader/material geometry vertices seems to arrive in v.vertex with the coordinates relative to the scene (0, 0, 0) instead of the gameobject center (which is the behaviour that I expected). When only one mesh is visible, then the coordinates comes relative to the gameobject center, or when different gameobjects have different shaders, or when mesh is more complex (like an sphere). It's like Unity is grouping the geometry underneath somehow...

Is this behaviour configurable? There is something I'm doing wrong?

I attach the shader I used to finally realize that something wasn't going like I expected:

 Shader "Custom/BasicVertex" {
     Properties {
         _Color ("Main Color", Color) = (1,1,1,0.5)
         _MainTex ("Texture", 2D) = "white" { }
         _Mx ("Mx", Float) = 1
         _My ("My", Float) = 1
         _Mz ("Mz", Float) = 1
     }
     SubShader {
         Pass {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #include "UnityCG.cginc"
 
             float4 _Color;
             sampler2D _MainTex;
             float _Mx, _My, _Mz;
 
             struct v2f {
                 float4 pos: SV_POSITION;
                 float2 uv: TEXCOORD0;
             };
             
             float4 _MainTex_ST;
 
             v2f vert(appdata_base v) {
                 v2f o;
                 float4 trvertex = float4(v.vertex.x * _Mx, v.vertex.y * _My, v.vertex.z * _Mz, v.vertex.w);
                 o.pos = mul(UNITY_MATRIX_MVP, trvertex);
                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
                 return o;
             }
 
             half4 frag(v2f i): COLOR {
                 half4 texcol = tex2D(_MainTex, i.uv);
                 return texcol * _Color;
             }
             ENDCG
         }
     }
     Fallback "VertexLit"
 }
Comment
Add comment · Show 1
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 AlucardJay · Oct 24, 2013 at 01:29 AM 0
Share

Just to mention you may also receive help in the shader forum : http://forum.unity3d.com/forums/16-ShaderLab

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Oct 24, 2013 at 03:27 AM

It will certain ly not use the GameObjects center but the GameObjects pivot since all vertex coordinates are local coordinates. In a lot cases the pivot is the GameObjects center but they aren't related in the first place. So make sure you set the pivot mode in Unity to pivot and not center.

And to answer your question: No, this behaviour is not configurable for Vertex shaders since that's the point of a vertex shader ;) Surface Shaders on the other hand work a little bit different, but since your shader is a "normal shader" the in coming vertex data stream is in local coordinates.

Comment
Add comment · 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
0

Answer by Gargore · Oct 29, 2013 at 07:58 PM

Hi Bunny83,

Thank you for trying to help :) but probably the question can be answered only by an Unity Staff person.

I wasn't talking about the editor (I believe the pivot's mode is an editor-only tool and it didn't affect runtime elements like scripts or shaders). Anyway the behaviour is fully independent from grouping performed at editor level, or from pivot-mode.

About the "behaviour", there are other queue manager settings that can be changed, and I cannot see why "this is the point of a vertex shader" :)

The mesh data grouping is made probably by the Unity Engine internals to improve performance (if I have made the engine probably I will try to make that kind of optimizations); I was asking if this behaviour (probably an optimization) can be disabled at material level or at queue mananger settings level somehow.

Comment
Add comment · 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

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

16 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

Related Questions

Unwrap a mesh with a vertex shader 0 Answers

Transform all Terrain Vertices to Map to Sphere 0 Answers

Why is batching breaking my shader? 0 Answers

Getting model bounds in vertex shader 0 Answers

Geomorphing terrain with a vertex shader (custom vertex data maybe?+ 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