0
\$\begingroup\$

Hy, I want to build some geometry with a geometryshader in Unity. I took a look at this. I want to create my geometry just in context of one point in 3D space (x,y,z). Can i somehow use the transform position vector as input value for the shader? Or is there Something like a one vertex mesh I could use? I tried this in Blender, but coulnd't import that single Vertex mesh into Unity. Thanks for your help!

\$\endgroup\$
2
  • \$\begingroup\$ I haven't yet tested to confirm, but I think you can use the Mesh class to create a new mesh with one vertex, then mesh.SetIndices(new int[]{0}, MeshTopology.Points) to create exactly one point primitive pointing at the first vertex. Does that get you the one-point mesh you're looking for? If not, can you describe in more detail what you're trying to do with your shader? \$\endgroup\$
    – DMGregory
    Commented Jan 15, 2016 at 14:48
  • \$\begingroup\$ Thanks, i will try it out. I want to archive a Lasereffetct upload.wikimedia.org/wikipedia/commons/6/68/…. I did it before with linierenderers but it was very uneficcient, now i want to try it with a shader. \$\endgroup\$
    – Freshchris
    Commented Jan 15, 2016 at 14:52

1 Answer 1

1
\$\begingroup\$

It worked. My Code:

    Mesh mesh = new Mesh();
    mesh.vertices = newVertices;
    mesh.uv = newUV;
    GetComponent<MeshFilter>().mesh = mesh;
    mesh.SetIndices(new int[] { 0 }, MeshTopology.Points, 0);

The last line creates was very important to create a trinagle. For saving the Mesh:

AssetDatabase.CreateAsset(m1, "Assets/" + "oneVertexMesh" + ".asset"); // saves to "assets/" AssetDatabase.SaveAssets();

\$\endgroup\$
1
  • \$\begingroup\$ You might not need the mesh.triangles = newTriangles line, since it's effectively overwritten by the later SetIndices call (the triangles setter is basically just a shortcut version of SetIndices for the common case where you're using triangular topology, rather than points) \$\endgroup\$
    – DMGregory
    Commented Jan 15, 2016 at 16:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .