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
0
Question by mgoi.tbgames · Sep 20, 2011 at 10:43 AM · shadermeshexceptiontangent

Getting "vertexSize != stride" when using mesh tangents

Hi!

I am trying to use the tangents fields of a procedural generated mesh, but Unity allways shows those exceptions:

  • Unhandled vertex structure for strided buffers!

  • vertexSize != stride

I am using this code (simplified version) to generate the mesh on awake of a monobehaviour:

 private Mesh BuildMesh()
 {
     const float PxSize = 0.0009765625f;
     const int VertexSize = 4;
     const int TriangleSize = 6;

     Rect uv0Data = new Rect(PxSize * 1.0f, PxSize * 1.0f, PxSize * 3.0f, PxSize * 3.0f) ;
     Vector2 uv1Data = new Vector2(2.0f, 4.0f) ;
     
     Vector3[] verts = new Vector3[VertexSize];
     Vector3[] normals = new Vector3[VertexSize];
     Vector2[] uv = new Vector2[VertexSize];
     Vector2[] uv1 = new Vector2[VertexSize];
     Vector4[] tangents = new Vector4[VertexSize];
     int[] tri = new int[TriangleSize];

     verts[0] = new Vector3(0, 0, 0);
     verts[1] = new Vector3(1, 0, 0);
     verts[2] = new Vector3(0, 0, 1);
     verts[3] = new Vector3(1, 0, 1);

     for (int i = 0; i < 4; i++)
     {
         normals[i] = Vector3.up;
     }

     uv[0] = new Vector2(uv0Data.x, uv0Data.y);
     uv[1] = new Vector2(uv0Data.x + uv0Data.width, uv0Data.y);
     uv[2] = new Vector2(uv0Data.x, uv0Data.y + uv0Data.height);
     uv[3] = new Vector2(uv0Data.x + uv0Data.width, uv0Data.y + uv0Data.height);

     uv1[0] = uv1[1] = uv1[2] = uv1[3] = uv1Data;

     tri[0] = 0;
     tri[1] = 2;
     tri[2] = 3;

     tri[3] = 0;
     tri[4] = 3;
     tri[5] = 1;

     tangents[0] = tangents[1] = tangents[2] = tangents[3] = new Vector4(uv0Data.x, uv0Data.y, uv0Data.width, uv0Data.height);

     Mesh m = new Mesh
         { vertices = verts, triangles = tri, uv = uv, uv1 = uv1, normals = normals, tangents = tangents };

     return m;
 }

The uv0, uv1/2 and normals attributes are already used. I require the tangent field for custom data which I have to deliver to the shader. I already tried:

  • Using UV1 and UV2 (impossible because Unity writes both channels to TEXCOORD1)

  • Using color field for the user data (impractible because color gets clamped and reduced to 8bit)

Is there a way to get rid of the exceptions or pass a 4D float vector as vertex attribute?

Thanks in advance.

Comment
Add comment · Show 4
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 jonas-echterhoff ♦♦ · Sep 20, 2011 at 11:01 AM 0
Share

uv1 has been renamed to uv2, they are the same property. What you are doing should work otherwise, i cannot find that error in our source. Does the console show any line numbers? Also, can you try setting triangles last, after setting all the other properties?

avatar image mgoi.tbgames · Sep 20, 2011 at 11:18 AM 0
Share

Hi Jonas, thanks for the fast answer. Setting the triangles last does not change anything. The console shows nothing but the editor log says:

$$anonymous$$ono: successfully reloaded assembly Unhandled vertex structure for strided buffers! UnityEditor.EditorGUIUtility:INTERNAL_CALL_RenderGameViewCameras(Rect&, Rect&, Boolean, Boolean) UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$onoGenerated\Editor\EditorGUIUtility.cs:261) UnityEditor.GameView:OnGUI() (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$ono\GameView\GameView.cs:372) System.Reflection.$$anonymous$$ono$$anonymous$$ethod:InternalInvoke(Object, Object[], Exception&) System.Reflection.$$anonymous$$ono$$anonymous$$ethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) System.Reflection.$$anonymous$$ethodBase:Invoke(Object, Object[]) UnityEditor.HostView:Invoke(String, Object) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$ono\GUI\DockArea.cs:213) UnityEditor.HostView:Invoke(String) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$ono\GUI\DockArea.cs:206) UnityEditor.DockArea:OnGUI() (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$ono\GUI\DockArea.cs:635)

[C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/Shaders/VBO.cpp line 492] (Filename: C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/$$anonymous$$onoGenerated/Editor/EditorGUIUtility.cs Line: 261)

vertexSize != stride UnityEditor.EditorGUIUtility:INTERNAL_CALL_RenderGameViewCameras(Rect&, Rect&, Boolean, Boolean) UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$onoGenerated\Editor\EditorGUIUtility.cs:261) UnityEditor.GameView:OnGUI() (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$ono\GameView\GameView.cs:372) System.Reflection.$$anonymous$$ono$$anonymous$$ethod:InternalInvoke(Object, Object[], Exception&) System.Reflection.$$anonymous$$ono$$anonymous$$ethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) System.Reflection.$$anonymous$$ethodBase:Invoke(Object, Object[]) UnityEditor.HostView:Invoke(String, Object) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$ono\GUI\DockArea.cs:213) UnityEditor.HostView:Invoke(String) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$ono\GUI\DockArea.cs:206) UnityEditor.DockArea:OnGUI() (at C:\BuildAgent\work\6bc5f79e0a4296d6\Editor\$$anonymous$$ono\GUI\DockArea.cs:635)

[C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/GfxDevice/d3d/D3D9VBO.cpp line 145] (Filename: C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/$$anonymous$$onoGenerated/Editor/EditorGUIUtility.cs Line: 261)

avatar image jonas-echterhoff ♦♦ · Sep 20, 2011 at 11:41 AM 0
Share

Hmm, which version of Unity are you using? I'm wondering, because 3.4.1 does not have that error message anywhere, and also does not have a line 492 in VBO.cpp.

avatar image mgoi.tbgames · Sep 20, 2011 at 01:00 PM 0
Share

I am using unity 3.3.0. With unity 3.4.0 the bug has disapeared. I will download unity 3.4.1 and check if it still works.

Thanks for the great help.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Sep 20, 2011 at 11:51 AM

Well, that sounds like an internal error. My guess is that happens because you assign the triangles too early. Unity have to decide what Vertex-format it should use for this mesh, but since they split the data into seperate array you can't say what data you're going to use. By assigning the triangles array the actual VBOs are generated. uv and normaly is no problem since nearly every format uses them so i guess Unity always includes those. Tangents are rarely used.

The order in which you assign the array is up to you but you should keep those things in mind:

  • If you want to change the vertex count you have to assign the vertices-array first.

  • Next step you should complete the Vertex data information (uvs,normals,colors,tangents,...)

  • According to the docs, assign tangents after normals.

  • The last step should be to assign the index-buffer (triangles array) since it will actually create the mesh.

  • If you want to completely change the vertex format you have to call Mesh.Clear() and start all over.

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 mgoi.tbgames · Sep 20, 2011 at 01:03 PM 0
Share

Thank you for your help. But the the given solution does not work in Unity 3.3.0; no matter which order is used. Tangents are broken in 3.3.0. I have to see if upgrading to unity 3.4.1. is an option for us.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a point cloud engine using shaders/meshes 0 Answers

Cancel out mesh alpha 1 Answer

how to shade a mesh created in unity 2 Answers

What are normals? 1 Answer

How to realize Unity Editor Scene Filter View Effect in my game. 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