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 DanaScully · Jun 12, 2017 at 07:26 AM · renderingclothvertex shadervertexcolorcloth renderer

Incorrect transparent rendering

I am trying to per-vertex color a piece of cloth. I am using unity's particle/alpha blended shader but then the cloth gets transparent. I am not sure what I am doing wrong. Changing the shaders also don't solve the problem. I am using Obicloth.

  void Awake()
     {
         Mesh mesh = gameObject.GetComponent<MeshFilter>().sharedMesh;
         Vector3[] vertices = mesh.vertices;
         int[] triangles = mesh.triangles;
 
         ObiCloth cloth = gameObject.GetComponent<ObiCloth>();
   
         Vector3[] verticesModified = new Vector3[triangles.Length];
         int[] trianglesModified = new int[triangles.Length];
 
         Color[] colors = new Color[triangles.Length];
         Color c = new Color();
         for(int i = 0; i < triangles.Length; i++)
         {
             verticesModified[i] = vertices[triangles[i]];
             trianglesModified[i] = i;
             int index = triangles[i];
             if(i%3 == 0)
             {
                 c = new Color(Random.Range(0.0f, 1.0f),
                     Random.Range(0.0f, 1.0f),
                     Random.Range(0.0f, 1.0f),
                     1.0f);
                 colors[index] = c;
             }
         }
 
 
         mesh.vertices = verticesModified;
         mesh.triangles = triangles;
         mesh.colors = colors;
 
         mesh.RecalculateNormals();
     }
Comment
Add comment · Show 3
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 revolute · Jun 12, 2017 at 07:34 AM 0
Share

Can you try addinig gameObject.GetComponent().shared$$anonymous$$esh = mesh; at the end of your script?

Im kind of hazy as to how shared stuff works but if I recall correctly, unity makes a clone of the mesh internally if you try to modify shared mesh.

In short, gameObject.GetComponent().shared$$anonymous$$esh != mesh .

avatar image Vojtasle · Jun 12, 2017 at 08:16 AM 0
Share

Im not really sure how this works but I had a similar struggle with not being able to set objects transparency and the problem was in type of material.

avatar image DanaScully Vojtasle · Jun 12, 2017 at 08:28 AM 0
Share

Sure but my material is a simple one that I created from the create tab and selected the Partciles/Alpha blended shader for it.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DanaScully · Jun 12, 2017 at 07:38 AM

Just did it but still the same. tried both meshfilter.sharedmesh and cloth.sharedmesh

Comment
Add comment · Show 7 · 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 Vojtasle · Jun 12, 2017 at 07:48 AM 0
Share

Isnt your gameObjects rendered material set to Transparent ? Object is little transparent even if Aplha is set to 1

avatar image DanaScully Vojtasle · Jun 12, 2017 at 07:55 AM 0
Share

I am not sure what you mean by that, but my render queue of the material is set to "From Shader".

avatar image revolute · Jun 12, 2017 at 08:27 AM 1
Share

I guess we can start from shader's "Tint Color" value and check whether it is transparent and texture's transparency.

After that, I might just point out that your code isn't setting every vertices color to a certain value. So every 1/3 vertices are set to some random color but 2/3 are not set. Try using "else" and set them to original color from your mesh. That should give you a start.

And while it wouldn't matter, your logic has a small mistake.

Consider a quad made from 2 triangles. The vertex array would be size of 4 while index array has the size of 6. This means that "Vector3[] vertices$$anonymous$$odified = new Vector3[triangles.Length];" will allocate more vertices than needed, though without indices to use the extra vertices, things wont matter (for now I suppose..?).

avatar image revolute · Jun 12, 2017 at 08:30 AM 0
Share

Since I have never used "Obi Cloth" asset, I am unaware of its designs.

To keep it out so that I may find your problem, consider testing without the plugin.

avatar image DanaScully · Jun 12, 2017 at 08:38 AM 0
Share

@revolute Thanks for pointing it out. When I disable the if it works. But I was hoping for a smooth coloring. That is why I thought maybe the by coloring 1 vertex the rest would be interpolated.

avatar image revolute · Jun 12, 2017 at 08:47 AM 0
Share

So problem solved? If I may advise you on that matter, vertices' colors are usually blended to balance between, so if you make a triangle and put each color of vertices red,green,blue respectively, you would get a spectrum of colors.

Show more comments
avatar image
0

Answer by Darkgaze · Sep 25, 2018 at 04:34 PM

I suggest you visit the official Obi forum in the contact section. Obi is big enough that we had to create a forum a long time ago. The creator of Obi will answer you in less than a week. http://obi.virtualmethodstudio.com/

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

71 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 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

How to compute shadows in custom Surface Shaders? 0 Answers

Screen shaders that alter geometry at runtime or through camera 1 Answer

How do I adapt this vertex manipulation shader so that my object (point cloud) keeps its original colouring? 0 Answers

"value must be greater than 0" - (Filename: Dynamics3/Cloth.cpp Line: 701) 1 Answer

Cloth Doesn't Move. 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