- Home /
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();
}
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 .
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.
Sure but my material is a simple one that I created from the create tab and selected the Partciles/Alpha blended shader for it.
Answer by DanaScully · Jun 12, 2017 at 07:38 AM
Just did it but still the same. tried both meshfilter.sharedmesh and cloth.sharedmesh
Isnt your gameObjects rendered material set to Transparent ? Object is little transparent even if Aplha is set to 1
I am not sure what you mean by that, but my render queue of the material is set to "From Shader".
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..?).
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.
@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.
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.
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/