I am trying to change the z offset of lines in unity so it is possible to cover one line with another in 3D space. For a simple case I am generating a 1x1 square on a 2x2 quad.
The code to generate the square is
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
void Start () {
MeshFilter filter=gameObject.AddComponent<MeshFilter>();
Mesh mesh=new Mesh();
mesh.vertices=new Vector3[] {
new Vector3(-0.5f, -0.5f, 0),
new Vector3(-0.5f, 0.5f, 0),
new Vector3(0.5f, -0.5f, 0),
new Vector3(0.5f, 0.5f, 0),
};
int[] lines=new int[] {
0, 1, 0, 2, 2, 3, 1, 3,
};
mesh.SetIndices(lines, MeshTopology.Lines, 0);
mesh.normals=new Vector3[] {
new Vector3(-0.5f, -0.5f, 0),
new Vector3(-0.5f, 0.5f, 0),
new Vector3(0.5f, -0.5f, 0),
new Vector3(0.5f, 0.5f, 0),
};
filter.mesh=mesh;
MeshRenderer renderer=gameObject.AddComponent<MeshRenderer>();
renderer.sharedMaterial=Resources.Load<Material>("Materials/Flat Offset");
}
}
where the flat offset shader is
Shader "Custom/Flat Offset"{
Properties {
_Color ("Color", Color) = (0.0, 0.0, 0.0, 0.0)
}
SubShader {
Pass {
Offset -1, -1
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform float4 _Color;
float4 vert (float4 position: POSITION) : SV_POSITION
{
return mul(UNITY_MATRIX_MVP, position);
}
float4 frag () : COLOR
{
return _Color;
}
ENDCG
}
}
FallBack "Diffuse"
}
The shader works to fix z fighting between two quads

However this does not fix z fighting between the quad/line.

Is there a way to change the depth offset of lines? I want to make it so one group of lines has a different depth offset from another group of lines (in addition to having a different depth offset than quads).