How can I access by script to the triangles of a wireframe shader ?

I have a wireframe shader on a object.
But what I need is to get access to each triangle in the wireframe. To get each triangle coordinates in the connected points and each triangle size and other stuff.

For example to color a specific triangle in the wireframe how can it be done ?

I’m using this shader/s: GitHub - Chaser324/unity-wireframe: General purpose wireframe shaders for use in Unity.

I know how to get the triangles vertices and normals and uv arrays from a mesh.
And how to change them and set new vertices or normals or uv.

But I want to change it on the wireframe. For example to color one specific triangle and the rest will still be wireframe. Or to get a specific triangle 3 connections positions and color one of the three lines of the triangle.

The problem I think is that I’m using this shader transparent and when I try to change the triangles color it will not effect it unless I change the shader back to standrad. But I want to use the wireframe transparent shader and color the wireframe triangles.

This is the script I’m using trying to color the wireframe triangles:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshGenerator : MonoBehaviour
{
    private void Start()
    {
        Mesh mesh = GetComponent<MeshFilter>().mesh;
        Vector3[] vertices = mesh.vertices;

        // create new colors array where the colors will be created.
        Color[] colors = new Color[vertices.Length];

        for (int i = 0; i < vertices.Length; i++)
            colors[i] = Color.Lerp(Color.red, Color.green, vertices[i].y);

        // assign the array of colors to the Mesh.
        mesh.colors = colors;
    }
}

It’s not giving any errors but also not coloring anything on the wireframe.

Using that shader as is? You can’t. That wireframe shader simply ignores the vertex colors. You could modify the shader to pay attention to vertex colors in some capacity, but it won’t be straightforward to designate colors for specific edges or mark specific triangles to be filled. You’re passing in per vertex data, and most of those vertices get reused by multiple edges and triangles.

The only method I can think of to do it would be to use the vertex color channels as a mask rather that an explicit color and in the geometry shader if all 3 vertices are marked then pass some additional value to the fragment shader telling it to fill in the triangle.

However if you don’t know how to modify the shader to accomplish this, I might suggest you abandon trying to go this route entirely and use something like Vectrosity to directly render the lines.

Other “maybe” easy solution could be to render a second mesh, containing only the triangle that you want, with the same wireframe shader but in a different color, and display it just over the full wireframe ?